0% found this document useful (0 votes)
29 views12 pages

Compiler Design Project: For DR, Elie Nasr by Anwar Zouyhed 12040411

This document contains an example grammar and the steps to construct the LR(1) and LALR(1) parsing tables for that grammar. It shows: 1) The example grammar. 2) The DFA of LR(1) items and general LR(1) parsing table. 3) The DFA of LALR(1) items and LALR(1) parsing table. 4) The potential difference between LR(1) and LALR(1) parsing is that LALR(1) may perform some spurious reductions before declaring an error.

Uploaded by

Anwar Zouyhed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views12 pages

Compiler Design Project: For DR, Elie Nasr by Anwar Zouyhed 12040411

This document contains an example grammar and the steps to construct the LR(1) and LALR(1) parsing tables for that grammar. It shows: 1) The example grammar. 2) The DFA of LR(1) items and general LR(1) parsing table. 3) The DFA of LALR(1) items and LALR(1) parsing table. 4) The potential difference between LR(1) and LALR(1) parsing is that LALR(1) may perform some spurious reductions before declaring an error.

Uploaded by

Anwar Zouyhed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

Compiler design project

For Dr, Elie nasr


By Anwar zouyhed
12040411

Example 5.2
5.2 Consider the following grammar:
E E$
E (L)
Ea
L L,E
L E

5.2 / a
a. Construct the DFA of LR(1) items for this
grammar.

Stage 0
E.E, $

E.(L), $
E.a,

Stage 9

EE. , $

LL,.E, )

Stage 3

E.(L), )

E(L.), ,

Ea. , $

E.a,

LL.,E, )

LL,.E , ,

LL.,E, ,

$
Stage 4

E(L.) , $

Stage 2
E (.L) , $

LL.,E , )

LL.,E , ,

L .L,E , )
L .E

,)
a

, ,

E.a,

E .a , )

E.(L) ,

[E.a

Stage 12

E(L.), )

E.(L), ,

E(L)., )

E(L)., ,
Stage 11
LL,E. , )

LL,E. , ,

Stage 6
a

Stage 8

Stage 7

E(L)., $

Ea., )

E(.L),

E(.L),

L.L,E , )
L.E ,

Ea., ,

E .(L) , )

L .L,E , ,
L .E

Stage 10

Stage 1

L.L,E , ,

L.E ,

Stage 5
LE. , )
LE. , ,

E.(L), ()
E.a,

()

E.(L), ,
E.a, , ,

5.2 / b
b. Construct the general LR(1) parsing table.

b.

r1: E(L) r2: E a

r3: LL,E r4: LE

State

Input

S2

S3

Goto
)

S6

S7

10

r2

S8

S9

r4

r4

S6

S7

r2

r2

8
9

Accept

1
2

r1
S6

S7

11

10

S12

S9

11

r3

r3

12

r1

r1

5.2 / c
c. Construct the DFA of LALR(1) items for this
grammar.

Stage 1

Stage 0

EE. , $

E.E, $
E.(L), $
E.a,

Stage 3 / 7

Ea. , $

Ea. , ) /,
Stage 9

Stage 2 / 6
E (.L) , $ /, / )
L .L,E , )
L .E

,)

, ,

Stage 4 / 10

E .(L) , )

E .a , )
E.(L) ,

[E.a

E.(L), )

LE. , )

E.a,

LE. , ,

L .L,E , ,

L .E

LL,.E, )

Stage 5

E(L.) , $ /, / )

Stage 11

LL,.E , ,

LL,E. , )

E.(L), ,

LL,E. , ,

E.a,

LL.,E , )
LL.,E , ,

Stage 8 / 12
E(L)., $ / ) / ,

5.2 / d
d. Construct the LALR(1) parsing table.

5.2 / d
d.

r1: E(L) r2: E a

r3: LL,E r4: LE

State

Input

S2/6

S3/7

Goto
)

Accept
S2/6

S3/7

4/10

3/7

r2

r2

4/10

S8/12

S9

r4

r4

8/12

r1

r1

1
2/6

S2/6

S3/7

r2

r1
11

10

S8/12

S9

11

r3

r3

5.2 / e
e. Describe any difference that might occur
between the actions of a general LR(1) parser
and an LALR(1) parser.

5.2 / e
ANS : The consequence of using LALR(1)
parsing over general LR(1) parsing is that , in
the presence of errors, some spurious
reeducation may be made before error is
declared

You might also like