What is semantic analysis?
The phase of the compiler that checks the source program for semantic consistency with the language definition.
What is a synthesized attribute?
Of a non terminal A at a parse tree node N is directly defined by a semantic rule associated with production at N (node value determined from child node(s))
What is an inherited attribute?
For a nonterminal B at a parse-tree node N is defined by a semantic rule associated with the production at the parent of N (node gets value from parent/sibling nodes)
What are attribute grammars?
Syntax-defined definitions whose semantic rules have no side effects.
What is a side effect?
Any action or rule application that results in an effect, such as printing or evaluating a value.
What is the purpose of the semantic analyzer?
Checking and verifying data types. Last chance to weed out inconsistent/incorrect programs at the front end.
What are the jobs of the semantic analyzer (know at least 3)
What is intermediate representation?
Data structure used by compiler to represent source code.
What are data types?
A collection or grouping of data values and the operations that can be performed on them.
What is a type system?
feature of a language, the collection of all its data types, data operations, and rules for how types can be combined or coerced
Language Type: Static
Type-checking performed at compile time.
Language Type: Dynamic
Type checking performed at run time
Language Type: Explicit
Types declared in source code
Language Type: Implicit
Type checking in compiler
Language Type: Safe
Cannot violate rules and structure of type system
Language Type: Unsafe
Can violate rules and structure of type system
Language Type: Atomic
Types provided by language and recognized by compiler
Language Type: Composite
Types that are built up from atomic types
Why do we use data types?
They give us a way of specifying the context of data
Why do we use type systems?
Ensures that everything is typed and all types agree with each other
Benefits of a type system?
Correctness, performance, expressiveness
What is data flow analysis?
Process of tracing how values make their way through a program
What are the benefits (3) of data flow analysis?
What is code generation/what does it do?
Takes intermediate representation, translates into machine code.
optimized TAC → code generation → machine code