Week 5 - Notes
Week 5 - Notes
(())
l
l
l
l
l
l
l
Start in qo
Push $ on top of stack (initialisation), move to q1
Consume ( and push ( , stay in q1
Consume ( and push ( , stay in q1
Consume ) and pop (, move to q2
Consume ) and pop (, stay in q2
Pop $ from stack, move to q3
()()
l
l
l
l
l
l
l
Start in qo
Push $ on top of stack (initialisation), move to q1
Consume ( and push ( , stay in q1
Consume ) and pop ( , move to q2
Consume ( and push ( , move to q1
Consume ) and pop ( , stay in q2
Pop $ from stack, move to q3
COMP2022 sem1, 2015, Kalina Yacef
11
Lookahead symbols
Lets consider a grammar with 2 rules for the start symbol
S-> XY | YZ
(other rules of the grammar not shown)
24
FIRST( (B) B) = { ( }
FIRST ( B ) = FIRST( (B)B ) FIRST() ={ (, }
S BC | a
B bB |
C cC |
FIRST() = {}
FIRST(c) = {c}
FIRTST(cC) = {c}
FIRST(C) = FIRST (cC) FIRST() = {c, }
FIRST(B) = FIRST (bB) FIRST() ={b, }
FIRST(S) = FIRST(BC) FIRST(a)= {a,b,c, }
COMP2022 sem1, 2015, Kalina Yacef
35
39
FIRST(BC) = {b, c, }
FIRST(a) = {a}
FIRST(bB) = {b}
FIRST() = {}
FOLLOW(B)={c,$}
FIRST(cC) = {c}
FIRST() = {}
FOLLOW(C)={$}
a
Sa
B
C
COMP2022 sem1, 2015, Kalina Yacef
S BC
S BC
S BC
B bB
C cC
42