To help in semantic analysis we need two tools
Semantic rules(definitions)
Semantic actions(translations)
Semantic analysis
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
Semantic errors
Syntax directed translation
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
Syntax directed definition
semantic rule in which each variable adds extra variable. And each production adds semantic rule