SEMANTICS Flashcards
What are the three primary methods of describing programming language semantics?
Operational semantics, axiomatic semantics, and denotational semantics.
Describe operational semantics.
Operational semantics defines the meaning of a program by executing its statements on a machine (real or simulated). The state change of the machine represents the meaning of the statement.
What is required to use operational semantics for a high-level language?
A virtual machine, as hardware pure interpreters are too expensive and software pure interpreters are machine-dependent.
What is the process for building operational semantics?
Build a translator to convert source code to machine code of an idealized computer and build a simulator for the idealized computer.
Explain axiomatic semantics.
Axiomatic semantics is based on formal logic and involves defining axioms or inference rules for each statement type to allow transformation of expressions into other expressions.
What are assertions in axiomatic semantics?
Assertions are statements that express relationships and constraints among variables. A precondition is an assertion before a statement, and a postcondition is an assertion after a statement.
What is a weakest precondition in axiomatic semantics?
The least restrictive precondition that will guarantee the postcondition.
Describe denotational semantics.
Denotational semantics is based on recursive function theory and involves defining a mathematical object for each language entity and a function that maps instances of language entities to instances of corresponding mathematical objects.
How is the state of a program defined in denotational semantics?
The state of a program is defined by the values of all its current variables, represented as s = {<i1, v1>, <i2, v2>, …, <in, vn>}.
Compare operational semantics and denotational semantics.
Operational semantics defines state changes by coded algorithms, while denotational semantics defines state changes by rigorous mathematical functions.
What are the key evaluation points for denotational semantics?
It can be used to prove program correctness, provides rigorous thinking about programs, aids in language design, and has been used in compiler generation systems, but is complex and of little use to language users.
What is an attribute grammar?
A descriptive formalism that can describe both the syntax and the semantics of a language.
What are the summary points regarding BNF and context-free grammars?
BNF and context-free grammars are equivalent meta-languages, well-suited for describing the syntax of programming languages.
Why are BNF and EBNF notations important?
They provide a structured and formal way to describe the syntax of programming languages, making it easier to understand and implement language constructs.