You are on page 1of 2

ASSIGNMENT # 2 (CLO2) Submission Date : 18-11-19

Compiler Construction BCS-7C By : Yasir Awan

Q. 1
Consider the following grammar:
E →(L) | a
L → L, E| E
Part-I
a) Construct the DFA of LR(0) items for this grammar.
b) Construct the SLR(1) parsing table for this grammar.
c) Show the parsing stack and the actions of an SLR(1) parser for the input string
( ( a ), a , (a , a ) ).
d) Is this grammar an LR (0) grammar? If not, describe the LR(0) conflict. If so,
construct the LR(0) parsing table, and describe how a parse might differ from an
SLR(1) parse.
Part-II
a) Construct the DFA of LR(1) items for this grammar.
b) Construct the general LR(1) parsing table.
c) Construct the DFA of LALR(1) items for this grammar.
d) Construct the LALR(1) parsing table.
e) Describe any difference that might occur between the actions of a general LR(1)
parser and an LALR(1) parser.

Q.2
Consider the following grammar:
S → S(S) | ∈
Part-I
a) Construct the DFA of LR(0) items for this grammar.
b) Construct the SLR(1) parsing table for this grammar.
c) Show the parsing stack and the actions of an SLR(1) parser for the input string
( ( ) ( ) ).
d) Is this grammar an LR (0) grammar? If not, describe the LR(0) conflict. If so,
construct the LR(0) parsing table, and describe how a parse might differ from an
SLR(1) parse.
Part-II
a) Construct the DFA of LR(1) items for this grammar.
b) Construct the general LR(1) parsing table.
c) Construct the DFA of LALR(1) items for this grammar.
Q. 3

Trace the behavior of a panic mode error recovery mechanism for the string (*2. using
the following parsing table. (As is discussed on page 246. Example 5.19) the DFA is given
on page 233.(Louden book)
State INPUT Goto

Number ( + - * ) $ command exp term Factor

0 s5 s6 1 2 3 4

1 accept

2 r1 r1 s7 s8 r1 r1 r1

3 r4 r4 r4 r4 s9 r4 r4

4 r6 r6 r6 r6 r6 r6 r6

5 r7 r7 r7 r7 r7 r7 r7

6 s5 s6 10 3 4

7 s5 s6 11 4

8 s5 s6 12 4

9 s5 s6 13

10 s7 s8 s14

11 r2 r2 r2 r2 s9 r2 r2

12 r3 r3 r3 r3 s9 r3 r3

13 r5 r5 r5 r5 r5 r5 r5

14 r8 r8 r8 r8 r8 r8 r8

You might also like