Semantic Analysis Flashcards
What are the two kinds of semantic (contextual) constraints?
Static and Dynamic
A static semantic constraint can be checked by…
a compiler performing static analysis.
How can a dynamic semantic (contextual) constraint be checked?
It can be checked by runtime code generated by a compiler.
What are some examples of static context constraints?
- Variables must be declared before used.
- Variables cannot be declared more than once in the same program unit.
- In x = y, x and y must be compatible.
- Every function must contain at least one return statement.
Static Analysis
Constraints can be described in terms of ______ or ______.
- Annotation
- Decoration of a Syntax Tree
What is the name of the compiler component that checks for constraints?
Semantic Analyzer
Do context free grammars impose contextual constraints on the sentences?
No.
Symbols in the grammar are associated with…
attributes.
Production rules in a grammar are associated with…
semantic rules indicating how the attribute values are computed.
What do attributes in a grammar do?
Capture correspondence between characters and mathematical values.
Example
Attribute val: The mathematical value that corresponds to the digit.
digit = 0 (character)
digit.val = 0 (digit)
What do conditions in a grammar do?
Constrain the sentences to those whose legal values are in a fixed and finite range.
What can semantic rules do?
Tells us how to compute the values of the attributes from the characters and other attributes.
What are synthesized attributes?
Attibute values that are calculated in productions where the associated symbol appears on the left hand side.
Dependencies point from child to parent in the parse tree.
(T/F) In inherited attributes, information always flow from child to parent in the parse tree.
False
Information may flow to a node from the parent OR siblings.
Analogous with CFG, attribute grammars are declarative.
Explain.
AGs define a set of valid trees, but don’t specify how to build or decorate them just like CFG define valid sentences, but not the parsing algorithm.