1
Chapter Fifteen: Stack Machine Applications
Formal Language, chapter 15, slide 1
Chapter Fifteen: Stack Machine Applications Formal Language, - - PowerPoint PPT Presentation
Chapter Fifteen: Stack Machine Applications Formal Language, chapter 15, slide 1 1 The parse tree (or a simplified version called the abstract syntax tree) is one of the central data structures of almost every compiler or other programming
1
Formal Language, chapter 15, slide 1
2
Formal Language, chapter 15, slide 2
3
Formal Language, chapter 15, slide 3
4
Formal Language, chapter 15, slide 4
5
– type 1 when the top symbol is nonterminal – type 2 when the top symbol is terminal
Formal Language, chapter 15, slide 5
6
Formal Language, chapter 15, slide 6
7
Formal Language, chapter 15, slide 7
8
Formal Language, chapter 15, slide 8
9
a b c $ S S → aS a S → bS b S → c
Formal Language, chapter 15, slide 9
10
Formal Language, chapter 15, slide 10
11
Formal Language, chapter 15, slide 11
12
Formal Language, chapter 15, slide 12
13
Formal Language, chapter 15, slide 13
14
Formal Language, chapter 15, slide 14
15
Formal Language, chapter 15, slide 15
16
a b c + * ( ) $ S S → AR S → AR S → AR S → AR R R → +AR R → R → A A → XB A → XB A → XB A → XB B B → B → *XB B → B → X X → a X → b X → c X → (S)
Formal Language, chapter 15, slide 16
17
Formal Language, chapter 15, slide 17
18
Formal Language, chapter 15, slide 18
19
Formal Language, chapter 15, slide 19
20
void match(x) { c = the current symbol in input if (c!=x) the parse fails; advance input to the next symbol; }
Formal Language, chapter 15, slide 20
21
void parse_S() { c = the current symbol in input (or $ at the end) if (c=='a' || c=='b' || c=='c' || c=='(') { // production S → AR parse_A(); parse_R(); } else the parse fails; } a b c + * ( ) $ S S → AR S → AR S → AR S → AR R R → +AR R → R → A A → XB A → XB A → XB A → XB B B → B → *XB B → B → X X → a X → b X → c X → (S)
Formal Language, chapter 15, slide 21
22
a b c + * ( ) $ S S → AR S → AR S → AR S → AR R R → +AR R → R → A A → XB A → XB A → XB A → XB B B → B → *XB B → B → X X → a X → b X → c X → (S)
Formal Language, chapter 15, slide 22
23
Formal Language, chapter 15, slide 23
24
Formal Language, chapter 15, slide 24
25
Formal Language, chapter 15, slide 25
26
Input Stack Next move abbcbba$ shift abbcbba$ a shift abbcbba$ b a shift abbcbba$ b b a shift abbcbba$ cb b a reduce by S → c aaacbbb$ Sbba shift abbcbba$ bSbba reduce by S → bSb abbcbba$ S b a shift abbcbba$ bSba reduce by S → bSb abbcbba$ S a shift abbcbba$ aSa reduce by S → aSa abbcbba$ S
Formal Language, chapter 15, slide 26
27
Formal Language, chapter 15, slide 27
28
Formal Language, chapter 15, slide 28
29
Formal Language, chapter 15, slide 29
30
Formal Language, chapter 15, slide 30
31
Formal Language, chapter 15, slide 31
32
Formal Language, chapter 15, slide 32
33
Formal Language, chapter 15, slide 33
34
Formal Language, chapter 15, slide 34
35
Formal Language, chapter 15, slide 35
36
Formal Language, chapter 15, slide 36
37
Formal Language, chapter 15, slide 37
38
regular languages DCFLs L(a*b*) {anbn} CFLs {xxR | x ∈ {a,b}*}
Formal Language, chapter 15, slide 38
39
Formal Language, chapter 15, slide 39
40
Formal Language, chapter 15, slide 40