Assignment on Unit 2
Course: Compiler Design(TCS-601)
Instructions
• Answer all questions with proper explanations and examples.
• Show step-by-step derivations wherever applicable.
• Use standard notation for grammar rules and parsing tables.
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’.
Q4. Bottom-Up Parsing Solve the following bottom-up parsing prob-
lems:
(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.
Q6. Removal of Ambiguous Grammar Given the following ambigu-
ous grammar, transform it into an equivalent unambiguous grammar:
E → E + E|E ∗ E|(E)|id
Show the derivation of an example expression before and after removal of
ambiguity.
Q7. Operator Precedence Grammar Problem Consider the follow-
ing grammar:
E → E + E|E ∗ E|id
(a) Construct the operator precedence table.
(b) Show the parsing steps for the expression: id + id ∗ 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?
Q9. Parser Generators What are parser generators? Explain their
role in compiler construction. Mention some widely used parser generators.
Q10. Comparison of Parsing Techniques Compare LL(1) and LR(1)
parsers based on:
• Parsing approach
• Grammar restrictions
• Lookahead requirements
• Examples