Assignment 2
Assignment 2
Instructions
• Answer all questions with proper explanations and examples.
Questions
Q1. Removal of Left Recursion Remove the left recursion from the
following grammars:
(a) A → Aα|β
(b) B → Ba|Bb|c
(c) S → Aa|b
A → Ac|Aad|bd|ϵ
Q2. Removal of Left Factoring Remove left factoring from the following
grammars:
(a) S → aA|aB
(b) S → aSSbS|aSaSb|abb|b
(c) A → Cd
B → Ce
C → A|B|f
1
Q3. LL(1) Parsing Construct an LL(1) parsing table for the following
grammar:
S → aAB|bBA
A → c|ϵ
B → d|ϵ
Determine if the grammar is LL(1) and justify your answer. Verify the input
’abcd’.
(i) Construct the LR(0) parsing table for the given grammar:
S → aS|b
(ii) Construct the SLR(1) parsing table for the given grammar:
S → aAc|aBd
A→z
B→z
Verify the input azc.
(iii) Construct the CLR(1) parsing table for the given grammar:
S → aAc|aBd|bA|bBc
A→z
B→z
Verify string azc
(iv) Construct the LALR(1) parsing table for the given grammar:
S → aAc|aBd|Bc.
A→z
B→z
2
Q5. Difference between Top-Down and Bottom-Up Parsing.
E → E + E|E ∗ E|(E)|id
Q8. Role of the Parser Explain the role of the parser in the compilation
process. How does it interact with lexical analysis and semantic analysis?
• Parsing approach
• Grammar restrictions
• Lookahead requirements
• Examples