Professional Documents
Culture Documents
Khulna University,Khulna,Bangladesh
Submitted To:
Aysha Akther
Submitted by :
Lecturer
Md. Azizul Haque
Computer science & Engineering
Discipline. ID:180235
1.(a).Answer:
A → BwA First(A)=First(B)=First(C) U First(y)={z,y}
A→Ɛ First(A)= {Ɛ};
B → CxB First(B)=First(C)={z}
B → yC First(B)={y}
C→z First(C)={z}
First Functions-
• First(A) = { y, z, Ɛ }
• First(B) = { y,z }
• First(C) = { z }
Follow Functions-
• Follow(A) = { $ }
• Follow(B) = { w }
• Follow(C) = { w,x }
(b).Answer:
By obtaining First and Follow form 1.(a) answer ,generating a parsing table:
Non- Terminal
terminal/Variable w x y z $
A A → BwA A → BwA A→Ɛ
B B → yC B → CxB
C C→z
In order to check if a grammar is LL(1) -
i.) The grammar is not an ambiguous grammar
ii.)The grammar should not be left recursive
iii.)The grammar should be deterministic.
For LL(1) parsing table, no cell should have more than one entry. that means Parsing
table have no FIRST/FIRST conflicts and no FIRST/FOLLOW conflicts.
From the above parsing table, as there are no conflicts, so the given grammar
is LL(1).
Add Augment Production, insert '•' symbol at the first position for every production
in G and also add the look ahead.
The look ahead is used to determine that where we place the final item.
The look ahead always add $ symbol for the argument production.
S` → •S, $ [for augment production, look ahead is always $]
S → •Aa, $
A → •d, a [Look ahead of A→•d is First{a,$}=a]
S → •bAc, $
S → •Bc, $
B → •d, c [Look ahead of B → •d is First{c,$}=c]
S → •bBa, $
Add all productions starting with S in modified I0 State because "•" is followed by
the non-terminal. So, the I0 State becomes.
Following the procedures for constructing the LR(1) parser, here is the resulting
State Diagram / Canonical collection of LR(1) items:
DFA:
I1
I6
S
A c
I2 I7 I11
S A
b B a
I0 I3 l8 I12
B
I9
d I4
I10
I5
Fig: DFA
Parsing Table:
State Action (terminal) Go to (Variable)
a b c d $ S A B
I0 S3 S5 1 2 4
I1 accept
I2 S6
I3 S9 7 8
I4 S10
I5 r5 r6
I6 r1
I7 S11
I8 S12
I9 r6 r5
I10 r3
I11 r2
I12 r4
Since there are no mutiple actions in any entry, the given grammar is LR(1).
However, when obtaining the LALR(1) parsing table by merging states, we will
merge states I5 and I9 , and the resulting state will be as follows:
I5, I9 [production same, but different look ahead]
I59: A → d•, a/c
B →d•, c/a