Questions: Programming Language Semantics

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A compiler engineer wants to prove that replacing the expression 'x * 2' with 'x + x' is always valid. Which formal semantics approach most directly supports this?

AOperational semantics, by tracing execution steps and showing both evaluate to the same final value on every input
BDenotational semantics, because if two expressions have identical denotations they are guaranteed to behave identically in any context
CAxiomatic semantics, by writing a Hoare triple that holds for both expressions
DSyntactic analysis, because structurally similar expressions have equivalent behavior
Question 2 Multiple Choice

What is the correct interpretation of the Hoare triple {x > 5} x = x - 3 {x > 2}?

AThe program x = x - 3 is only allowed to execute when x > 5
BIf x > 5 holds before execution, then x > 2 is guaranteed to hold after execution
CAfter executing x = x - 3, the postcondition x > 2 implies x > 5 was true beforehand
DThe triple asserts that x = x - 3 transforms x > 5 into exactly x > 2
Question 3 True / False

Operational semantics defines the meaning of a program by specifying how it executes step by step, making it closely analogous to an interpreter specification.

TTrue
FFalse
Question 4 True / False

A program that parses successfully according to a language's grammar necessarily has a well-defined, unambiguous meaning.

TTrue
FFalse
Question 5 Short Answer

Why is it not enough for a compiler to test an optimization on a large number of inputs to prove it is valid? What does formal semantics provide that testing cannot?

Think about your answer, then reveal below.