Tutorial Questions II: C Byregowda Institute of Technology
Tutorial Questions II: C Byregowda Institute of Technology
Date: 05-04-2019
3. Write the Lex program that recognizes the tokens ws, if, then, else, id, number and relational
operator.
E->E+E|E*E|(E)|I
I->a|b|Ia|Ib|I0|I1
i) Check whether the grammar is ambiguous or not for the input a*b+a
ii) If ambiguous obtain an equivalent unambiguous grammar.
6. What is left recursion? Write an algorithm to eliminate left recursion. Eliminate left recursion
from the following grammar.
S->(L)|a
L->L,S|S
7. What is recursive decent parser? Trace and explain working of the recursive descent parser for
the input “bcd” and grammar:
A->bCd
C->ce|c
8. Construct the predictive parsing table by making necessary changes to the grammar given
below
E->E+T|T
T->T*F|F
F->(E)|id
9. What is Handle pruning? Give Bottom up parses for the input string aaa*a++ using the
grammar
S->SS+ | SS* | a