



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















2
Consider the ambiguous grammar E → E + E | E × E | int
We will DFA state containg [E → E × E•, +] [E → E • + E, +]
4
Again we have a shift/reduce conflict
We need to reduce because × has precedence over +
5
Again we have a shift/reduce conflict
We need to reduce because × has precedence over +
7
This is called a reduce-reduce conflict
Usually due to gross ambiguity in the grammar
8
LR(1) parsing table for even a simple language can be extremely large with thousands of entries.
10
It is possible to reduce the size of the table
Many states in the DFA are similar
11
0
E → int on ),+
int
E
(
E int
E → int on $,+
accept on $
S E→→ • •E, $E+(E), $/+ E→ • int, $/+
E→ int • , $/+ 1
2 SE→→^ EE••, $ +(E), $/+
E→ E+•(E), $/+ 3
E E→→ E+(•E+(E), )/+•E), $/+ 4 E→ • int, )/+ 6 E E→→^ E+(•E+(E), )/+•E), $/+ E→ • int, )/+ E→ int • , )/+ 5
13
These states have the same core
E → int on $,+
E→ int • , $/+ 1 E → int on ),+
E→ int • , )/+ 5
14
Upon merge, we obtain
E → int on $,+,)
E→ int • , $/+/) 1'
16
Example:
the core of { [X → α•β, b], [Y → γ•δ, d] } is { X → α•β, Y → γ•δ }
17
Consider the LR(1) states { [X → α•, a], [Y → β•, c] } { [X → α•, b], [Y → β•, d] } They have the same core and can be merged
19
The merged state contains
{ [X → α•, a/b], [Y → β•, c/d] }
These are called the LALR(1) states
20
The merged state contains
{ [X → α•, a/b], [Y → β•, c/d] }
These are called the LALR(1) states