Ch3&5 Flashcards
(56 cards)
Define syntax and semantics.
Syntax: Form of its expressions, statements, and program units.
Semantics: Meaning of these expressions, statements, and program units.
What is the difference between a sentence and a sentential form?
Sentence: Strings of symbols belonging to a language; a sentential form containing only terminal symbols.
Sentential Form: Any string of symbols that appear in a derivation. May contain non-terminal symbols.
Define a left-recursive grammar rule.
A grammar is left-recursive if some non-terminal A will eventually derive a sentential form with itself (A) as the left-most symbol.
What three extensions are common to most EBNFs?
Optional parts: [ ]
Repetitions: { }
Alternatives: |
Distinguish between static and dynamic semantics.
Static semantics: Can be determined at compile time (e.g., type checking).
Dynamic semantics: Can only be determined at run time (the program’s behavior during execution).
What purpose do predicates serve in an attribute grammar?
Specify conditions that must be true for a rule to be valid (static semantic constraints).
What is the difference between a synthesized and an inherited attribute?
Synthesized attribute: Its value is computed from its children in the parse tree (information flows up).
Inherited attribute: Its value is passed down from its parent or siblings (information flows down).
How is the order of evaluation of attributes determined for the trees of a given attribute grammar?
By the dependencies between attributes. An attribute is evaluated after its dependencies are evaluated.
What is the primary use of attribute grammars?
To define the static semantics of programming languages.
Explain the primary uses of a methodology and notation for describing the semantics of programming languages.
Programmer understanding.
Compiler construction.
Program verification.
Language design.
Why can machine languages not be used to define statements in operational semantics?
They are too low-level and machine-dependent. Operational semantics aims for abstraction.
Describe the two levels of uses of operational semantics.
Natural operational semantics: Describes the overall effect of program execution.
Structural operational semantics: Describes the step-by-step execution.
In denotational semantics, what are the syntactic and semantic domains?
Syntactic domains: Sets of syntactic objects (programs, statements).
Semantic domains: Sets of meanings (numbers, functions).
What is stored in the state of a program for denotational semantics?
The values of variables and other program data.
Which semantics approach is most widely known?
Operational semantics.
What two things must be defined for each language entity in order to construct a denotational description of the language?
A semantic domain.
A semantic function.
Which part of an inference rule is the antecedent?
The part above the horizontal line (the premises).
What is a predicate transformer function?
Maps a postcondition to a precondition.
What does partial correctness mean for a loop construct?
If the loop terminates, the postcondition will be true.
On what branch of mathematics is axiomatic semantics based?
Mathematical logic (predicate calculus).
On what branch of mathematics is denotational semantics based?
Domain theory.
What is the problem with using a software pure interpreter for operational semantics?
They can be complex, slow, and may not be sufficiently abstract.
Explain what the preconditions and postconditions of a given statement mean in axiomatic semantics.
Precondition: What must be true before execution.
Postcondition: What will be true after execution.
Describe the approach of using axiomatic semantics to prove the correctness of a given program
Derive preconditions from postconditions using inference rules. If the program’s initial state matches the derived precondition, it’s correct.