JAMIA HAMDARD
Department of Computer Science & Engineering
School of Engineering Sciences & Technology
Tutorial 1- Compiler Design
Question 1. Eliminate left recursion from the following grammar:
S→Sa|bS|b
Question 2. Eliminate left recursion from the following grammar:
exp→ exp addop term | term
addop→ + | -
term → term mulop factor | factor
mulop → *
factor → (exp) | number
Question 3. Left-factor the following grammar:
S → if E then S else S
S → if E then S
S → other
Question 4. For the grammar:
E→E+T|T
T→T*F|F
F → ( E ) | id
Write the leftmost derivation & rightmost derivation of the string id + id * id.
Question 5. From the grammar below S -> SS+ | SS* | a derive the string aa+a* using both
leftmost derivation & rightmost derivation.