EECS 665 Compiler Construction 1
Concepts Introduced in Chapter 2
- A more detailed overview of the compilation
process.
– Parsing – Scanning – Semantic Analysis – Syntax-Directed Translation – Intermediate Code Generation
Concepts Introduced in Chapter 2 A more detailed overview of the - - PowerPoint PPT Presentation
Concepts Introduced in Chapter 2 A more detailed overview of the compilation process. Parsing Scanning Semantic Analysis Syntax-Directed Translation Intermediate Code Generation 1 EECS 665 Compiler Construction Model of A
EECS 665 Compiler Construction 1
– Parsing – Scanning – Semantic Analysis – Syntax-Directed Translation – Intermediate Code Generation
EECS 665 Compiler Construction 2
source program tokens syntax tree three-address code
EECS 665 Compiler Construction 3
– A set of tokens, known as terminal symbols. – A set of nonterminals. – A set of productions where each production consists of a
– A designation of one of the nonterminals as the start symbol.
EECS 665 Compiler Construction 4
EECS 665 Compiler Construction 5
EECS 665 Compiler Construction 6
– The root is labeled by the start symbol. – Each leaf is labeled by a token or by . – Each interior node is labeled by a nonterminal. – If A is the nonterminal labeling some interior node
followed by Fig. 2.5
EECS 665 Compiler Construction 7
followed by Fig. 2.6
EECS 665 Compiler Construction 8
– Left associativity means that (x op1 y) is applied first
– Right associativity means that (y op2 z) is applied
followed by Fig. 2.7
EECS 665 Compiler Construction 9
EECS 665 Compiler Construction 10
EECS 665 Compiler Construction 11
followed by Fig. 2.9, 2.10
EECS 665 Compiler Construction 12
EECS 665 Compiler Construction 13
(0,0) (-1,0) (-1,-1) (2,-1) (2,1) Input String:
followed by Fig. A, B, 2.11
EECS 665 Compiler Construction 14
followed by Fig. 2.15, 2.14
EECS 665 Compiler Construction 15
EECS 665 Compiler Construction 16
– Top-Down
– Bottom-Up
followed by Fig. 2.17, 2.18
EECS 665 Compiler Construction 17
– Decides which production to use by examining the
– The appropriate procedure is invoked for each
followed by Fig. 2.15
EECS 665 Compiler Construction 18
followed by Fig. C, D, E, F
EECS 665 Compiler Construction 19
– Each interior node is an operator rather than a
– Convenient for translation.
EECS 665 Compiler Construction 20
– id
– n
– blanks, tabs, newlines, comments
EECS 665 Compiler Construction 21
read character push back character pass token and its attributes
EECS 665 Compiler Construction 22
– keywords are reserved in many languages – initialize symbol table with keywords
followed by Fig. G
EECS 665 Compiler Construction 23
EECS 665 Compiler Construction 24
– create a distinct symbol table for each block. – chain the symbol tables in a hierarchical tree structure.
followed by Fig. 2.36, I
EECS 665 Compiler Construction 25
– Used on the left side of an assignment statement. – Used to refer to a location.
– Used on the right side of an assignment statement. – Used to refer to a value.
EECS 665 Compiler Construction 26
– syntax trees
– three-address code
followed by Fig. 2.39
EECS 665 Compiler Construction 27
– General Format: x = y op z – Arrays: x [ y ] = z, x = y [ z ] – Copy: x = y – Control flow: ifFalse x goto L, – ifTrue x goto L, – goto L
EECS 665 Compiler Construction 28
after
EECS 665 Compiler Construction 29
– Syntactic checking
– Type checking