Chapter 4 Flashcards
To help in semantic analysis we need two tools
Semantic rules(definitions)
Semantic actions(translations)
Semantic analysis
- checks the src program for semantic error
- type checking
- Example: Array indexing using floats
Semantic analysis uses … from the syntax analysis
hierarchical structure to identify operators and operands
Semantic analyzer judgment
Example: int a = “value”; is syntactically and lexically correct but semantic analyzer throws an error
Semantic analyzer tasks
- Scope resolution
- Type checking
- Array bound checking
Semantic errors
- Type mismatch
- Undeclared vars
- Reserved identifier use
- Multiple declaration of variable
- Parameter and argument mismatch
Syntax directed translation
- refers to a method a compiler implementation where the source language translation is completely driven by the parser
Syntax directed translation is directed by
Context free grammars
Attributed grammars
Augment CFG with information to control semantic analysis and translation process
Steps in syntax directed translation
input string -> parse tree -> dependency graph -> eval of semantic rules
Output action of Syntax directed translation
- computation of values for variable belonging to the compiler
- generate of intermediate code
- printing an error diagnostic
- placement of values in table
Syntax directed definition
semantic rule in which each variable adds extra variable. And each production adds semantic rule