Compiler Phases
Main Compiler Phases
- Compiler Phases
- Lexical Analysis
- Syntactic Analysis (ie Parsing)
- Intermediate Code Generation (and semantic analysis)
- Optimization (optional)
- Code Generation
- Data structure: Symbol table
- Used to communicate information between phases
- See figure 1.3 in Sebesta
Compiler Structure
- Compiler phases
- Lexical analysis (aka scanner):
seq of characters -> seq of tokens
- Syntactic analysis (aka parser): seq of tokens -> parse tree
- Intermediate code generation
- Code generation
- Optimization (optional)
- Symbol table involved in several phases
- See Figure 1.3 in text
Grammars and Compiler Structure
- The structure of the productions for identifiers and numbers is
much simpler than that of program
- Programs have hierarchical structure
- Identifiers and numbers have a simple, flat structure
- This difference in structure is reflected in the grammars
- This difference in structure and grammar is reflected in how
compilers are written, as we will see later.
Truth in Advertising Alert
-
Actually, the lexical analyzer produces a single tokens each time it
is called by the parser
- Parse trees are not always produced