Bottom-up Analysis. Theorem: Proof: Let a grammar G be reduced and left-recursive, then G is not LL(k) for any k.
|
|
- Emily Clarke
- 5 years ago
- Views:
Transcription
1 Bottom-up Analysis Theorem: Let a grammar G be reduced and left-recursive, then G is not LL(k) for any k. Proof: Let A Aβ α P and A be reachable from S Assumption: G is LL(k) A n A S First k (αβ n γ) First k (αβ n+1 γ) = A β n β γ First k ( ) 117 / 292
2 Bottom-up Analysis Theorem: Let a grammar G be reduced and left-recursive, then G is not LL(k) for any k. Proof: Let A Aβ α P and A be reachable from S Assumption: G is LL(k) A n A S First k (αβ n γ) First k (αβ n+1 γ) = A β n β γ α First k ( ) 117 / 292
3 Bottom-up Analysis Theorem: Let a grammar G be reduced and left-recursive, then G is not LL(k) for any k. Proof: Let A Aβ α P and A be reachable from S Assumption: G is LL(k) A n A S First k (αβ n γ) First k (αβ n+1 γ) = A β n β γ A β α First k ( ) 117 / 292
4 Bottom-up Analysis Theorem: Let a grammar G be reduced and left-recursive, then G is not LL(k) for any k. Proof: Let A Aβ α P and A be reachable from S Assumption: G is LL(k) First k (αβ n γ) First k (αβ n+1 γ) = Case 1: β ǫ Contradiction!!! Case 2: β w ǫ == First k (αw k γ) First k (αw k+1 γ) 117 / 292
5 Shift-Reduce Parser Idea: We delay the decision whether to reduce until we know, whether the input matches the right-hand-side of a rule! Donald Knuth Construction: Shift-Reduce parser M R G The input is shifted successively to the pushdown. Is there a complete right-hand side (a handle) atop the pushdown, it is replaced (reduced) by the corresponding left-hand side 118 / 292
6 Shift-Reduce Parser Example: The pushdown automaton: S AB A a B b States: q 0, f, a, b, A, B, S; Start state: q 0 End state: f q 0 a q 0 a a ǫ A A b Ab b ǫ B AB ǫ S q 0 S ǫ f 119 / 292
7 Shift-Reduce Parser Construction: In general, we create an automaton M R G = (Q,T,δ,q 0,F) with: Q = T N {q 0,f} F = {f}; Transitions: (q 0,f fresh); δ = {(q,x,qx) q Q,x T} // Shift-transitions {(qα,ǫ,qa) q Q,A α P} // Reduce-transitions {(q 0 S,ǫ,f)} // finish Example-computation: (q 0, ab) (q 0 a, b) (q 0 A, b) (q 0 A b, ǫ) (q 0 AB, ǫ) (q 0 S, ǫ) (f, ǫ) 120 / 292
8 Shift-Reduce Parser Observation: The sequence of reductions corresponds to a reverse rightmost-derivation for the input To prove correctnes, we have to prove: (ǫ, w) (A, ǫ) iff A w The shift-reduce pushdown automaton MG R non-deterministic is in general also For a deterministic parsing-algorithm, we have to identify computation-states for reduction == LR-Parsing 121 / 292
9 Reverse Rightmost Derivations in Shift-Reduce-Parsers Idea: Observe reverse rightmost-derivations of M R G! Input: + 40 E 1 E 0 + T 1 Pushdown: ( q 0 T F ) T 0 F 2 T 1 F 2 F 1 Generic Observation: In a sequence of configurations of M R G name (q 0 αγ, v) (q 0 αb, v) (q 0 S, ǫ) we call αγ a viable prefix for the complete item [B γ ]. 122 / 292
10 Reverse Rightmost Derivations in Shift-Reduce-Parsers Idea: Observe reverse rightmost-derivations of M R G! Input: E 1 E 0 + T 1 Pushdown: ( q 0 E + F ) T 0 T 1 F 2 F 2 F 1 Generic Observation: In a sequence of configurations of M R G name (q 0 αγ, v) (q 0 αb, v) (q 0 S, ǫ) we call αγ a viable prefix for the complete item [B γ ]. 122 / 292
11 Bottom-up Analysis: Viable Prefix αγ is viable for [B γ ] iff S R αbv A 0 i 0 α 1 A 1 i 1 α 2 A 2 i 2 α m B i γ... with α = α 1... α m Conversely, for an arbitrary valid word α we can determine the set of all later on possibly matching rules / 292
12 Bottom-up Analysis: Admissible Items The item [B γ β] is called admissible for α iff S R αbv with α = αγ : A 0 i 0 α 1 A 1 i 1 α 2 A 2 i 2 α m B i γ β... with α = α 1... α m 124 / 292
13 Characteristic Automaton Observation: The set of viable prefixes from (N T) for (admissible) items can be computed from the content of the shift-reduce parser s pushdown with the help of a finite automaton: States: Items Start state: [S S] Final states: {[B γ ] B γ P} Transitions: (1) ([A α Xβ],X,[A αx β]), X (N T),A αxβ P; (2) ([A α Bβ],ǫ, [B γ]), A αbβ, B γ P; The automaton c(g) is called characteristic automaton for G. 125 / 292
14 Characteristic Automaton For example: E E+T 0 T 1 T T F 0 F 1 F ( E ) 0 2 S E E S E E E+T E + T E E +T E E+ T E E+T E T T E T T T F T F T T F T T F T T F T F F T F ( E ) F ( E ) F ( E ) F ( E ) F ( E ) F F 126 / 292
15 Canonical LR(0)-Automaton The canonical LR(0)-automaton LR(G) is created from c(g) by: 1 performing arbitrarily many ǫ-transitions after every consuming transition 2 performing the powerset construction... for example: E F 0 ( T ( F 3 ( F E 5 ( T * T 11 ) 9 7 * F / 292
16 Canonical LR(0)-Automaton Example: E E+T 0 T 1 Therefore we determine: T T F 0 F 1 F ( E ) 0 2 q 0 = {[S E], q 1 = δ(q 0,E) = {[S E ], {[E E+T], {[E E +T]} {[E T], {[T T F], q 2 = δ(q 0,T) = {[E T ], {[T F], {[T T F]} {[F (E)], {[F ]} q 3 = δ(q 0,F) = {[T F ]} q 4 = δ(q 0,) = {[F ]} 128 / 292
17 Canonical LR(0)-Automaton q 5 = δ(q 0, () = {[F ( E)], q 7 = δ(q 2, ) = {[T T F], {[E E+T], {[F (E)], {[E T], {[F ]} {[T T F], {[T F], q 8 = δ(q 5,E) = {[F (E )]} {[F (E)], {[E E +T]} {[F ]} q 9 = δ(q 6,T) = {[E E+T ], q 6 = δ(q 1,+) = {[E E+ T], {[T T F]} {[T T F], {[T F], q 10 = δ(q 7,F) = {[T T F ]} {[F (E)], {[F ]} q 11 = δ(q 8, )) = {[F (E) ]} 129 / 292
18 Canonical LR(0)-Automaton Observation: The canonical LR(0)-automaton can be created directly from the grammar. Therefore we need a helper function δǫ (ǫ-closure) We define: δ ǫ(q) = q {[B γ] [A α B β ] q, β (N T) : B Bβ} States: Sets of items; Start state: δ ǫ {[S S]} Final states: {q A α P : [A α ] q} Transitions: δ(q,x) = δ ǫ {[A αx β] [A α Xβ] q} 130 / 292
19 LR(0)-Parser Idea for a parser: The parser manages a viable prefix α = X 1...X m on the pushdown and uses LR(G), to identify reduction spots. It can reduce with A γ, if [A γ ] is admissible for α Optimization: We push the states instead of the X i in order not to process the pushdown s content with the automaton anew all the time. Reduction with A γ leads to popping the uppermost γ states and continue with the state on top of the stack and input A. Attention: This parser is only deterministic, if each final state of the canonical LR(0)-automaton is conflict free. 131 / 292
20 LR(0)-Parser... for example: q 1 = {[S E ], {[E E +T]} q 2 = {[E T ], q 9 = {[E E+T ], {[T T F]} {[T T F]} q 3 = {[T F ]} q 10 = {[T T F ]} q 4 = {[F ]} q 11 = {[F (E) ]} The final states q 1,q 2,q 9 contain more then one admissible item non deterministic! 132 / 292
21 LR(0)-Parser The construction of the LR(0)-parser: States: Q {f} (f fresh) Start state: q 0 Final state: f Transitions: Shift: (p,a,pq) if q = δ(p,a) Reduce: (pq 1...q m,ǫ,pq) if [A X 1...X m ] q m, q = δ(p,a) Finish: (q 0 p,ǫ,f) if [S S ] p with LR(G) = (Q,T,δ,q 0,F). 133 / 292
22 LR(0)-Parser Correctness: we show: The accepting computations of an LR(0)-parser are one-to-one related to those of a shift-reduce parser M R G. we conclude: The accepted language is exactly L(G) The sequence of reductions of an accepting computation for a word w T yields a reverse rightmost derivation of G for w 134 / 292
23 LR(0)-Parser Attention: Unfortunately, the LR(0)-parser is in general non-deterministic. We identify two reasons: Reduce-Reduce-Conflict: [A γ ], [A γ ] q with A A γ γ Shift-Reduce-Conflict: [A γ ], [A α aβ] q with a T for a state q Q. Those states are called LR(0)-unsuited. 135 / 292
24 Revisiting the Conflicts of the LR(0)-Automaton What differenciates the particular Reductions and Shifts? Input: E 1 E 0 + T 1 Pushdown: ( q 0 T ) E 1 T 0?? F 2 T 1 F 2 F 1 name E E+T 0 T 1 T T F 0 F 1 F ( E ) / 292
25 Revisiting the Conflicts of the LR(0)-Automaton What differenciates the particular Reductions and Shifts? Input: + 40 T 0? E 1 E 0 + T 1 Pushdown: ( q 0 T )? T 0 F 2 T 1 F 2 F 1 name E E+T 0 T 1 T T F 0 F 1 F ( E ) / 292
26 Revisiting the Conflicts of the LR(0)-Automaton Idea: Matching lookahead with right context matters! Input: E 1 E 0 + T 1 Pushdown: ( q 0 T ) E 1 T 0?? F 2 T 1 F 2 F 1 name E E+T 0 T 1 T T F 0 F 1 F ( E ) / 292
27 Revisiting the Conflicts of the LR(0)-Automaton Idea: Matching lookahead with right context matters! Input: Pushdown: ( q 0 T ) + 40 T 0? E 1? T 0 E 0 + T 1 F 2 T 1 F 2 F 1 name E E+T 0 T 1 T T F 0 F 1 F ( E ) / 292
28 LR(k)-Grammars Idea: Consider k-lookahead in conflict situations. Definition: The reduced contextfree grammar G is called LR(k)-grammar, if for First k (w) = First k (x) with: } S R αaw αβw S R α A w follows: α = α A = A w = x αβx Strategy for testing Grammars for LR(k)-property 1 Focus iteratively on all rightmost derivations S R αxw αβw 2 Identify handle αβ in s. forms αβw (w T, α,β (N T) ) 3 Determine minimal k, such that First k (w) associates β with a unique X β for non-prefixing αβs 137 / 292
29 LR(k)-Grammars for example: (1) S A B A aab 0 B abbb 1... is not LL(k) for any k but LR(0): Let S RαXw αβw. Then αβ is of one of these forms: A, B, a n aab, a n abbb, a n 0, a n 1 (n 0) (2) S aac A Abb b... is also not LL(k) for any k but again LR(0): Let S RαXw αβw. Then αβ is of one of these forms: ab, aabb, aac 138 / 292
30 LR(k)-Grammars for example: (3) S aac A bba b... is not LR(0), but LR(1): Let S R αxw αβw with {y} = First k(w) then αβy is of one of these forms: ab 2n bc, ab 2n bbac, aac (4) S aac A bab b... is not LR(k) for any k 0: Consider the rightmost derivations: S Rab n Ab n c ab n bb n c 139 / 292
31 LR(1)-Parsing Idea: Let s equip items with 1-lookahead Definition LR(1)-Item An LR(1)-item is a pair [B α β, x] with x Follow 1 (B) = {First 1 (ν) S µbν} 140 / 292
32 Admissible LR(1)-Items The item [B α β, x] is admissable for γα if: S RγBw with {x} = First 1 (w) S i 0 γ 0 A 1 i 1 γ 1 A mi m γ m B i α β x w... with γ 0...γ m = γ 141 / 292
33 The Characteristic LR(1)-Automaton The set of admissible LR(1)-items for viable prefixes is again computed with the help of the finite automaton c(g,1). The automaton c(g,1): States: LR(1)-items Start state: [S S, ǫ] Final states: {[B γ, x] B γ P,x Follow 1 (B)} Transitions: (1) ([A α Xβ, x],x,[a αx β, x]), X (N T) (2) ([A α Bβ, x],ǫ, [B γ, x ]), A αbβ, B γ P,x First 1 (β) 1 {x}; This automaton works like c(g) but additionally manages a 1-prefix from Follow 1 of the left-hand sides. 142 / 292
34 The Canonical LR(1)-Automaton The canonical LR(1)-automaton LR(G,1) is created from c(g,1), by performing arbitrarily many ǫ-transitions and then making the resulting automaton deterministic... But again, it can be constructed directly from the grammar; analoguously to LR(0), we need the ǫ-closure δ ǫ as a helper function: δ ǫ(q) = q {[C γ, x] [A α Bβ, x ] q,β (N T) : B Cβ x First 1 (ββ ) 1 {x }} Then, we define: States: Sets of LR(1)-items; Start state: δ ǫ {[S S, ǫ]} Final states: {q A α P : [A α, x] q} Transitions: δ(q,x) = δ ǫ {[A αx β, x] [A α Xβ, x] q} 143 / 292
35 The Canonical LR(1)-Automaton For example: E E+T 0 T 1 T T F 0 F 1 F ( E ) 0 2 First 1 (S ) = First 1 (E) = First 1 (T) = First 1 (F) = name,,( q 0 = {[S E, {ǫ}], q 3 = δ(q 0,F) = {[T F, {ǫ,+, }]} {[E E +T, {ǫ,+}], {[E T, {ǫ,+}], q 4 = δ(q 0,) {[F, {ǫ,+, }]} {[T T F, {ǫ,+, }], {[T F, {ǫ,+, }], q 5 = δ(q 0, () = {[F ( E ), {ǫ,+, }], {[F (E ), {ǫ,+, }], {[E E +T, {),+}], {[F,{ǫ,+, }]} {[E T, {),+}], {[T T F, {),+, }], q 1 = δ(q 0,E) = {[S E, {ǫ}], {[T F, {),+, }], {[E E +T, {ǫ,+}]} {[F (E ), {),+, }], {[F, {),+, }]} q 2 = δ(q 0,T) = {[E T, {ǫ,+}], {[T T F, {ǫ,+, }]} 144 / 292
36 The Canonical LR(1)-Automaton For example: E E+T 0 T 1 T T F 0 F 1 F ( E ) 0 2 First 1 (S ) = First 1 (E) = First 1 (T) = First 1 (F) = name,,( q 5 = δ(q 5, () = {[F ( E ), {),+, }], q 7 = δ(q 2, ) = {[T T F, {ǫ,+, }], {[E E +T, {),+}], {[F (E ), {ǫ,+, }], {[E T, {),+}], {[F, {ǫ,+, }]} {[T T F, {),+, }], {[T F, {),+, }], q 8 = δ(q 5,E) = {[F (E ),{ǫ,+, }]} {[F (E ), {),+, }], {[E E +T, {),+}]} {[F, {),+, }]} q 9 = δ(q 6,T) = {[E E +T, {ǫ,+}], q 6 = δ(q 1,+) = {[E E + T, {ǫ,+}], {[T T F, {ǫ,+, }]} {[T T F, {ǫ,+, }], {[T F, {ǫ,+, }], q 10 = δ(q 7,F) = {[T T F, {ǫ,+, }]} {[F (E ), {ǫ,+, }], {[F, {ǫ,+, }]} q 11 = δ(q 8, )) = {[F (E ), {ǫ,+, }]} 145 / 292
37 The Canonical LR(1)-Automaton For example: E E+T 0 T 1 T T F 0 F 1 F ( E ) 0 2 First 1 (S ) = First 1 (E) = First 1 (T) = First 1 (F) = name,,( q 2 q 3 q 4 = δ(q 5,T) = {[E T, {),+}], q 7 {[T T F, {),+, }]} = δ(q 9, ) = {[T T F, {),+, }], {[F (E ), {),+, }], {[F, {),+, }]} = δ(q 5,F) = {[T F, {),+, }]} q 8 = δ(q 5,E) = {[F (E ),{),+, }]} = δ(q 5,) = {[F, {),+, }]} {[E E +T, {),+}]} q 6 = δ(q 8,+) = {[E E + T, {),+}], q 9 {[T T F, {),+, }], {[T F, {),+, }], {[F (E ), {),+, }], q 10 {[F, {),+, }]} q 11 = δ(q 6,T) = {[E E +T, {),+}], {[T T F, {),+, }]} = δ(q 7,F) = {[T T F, {),+, }]} = δ(q 8, )) = {[F (E ), {),+, }]} 146 / 292
38 The Canonical LR(1)-Automaton E F 0 ( T F 3 ( F 5 ( T 2 6 E + 8 * T 11 ) 9 7 * F / 292
39 The Canonical LR(1)-Automaton E F 0 ( T + T T 6 4 F ( F F 3 E ) 11 5 ( 8 ( F ( T ) E ( *( 7 T 2 * * F 9 * 10 F / 292
40 The Canonical LR(1)-Automaton Discussion: In the example, the number of states was almost doubled... and it can become even worse The conflicts in states q 1,q 2,q 9 are now resolved! e.g. we have for: with: q 9 = {[E E+T, {ǫ,+}], {[T T F, {ǫ,+, }]} {ǫ,+} (First 1 ( F) 1 {ǫ,+, }) = {ǫ,+} { } = 148 / 292
41 The LR(1)-Parser: action goto Output The goto-table encodes the transitions: goto[q,x] = δ(q,x) Q The action-table describes for every state q and possible lookahead w the necessary action. 149 / 292
42 The LR(1)-Parser: The construction of the LR(1)-parser: States: Q {f} (f fresh) Start state: q 0 Final state: f Transitions: Shift: (p,a,pq) if q = goto[q,a], s = action[p,w] Reduce: (pq 1... q β,ǫ,pq) if [A β ] q β, q = goto(p,a), [A β ] = action[q β,w] Finish: (q 0 p,ǫ,f) if [S S ] p with LR(G,1) = (Q,T,δ,q 0,F). 150 / 292
43 The LR(1)-Parser: Possible actions are: shift // Shift-operation reduce(a γ) // Reduction with callback/output error // Error... for example: E E+T 0 T 1 T T F 0 F 1 F ( E ) 0 1 action ǫ ( ) + q 1 S,0 s q 2 E,1 E,1 s q 2 E,1 E,1 s q 3 T,1 T,1 T,1 q 3 T,1 T,1 T,1 q 4 F,1 F,1 F,1 q 4 F,1 F,1 F,1 q 9 E,0 E,0 s q 9 E,0 E,0 s q 10 T,0 T,0 T,0 q 10 T,0 T,0 T,0 q 11 F,0 F,0 F,0 q 11 F,0 F,0 F,0 151 / 292
44 The Canonical LR(1)-Automaton In general: We identify two conflicts: Reduce-Reduce-Conflict: [A γ, x], [A γ, x] q with A A γ γ Shift-Reduce-Conflict: [A γ, x], [A α aβ, y] q with a T und x {a}. for a state q Q. Such states are now called LR(1)-unsuited 152 / 292
45 The Canonical LR(1)-Automaton In general: We identify two conflicts: Reduce-Reduce-Conflict: [A γ, x], [A γ, x] q with A A γ γ Shift-Reduce-Conflict: [A γ, x], [A α aβ, y] q with a T und x {a} k First k (β) k {y}. for a state q Q. Such states are now called LR(k)-unsuited 152 / 292
46 Special LR(k)-Subclasses Theorem: A reduced contextfree grammar G is called LR(k) iff the canonical LR(k)-automaton LR(G,k) has no LR(k)-unsuited states. Discussion: Our example apparently is LR(1) In general, the canonical LR(k)-automaton has much more states then LR(G) = LR(G, 0) Therefore in practice, subclasses of LR(k)-grammars are often considered, which only use LR(G)... For resolving conflicts, the items are assigned special lookahead-sets: 1 independently on the state itself == Simple LR(k) 2 dependent on the state itself == LALR(k) 153 / 292
47 Syntactic Analysis Chapter 5: Summary 154 / 292
48 Parsing Methods deterministic languages = LR(1) =... = LR(k) LALR(k) SLR(k) LR(0) regular languages LL(1) LL(k) 155 / 292
49 Parsing Methods deterministic languages = LR(1) =... = LR(k) LALR(k) SLR(k) LR(0) regular languages Discussion: LL(1) All contextfree languages, that can be parsed with a deterministic pushdown automaton, can be characterized with an LR(1)-grammar. LR(0)-grammars describe all prefixfree deterministic contextfree languages The language-classes of LL(k)-grammars form a hierarchy within the deterministic contextfree languages. LL(k) 156 / 292
50 Lexical and Syntactical Analysis: Concept of specification and implementation: 0 0 [1-9][0-9]* Generator [1 9] [0 9] E E{op}E Generator 157 / 292
51 Lexical and Syntactical Analysis: From Regular Expressions to Finite Automata f t f * f f f a f f f f a b a b a b a 0 b a 1 a b a a 2 a b 3 4 From Finite Automata to Scanners a 02 b 023 w r i t e l n ( " H a l l o " ) ; 1 a 14 A B / 292
52 Lexical and Syntactical Analysis: Computation of lookahead sets: Fǫ(S ) Fǫ(E) Fǫ(E) Fǫ(E) a b c Fǫ(E) Fǫ(T) Fǫ(T) Fǫ(T) Fǫ(T) Fǫ(F) Fǫ(F) {(, name, } a S E T F (,, name 2 From Item-Pushdown Automata to LL(1)-Parsers: S AB i0 S i1 A1 β0 A a B b in An i B β1 β a b γ w First1( ) w First1(First1(γ) 1 First1(β) First1(β0)) w First1(γ) 1 Follow1(B) δ M Output 159 / 292
53 Lexical and Syntactical Analysis: From characteristic to canonical Automata: S E E E+T E T T T T F F E E T T F S E E T T F ( E ) ( F ) F ) F ) F ( ( ( E ) E E E F F + T E +T E T E E E+ E+T F T T F T T F T T F 0 T E F ( ( F F T ( ( 6 E T + 11 ) 8 * 9 7 * F 10 From Shift-Reduce-Parsers to LR(1)-Parsers: S i0 + T E + T 6 γ0 A1 i1 9 4 F + F 4 γ1 Amim * ( F ( F 3 E ) 11 * 5 γm B i ( 8 T ( F ( T E ) 5 8 F 2 ( ( α β T * 7 10 F 2 x w * 7 10 action goto Output 160 / 292
Chapter 4: Bottom-up Analysis 106 / 338
Syntactic Analysis Chapter 4: Bottom-up Analysis 106 / 338 Bottom-up Analysis Attention: Many grammars are not LL(k)! A reason for that is: Definition Grammar G is called left-recursive, if A + A β for
More informationTHEORY OF COMPILATION
Lecture 04 Syntax analysis: top-down and bottom-up parsing THEORY OF COMPILATION EranYahav 1 You are here Compiler txt Source Lexical Analysis Syntax Analysis Parsing Semantic Analysis Inter. Rep. (IR)
More informationBottom-Up Syntax Analysis
Bottom-Up Syntax Analysis Wilhelm/Seidl/Hack: Compiler Design Syntactic and Semantic Analysis, Chapter 3 Reinhard Wilhelm Universität des Saarlandes wilhelm@cs.uni-saarland.de and Mooly Sagiv Tel Aviv
More informationBottom-Up Syntax Analysis
Bottom-Up Syntax Analysis Wilhelm/Seidl/Hack: Compiler Design Syntactic and Semantic Analysis Reinhard Wilhelm Universität des Saarlandes wilhelm@cs.uni-saarland.de and Mooly Sagiv Tel Aviv University
More informationCS 406: Bottom-Up Parsing
CS 406: Bottom-Up Parsing Stefan D. Bruda Winter 2016 BOTTOM-UP PUSH-DOWN AUTOMATA A different way to construct a push-down automaton equivalent to a given grammar = shift-reduce parser: Given G = (N,
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: LR(0) Grammars LR(0) Grammars The case k = 0 is
More informationBottom-Up Syntax Analysis
Bottom-Up Syntax Analysis Wilhelm/Maurer: Compiler Design, Chapter 8 Reinhard Wilhelm Universität des Saarlandes wilhelm@cs.uni-sb.de and Mooly Sagiv Tel Aviv University sagiv@math.tau.ac.il Subjects Functionality
More informationShift-Reduce parser E + (E + (E) E [a-z] In each stage, we shift a symbol from the input to the stack, or reduce according to one of the rules.
Bottom-up Parsing Bottom-up Parsing Until now we started with the starting nonterminal S and tried to derive the input from it. In a way, this isn t the natural thing to do. It s much more logical to start
More informationParsing -3. A View During TD Parsing
Parsing -3 Deterministic table-driven parsing techniques Pictorial view of TD and BU parsing BU (shift-reduce) Parsing Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1) Problems with
More informationLR2: LR(0) Parsing. LR Parsing. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class
LR2: LR(0) Parsing LR Parsing CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Parsing - Roadmap Parser: decision procedure: builds a parse tree Top-down vs. bottom-up
More informationSyntax Analysis (Part 2)
Syntax Analysis (Part 2) Martin Sulzmann Martin Sulzmann Syntax Analysis (Part 2) 1 / 42 Bottom-Up Parsing Idea Build right-most derivation. Scan input and seek for matching right hand sides. Terminology
More informationn Top-down parsing vs. bottom-up parsing n Top-down parsing n Introduction n A top-down depth-first parser (with backtracking)
Announcements n Quiz 1 n Hold on to paper, bring over at the end n HW1 due today n HW2 will be posted tonight n Due Tue, Sep 18 at 2pm in Submitty! n Team assignment. Form teams in Submitty! n Top-down
More informationType 3 languages. Type 2 languages. Regular grammars Finite automata. Regular expressions. Type 2 grammars. Deterministic Nondeterministic.
Course 7 1 Type 3 languages Regular grammars Finite automata Deterministic Nondeterministic Regular expressions a, a, ε, E 1.E 2, E 1 E 2, E 1*, (E 1 ) Type 2 languages Type 2 grammars 2 Brief history
More informationCMSC 330: Organization of Programming Languages. Pushdown Automata Parsing
CMSC 330: Organization of Programming Languages Pushdown Automata Parsing Chomsky Hierarchy Categorization of various languages and grammars Each is strictly more restrictive than the previous First described
More informationPARSING AND TRANSLATION November 2010 prof. Ing. Bořivoj Melichar, DrSc. doc. Ing. Jan Janoušek, Ph.D. Ing. Ladislav Vagner, Ph.D.
PARSING AND TRANSLATION November 2010 prof. Ing. Bořivoj Melichar, DrSc. doc. Ing. Jan Janoušek, Ph.D. Ing. Ladislav Vagner, Ph.D. Preface More than 40 years of previous development in the area of compiler
More informationCompiler Design 1. LR Parsing. Goutam Biswas. Lect 7
Compiler Design 1 LR Parsing Compiler Design 2 LR(0) Parsing An LR(0) parser can take shift-reduce decisions entirely on the basis of the states of LR(0) automaton a of the grammar. Consider the following
More informationI 1 : {S S } I 2 : {S X ay, Y X } I 3 : {S Y } I 4 : {X b Y, Y X, X by, X c} I 5 : {X c } I 6 : {S Xa Y, Y X, X by, X c} I 7 : {X by } I 8 : {Y X }
Let s try building an SLR parsing table for another simple grammar: S XaY Y X by c Y X S XaY Y X by c Y X Canonical collection: I 0 : {S S, S XaY, S Y, X by, X c, Y X} I 1 : {S S } I 2 : {S X ay, Y X }
More informationContext free languages
Context free languages Syntatic parsers and parse trees E! E! *! E! (! E! )! E + E! id! id! id! 2 Context Free Grammars The CF grammar production rules have the following structure X α being X N and α
More informationCurs 8. LR(k) parsing. S.Motogna - FL&CD
Curs 8 LR(k) parsing Terms Reminder: rhp = right handside of production lhp = left handside of production Prediction see LL(1) Handle = symbols from the head of the working stack that form (in order) a
More informationOn LR(k)-parsers of polynomial size
On LR(k)-parsers of polynomial size Norbert Blum October 15, 2013 Abstract Usually, a parser for an LR(k)-grammar G is a deterministic pushdown transducer which produces backwards the unique rightmost
More informationAdministrivia. Test I during class on 10 March. Bottom-Up Parsing. Lecture An Introductory Example
Administrivia Test I during class on 10 March. Bottom-Up Parsing Lecture 11-12 From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS14 Lecture 11 1 2/20/08 Prof. Hilfinger CS14 Lecture 11 2 Bottom-Up
More informationINF5110 Compiler Construction
INF5110 Compiler Construction Parsing Spring 2016 1 / 131 Outline 1. Parsing Bottom-up parsing Bibs 2 / 131 Outline 1. Parsing Bottom-up parsing Bibs 3 / 131 Bottom-up parsing: intro LR(0) SLR(1) LALR(1)
More informationSyntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 3. Y.N. Srikant
Syntax Analysis: Context-free Grammars, Pushdown Automata and Part - 3 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler
More informationBottom-up syntactic parsing. LR(k) grammars. LR(0) grammars. Bottom-up parser. Definition Properties
Course 8 1 Bottom-up syntactic parsing Bottom-up parser LR(k) grammars Definition Properties LR(0) grammars Characterization theorem for LR(0) LR(0) automaton 2 a 1... a i... a n # X 1 X 1 Control Parsing
More information60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor
60-354, Theory of Computation Fall 2013 Asish Mukhopadhyay School of Computer Science University of Windsor Pushdown Automata (PDA) PDA = ε-nfa + stack Acceptance ε-nfa enters a final state or Stack is
More informationBottom-Up Parsing. Ÿ rm E + F *idÿ rm E +id*idÿ rm T +id*id. Ÿ rm F +id*id Ÿ rm id + id * id
Bottom-Up Parsing Attempts to traverse a parse tree bottom up (post-order traversal) Reduces a sequence of tokens to the start symbol At each reduction step, the RHS of a production is replaced with LHS
More informationCS415 Compilers Syntax Analysis Top-down Parsing
CS415 Compilers Syntax Analysis Top-down Parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Announcements Midterm on Thursday, March 13
More informationLecture VII Part 2: Syntactic Analysis Bottom-up Parsing: LR Parsing. Prof. Bodik CS Berkley University 1
Lecture VII Part 2: Syntactic Analysis Bottom-up Parsing: LR Parsing. Prof. Bodik CS 164 -- Berkley University 1 Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient
More informationEXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully
EXAM Please read all instructions, including these, carefully There are 7 questions on the exam, with multiple parts. You have 3 hours to work on the exam. The exam is open book, open notes. Please write
More informationCA Compiler Construction
CA4003 - Compiler Construction Bottom Up Parsing David Sinclair Bottom Up Parsing LL(1) parsers have enjoyed a bit of a revival thanks to JavaCC. LL(k) parsers must predict which production rule to use
More informationBottom-up syntactic parsing. LR(k) grammars. LR(0) grammars. Bottom-up parser. Definition Properties
Course 8 1 Bottom-up syntactic parsing Bottom-up parser LR(k) grammars Definition Properties LR(0) grammars Characterization theorem for LR(0) LR(0) automaton 2 a 1... a i... a n # X 1 X 1 Control Parsing
More informationCS Rewriting System - grammars, fa, and PDA
Restricted version of PDA If (p, γ) δ(q, a, X), a Σ {ε}, p. q Q, X Γ. restrict γ Γ in three ways: i) if γ = YX, (q, ay, Xβ) (p, y, YXβ) push Y Γ, ii) if γ = X, (q, ay, Xβ) (p, y, Xβ) no change on stack,
More informationCS20a: summary (Oct 24, 2002)
CS20a: summary (Oct 24, 2002) Context-free languages Grammars G = (V, T, P, S) Pushdown automata N-PDA = CFG D-PDA < CFG Today What languages are context-free? Pumping lemma (similar to pumping lemma for
More informationCreating a Recursive Descent Parse Table
Creating a Recursive Descent Parse Table Recursive descent parsing is sometimes called LL parsing (Left to right examination of input, Left derivation) Consider the following grammar E TE' E' +TE' T FT'
More information1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,
1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u, v, x, y, z as per the pumping theorem. 3. Prove that
More informationSLR(1) and LALR(1) Parsing for Unrestricted Grammars. Lawrence A. Harris
SLR(1) and LALR(1) Parsing for Unrestricted Grammars Lawrence A. Harris Abstract Simple LR(1) and lookahead LR(1) phrase structure grammars are defined and corresponding deterministic two-pushdown automata
More informationSyntax Analysis Part I
1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2013 2 Position of a Parser in the Compiler Model Source Program Lexical Analyzer
More informationWhy augment the grammar?
Why augment the grammar? Consider -> F + F FOLLOW F -> i ---------------- 0:->.F+ ->.F F->.i i F 2:F->i. Action Goto + i $ F ----------------------- 0 s2 1 1 s3? 2 r3 r3 3 s2 4 1 4? 1:->F.+ ->F. i 4:->F+.
More informationCompiler Design Spring 2017
Compiler Design Spring 2017 3.4 Bottom-up parsing Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation 1 Bottom up parsing Goal: Obtain rightmost derivation in reverse w S Reduce
More informationBriefly on Bottom-up
Briefly on Bottom-up Paola Quaglia University of Trento November 11, 2017 Abstract These short notes provide descriptions and references relative to the construction of parsing tables for SLR(1), for LR(1),
More informationCSE302: Compiler Design
CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 27, 2007 Outline Recap
More informationEverything You Always Wanted to Know About Parsing
Everything You Always Wanted to Know About Parsing Part IV : Parsing University of Padua, Italy ESSLLI, August 2013 Introduction First published in 1968 by Jay in his PhD dissertation, Carnegie Mellon
More informationIntroduction to Bottom-Up Parsing
Introduction to Bottom-Up Parsing Outline Review LL parsing Shift-reduce parsing The LR parsing algorithm Constructing LR parsing tables 2 Top-Down Parsing: Review Top-down parsing expands a parse tree
More informationIntroduction to Bottom-Up Parsing
Introduction to Bottom-Up Parsing Outline Review LL parsing Shift-reduce parsing The LR parsing algorithm Constructing LR parsing tables Compiler Design 1 (2011) 2 Top-Down Parsing: Review Top-down parsing
More informationSyntactic Analysis. Top-Down Parsing
Syntactic Analysis Top-Down Parsing Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in Compilers class at University of Southern California (USC) have explicit permission to make
More informationBottom-up syntactic parsing. LR(k) grammars. LR(0) grammars. Bottom-up parser. Definition Properties
Course 9-10 1 Bottom-up syntactic parsing Bottom-up parser LR(k) grammars Definition Properties LR(0) grammars Characterization theorem for LR(0) LR(0) automaton 2 a 1... a i... a n # X 1 X 1 Control Parsing
More informationΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 7a Syntax Analysis Elias Athanasopoulos
ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών Lecture 7a Syntax Analysis Elias Athanasopoulos eliasathan@cs.ucy.ac.cy Operator-precedence Parsing A class of shiq-reduce parsers that can be writen by hand
More informationComputer Science 160 Translation of Programming Languages
Computer Science 160 Translation of Programming Languages Instructor: Christopher Kruegel Building a Handle Recognizing Machine: [now, with a look-ahead token, which is LR(1) ] LR(k) items An LR(k) item
More informationTalen en Compilers. Johan Jeuring , period 2. October 29, Department of Information and Computing Sciences Utrecht University
Talen en Compilers 2015-2016, period 2 Johan Jeuring Department of Information and Computing Sciences Utrecht University October 29, 2015 12. LL parsing 12-1 This lecture LL parsing Motivation Stack-based
More informationCompiler Construction Lent Term 2015 Lectures (of 16)
Compiler Construction Lent Term 2015 Lectures 13 --- 16 (of 16) 1. Return to lexical analysis : application of Theory of Regular Languages and Finite Automata 2. Generating Recursive descent parsers 3.
More informationCompiler Construction Lent Term 2015 Lectures (of 16)
Compiler Construction Lent Term 2015 Lectures 13 --- 16 (of 16) 1. Return to lexical analysis : application of Theory of Regular Languages and Finite Automata 2. Generating Recursive descent parsers 3.
More informationSyntax Analysis Part I
1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2013 2 Position of a Parser in the Compiler Model Source Program Lexical Analyzer
More informationEXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully
EXAM Please read all instructions, including these, carefully There are 7 questions on the exam, with multiple parts. You have 3 hours to work on the exam. The exam is open book, open notes. Please write
More informationBottom up parsing. General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing);
Bottom up parsing General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing); 1 Top-down vs Bottom-up Bottom-up more powerful than top-down; Can process
More informationLL conflict resolution using the embedded left LR parser
DOI: 10.2298/CSIS111216023S LL conflict resolution using the embedded left LR parser Boštjan Slivnik University of Ljubljana Faculty of Computer and Information Science Tržaška cesta 25, 1000 Ljubljana,
More informationSyntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4
1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van ngelen, Flora State University, 2007 Position of a Parser in the Compiler Model 2 Source Program Lexical Analyzer Lexical
More information8. LL(k) Parsing. Canonical LL(k) parser dual of the canonical LR(k) parser generalization of strong LL(k) parser
3/8/18 8. 8. LL(k) Parsing 1 1 8. LL(k) Parsing Canonical LL(k) parser The most general deterministic parsing method in which the input string is parsed (1) in a single Left-to-right scan, (2) producing
More informationContext-free Languages and Pushdown Automata
Context-free Languages and Pushdown Automata Finite Automata vs CFLs E.g., {a n b n } CFLs Regular From earlier results: Languages every regular language is a CFL but there are CFLs that are not regular
More informationIntroduction to Bottom-Up Parsing
Outline Introduction to Bottom-Up Parsing Review LL parsing Shift-reduce parsing he LR parsing algorithm Constructing LR parsing tables 2 op-down Parsing: Review op-down parsing expands a parse tree from
More informationParsing Algorithms. CS 4447/CS Stephen Watt University of Western Ontario
Parsing Algorithms CS 4447/CS 9545 -- Stephen Watt University of Western Ontario The Big Picture Develop parsers based on grammars Figure out properties of the grammars Make tables that drive parsing engines
More informationBottom-Up Syntax Analysis
Bottom-Up Syntax Analysis Mooly Sagiv http://www.cs.tau.ac.il/~msagiv/courses/wcc13.html Textbook:Modern Compiler Design Chapter 2.2.5 (modified) 1 Pushdown automata Deterministic fficient Parsers Report
More informationIntroduction to Bottom-Up Parsing
Outline Introduction to Bottom-Up Parsing Review LL parsing Shift-reduce parsing he LR parsing algorithm Constructing LR parsing tables Compiler Design 1 (2011) 2 op-down Parsing: Review op-down parsing
More information컴파일러입문 제 3 장 정규언어
컴파일러입문 제 3 장 정규언어 목차 3.1 정규문법과정규언어 3.2 정규표현 3.3 유한오토마타 3.4 정규언어의속성 Regular Language Page 2 정규문법과정규언어 A study of the theory of regular languages is often justified by the fact that they model the lexical
More information1. For the following sub-problems, consider the following context-free grammar: S AB$ (1) A xax (2) A B (3) B yby (5) B A (6)
ECE 468 & 573 Problem Set 2: Contet-free Grammars, Parsers 1. For the following sub-problems, consider the following contet-free grammar: S AB$ (1) A A (2) A B (3) A λ (4) B B (5) B A (6) B λ (7) (a) What
More informationLR(1) Parsers Part III Last Parsing Lecture. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved.
LR(1) Parsers Part III Last Parsing Lecture Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. LR(1) Parsers A table-driven LR(1) parser looks like source code Scanner Table-driven Parser
More informationAccept or reject. Stack
Pushdown Automata CS351 Just as a DFA was equivalent to a regular expression, we have a similar analogy for the context-free grammar. A pushdown automata (PDA) is equivalent in power to contextfree grammars.
More informationCompiler Construction Lectures 13 16
Compiler Construction Lectures 13 16 Lent Term, 2013 Lecturer: Timothy G. Griffin 1 Generating Lexical Analyzers Source Program Lexical Analyzer tokens Parser Lexical specification Scanner Generator LEX
More informationFormal Languages and Automata
Formal Languages and Automata Lecture 6 2017-18 LFAC (2017-18) Lecture 6 1 / 31 Lecture 6 1 The recognition problem: the Cocke Younger Kasami algorithm 2 Pushdown Automata 3 Pushdown Automata and Context-free
More informationCS415 Compilers Syntax Analysis Bottom-up Parsing
CS415 Compilers Syntax Analysis Bottom-up Parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review: LR(k) Shift-reduce Parsing Shift reduce
More informationDefinition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where
Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the
More informationCompiling Techniques
Lecture 5: Top-Down Parsing 6 October 2015 The Parser Context-Free Grammar (CFG) Lexer Source code Scanner char Tokeniser token Parser AST Semantic Analyser AST IR Generator IR Errors Checks the stream
More informationTHEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET
THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET Regular Languages and FA A language is a set of strings over a finite alphabet Σ. All languages are finite or countably infinite. The set of all languages
More informationTop-Down Parsing and Intro to Bottom-Up Parsing
Predictive Parsers op-down Parsing and Intro to Bottom-Up Parsing Lecture 7 Like recursive-descent but parser can predict which production to use By looking at the next few tokens No backtracking Predictive
More informationFundamentele Informatica II
Fundamentele Informatica II Answer to selected exercises 5 John C Martin: Introduction to Languages and the Theory of Computation M.M. Bonsangue (and J. Kleijn) Fall 2011 5.1.a (q 0, ab, Z 0 ) (q 1, b,
More informationEXAM. Please read all instructions, including these, carefully NAME : Problem Max points Points 1 10 TOTAL 100
EXAM Please read all instructions, including these, carefully There are 7 questions on the exam, with multiple parts. You have 3 hours to work on the exam. The exam is open book, open notes. Please write
More informationComputational Models - Lecture 4
Computational Models - Lecture 4 Regular languages: The Myhill-Nerode Theorem Context-free Grammars Chomsky Normal Form Pumping Lemma for context free languages Non context-free languages: Examples Push
More informationHarvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs
Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harry Lewis October 8, 2013 Reading: Sipser, pp. 119-128. Pushdown Automata (review) Pushdown Automata = Finite automaton
More informationChapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009
Chapter 1 Formal and View Lecture on the 28th April 2009 Formal of PA Faculty of Information Technology Brno University of Technology 1.1 Aim of the Lecture 1 Define pushdown automaton in a formal way
More informationFoundations of Informatics: a Bridging Course
Foundations of Informatics: a Bridging Course Week 3: Formal Languages and Semantics Thomas Noll Lehrstuhl für Informatik 2 RWTH Aachen University noll@cs.rwth-aachen.de http://www.b-it-center.de/wob/en/view/class211_id948.html
More informationCompiling Techniques
Lecture 5: Top-Down Parsing 26 September 2017 The Parser Context-Free Grammar (CFG) Lexer Source code Scanner char Tokeniser token Parser AST Semantic Analyser AST IR Generator IR Errors Checks the stream
More informationEverything You Always Wanted to Know About Parsing
Everything You Always Wanted to Know About Parsing Part V : LR Parsing University of Padua, Italy ESSLLI, August 2013 Introduction Parsing strategies classified by the time the associated PDA commits to
More informationSyntax Analysis, VI Examples from LR Parsing. Comp 412
COMP 412 FALL 2017 Syntax Analysis, VI Examples from LR Parsing Comp 412 source code IR IR target code Front End Optimizer Back End Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved.
More informationTheory of Computation - Module 3
Theory of Computation - Module 3 Syllabus Context Free Grammar Simplification of CFG- Normal forms-chomsky Normal form and Greibach Normal formpumping lemma for Context free languages- Applications of
More informationMA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation CFL Hierarchy CFL Decision Problems Your Questions? Previous class days' material Reading Assignments HW 12 or 13 problems Anything else I have included some slides online
More informationPage 1. Compiler Lecture Note, (Regular Language) 컴파일러입문 제 3 장 정규언어. Database Lab. KHU
Page 1 컴파일러입문 제 3 장 정규언어 Page 2 목차 I. 정규문법과정규언어 II. 정규표현 III. 유한오토마타 VI. 정규언어의속성 Page 3 정규문법과정규언어 A study of the theory of regular languages is often justified by the fact that they model the lexical analysis
More informationCompiling Techniques
Lecture 6: 9 October 2015 Announcement New tutorial session: Friday 2pm check ct course webpage to find your allocated group Table of contents 1 2 Ambiguity s Bottom-Up Parser A bottom-up parser builds
More informationChomsky Normal Form for Context-Free Gramars
Chomsky Normal Form for Context-Free Gramars Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. 17 September 2014 Outline 1 CNF 2 Converting to CNF 3 Correctness
More informationParsing VI LR(1) Parsers
Parsing VI LR(1) Parsers N.B.: This lecture uses a left-recursive version of the SheepNoise grammar. The book uses a rightrecursive version. The derivations (& the tables) are different. Copyright 2005,
More informationParsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26
Parsing Context-Free Grammars (CFG) Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Winter 2017/18 1 / 26 Table of contents 1 Context-Free Grammars 2 Simplifying CFGs Removing useless symbols Eliminating
More informationFORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY REVIEW for MIDTERM 1 THURSDAY Feb 6 Midterm 1 will cover everything we have seen so far The PROBLEMS will be from Sipser, Chapters 1, 2, 3 It will be
More informationFinite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018
Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 14 Ana Bove May 14th 2018 Recap: Context-free Grammars Simplification of grammars: Elimination of ǫ-productions; Elimination of
More informationAnnouncements. H6 posted 2 days ago (due on Tue) Midterm went well: Very nice curve. Average 65% High score 74/75
Announcements H6 posted 2 days ago (due on Tue) Mterm went well: Average 65% High score 74/75 Very nice curve 80 70 60 50 40 30 20 10 0 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96 101 106
More informationCompiler Principles, PS4
Top-Down Parsing Compiler Principles, PS4 Parsing problem definition: The general parsing problem is - given set of rules and input stream (in our case scheme token input stream), how to find the parse
More informationLecture 11 Sections 4.5, 4.7. Wed, Feb 18, 2009
The s s The s Lecture 11 Sections 4.5, 4.7 Hampden-Sydney College Wed, Feb 18, 2009 Outline The s s 1 s 2 3 4 5 6 The LR(0) Parsing s The s s There are two tables that we will construct. The action table
More informationPushdown Automata: Introduction (2)
Pushdown Automata: Introduction Pushdown automaton (PDA) M = (K, Σ, Γ,, s, A) where K is a set of states Σ is an input alphabet Γ is a set of stack symbols s K is the start state A K is a set of accepting
More informationFinal exam study sheet for CS3719 Turing machines and decidability.
Final exam study sheet for CS3719 Turing machines and decidability. A Turing machine is a finite automaton with an infinite memory (tape). Formally, a Turing machine is a 6-tuple M = (Q, Σ, Γ, δ, q 0,
More informationUNIT-VI PUSHDOWN AUTOMATA
Syllabus R09 Regulation UNIT-VI PUSHDOWN AUTOMATA The context free languages have a type of automaton that defined them. This automaton, called a pushdown automaton, is an extension of the nondeterministic
More informationTheory of Computation Turing Machine and Pushdown Automata
Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type
More informationCDM Parsing and Decidability
CDM Parsing and Decidability 1 Parsing Klaus Sutner Carnegie Mellon Universality 65-parsing 2017/12/15 23:17 CFGs and Decidability Pushdown Automata The Recognition Problem 3 What Could Go Wrong? 4 Problem:
More informationProf. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan
Language Processing Systems Prof. Mohamed Hamada Software Engineering La. The University of izu Japan Syntax nalysis (Parsing) 1. Uses Regular Expressions to define tokens 2. Uses Finite utomata to recognize
More information