










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!











Shift-Reduce parsing
x + y + z?
stack Input Action if x t if y t s2 e s3?
suppose both procedure call and array reference have similar syntax:
stack Input Action
id ( id ) id?
Should id reduce to a parameter or an expression. Depends on whether the bottom most id is an array or a procedure.
state
terminals non-terminals
0 1
2
id + * ( ) $ E T F
shift (state = 5)
reduce(prod = 12)
goto(state = 2)
state
terminals non-terminals
0 1 2 3 4 5 6 7 8 9
10
11
id +^ * (^ )^ $^ E^ T^ F
s5 s4 (^1 2 )
s6 acc
r2 (^) s7 r2 r r4 r4 (^) r r s5 (^) s4 8 2 3 r6 (^) r6 r6 (^) r
s5 (^) s4 (^9 )
s5 s4 10
s6 s
r1 (^) s7 r1 (^) r
r3 r3^ r3^ r
r5 r5 r5 (^) r
Stack Input
(?,0) id * id + id $
(?,0)(id,5) * id + id $
(?,0)(F,3) * id + id $
(?,0)(T,2) * id + id $
(?,0)(T,2)(*,7) id + id $
(?,0)(T,2)(*,7)(id,5) + id $
(?,0)(T,2)(*,7)(F,10) + id $
(?,0)(T,2) + id $
(?,0)(E,1) + id $
(?,0)(E,1)(+,6) id $
(?,0)(E,1)(+,6)(id,5) $
(?,0)(E,1)(+,6)(F,3) $
(?,0)(E,1)(+,6)(T,9) $
(?,0)(E,1) $
some RHS of a production.
Example closure construction
Start of with the single item derived from the start symbol.
I = { E’ ->. E }
Then the closure of I contains:
{ E’ ->. E,
E ->. E + T,
E -> .T
T ->. T * F
T ->. F
F ->. ( E )
F ->. id }
6) F -> id