6. Semantic Analysis PART ONE
6. Semantic Analysis PART ONE
Semantic Analysis phase Purpose: compute additional information needed for compilation that is beyond the capabilities of Context Free Grammars and standard parsing algorithms Static semantic analysis: Take place prior to execution (Such as building a symbol table, performing type inference and type checking Classification analysis of a program required by the rules of the programming language to establish its correctness and to guarantee proper execution Analysis performed by a compiler to enhance the efficiency of execution of the translated program
• Semantic Analysis Phase – Purpose: compute additional information needed for compilation that is beyond the capabilities of ContextFree Grammars and Standard Parsing Algorithms – Static semantic analysis: Take place prior to execution (Such as building a symbol table、performing type inference and type checking) • Classification – Analysis of a program required by the rules of the programming language to establish its correctness and to guarantee proper execution – Analysis performed by a compiler to enhance the efficiency of execution of the translated program
Description of the static semantic analysis Attribute grammar identify attributes of language entities that must be computed and to write attribute equations or semantic rules that express how the computation of such attributes is related to the grammar rules of the language Which is most useful for languages that obey the principle of syntax-Directed Semantics Abstract syntax as represented by an abstract syntax tree
• Description of the static semantic analysis – Attribute grammar • identify attributes of language entities that must be computed • and to write attribute equations or semantic rules that express how the computation of such attributes is related to the grammar rules of the language – Which is most useful for languages that obey the principle of Syntax-Directed Semantics – Abstract syntax as represented by an abstract syntax tree
Implementation of the static semantic analysis Not as clearly expressible as parsing algorithms because of the addition problem caused by the timing of the analysis during the compilation process Multi-pass(more common) or single pass lead to totally different process Emphasis Attributes and attribute grammars Algorithms for attribute computation The symbol table Data types and type checking a semantic analyzer for the tiNy language
• Implementation of the static semantic analysis: – Not as clearly expressible as parsing algorithms because of the addition problem caused by the timing of the analysis during the compilation process – Multi-pass (more common) or single pass lead to totally different process • Emphasis: – Attributes and attribute grammars – Algorithms for attribute computation – The symbol table – Data types and type checking – A semantic analyzer for the TINY language
Contents Part One 6.1 Attributes and Attribute grammars 6.2 Algorithms for Attribute Computation Part two 6.3 The symbol table 6.4 Data Types and Type Checking 6.5 A Semantic Analyzer for the tINY Language
Contents Part One 6.1 Attributes and Attribute Grammars 6.2 Algorithms for Attribute Computation Part Two 6.3 The Symbol Table 6.4 Data Types and Type Checking 6.5 A Semantic Analyzer for the TINY Language