You are on page 1of 12

Chapter-4(Last Part)

▪ LL parse tables computed using FIRST/FOLLOW


▪ Nonterminals  terminals → productions
▪ Computed using FIRST/FOLLOW
▪ LR parsing tables computed using closure/goto
▪ LR states  terminals → shift/reduce actions
▪ LR states  nonterminals → goto state transitions
▪ A grammar is
▪ LL(1) if its LL(1) parse table has no conflicts
▪ SLR if its SLR parse table has no conflicts
▪ LALR if its LALR parse table has no conflicts
▪ LR(1) if its LR(1) parse table has no conflicts

8
LR(1)

LALR
LL(1) SLR

LR(0)

9
stack input
1. S’ → E id + $ E $0 id+id+id$
2. E → E + E 0 s2 1 … …
3. E → id 1 s3 acc $0E1+3E4 +id$
2 r3 r3
3 s2 4   
4 s3/r2 r2
When shifting on +:
yields right associativity
id+(id+id)
Shift/reduce conflict: When reducing on +:
action[4,+] = shift 4 yields left associativity
action[4,+] = reduce E → E + E (id+id)+id 10
▪ Left-associative operators: reduce
▪ Right-associative operators: shift
▪ Operator of higher precedence on stack: reduce
▪ Operator of lower precedence on stack: shift

stack input
$0 id*id+id$
S’ → E
E→E+E … …
E→E*E $0E1*3E5 +id$ reduce E → E * E
E → id
   11
Thank You!!!!

You might also like