Sheet
Sheet
Sheet
1. Given the following grammar:
assgstmt identifier := expression
expression identifier
expression number
expression expression + expression
expression expression - expression
expression expression * expression
expression expression / expression
2.
a. Describe the languages denoted by the following regular
expressions:
1. a(a|b)*a
2. ((ε|a)b*)*
3. (a|b)*a(a|b)(a|b)
4. a*ba*ba*ba*
Fig. (1)
Fig. (2)
3.
a. Given the following grammar:
S SS+ |SS* | a
i. Show how the string "aa+a*" can be generated by this
grammar by two different ways and construct the
parse tree for this string. (hint: use leftmost derivation
and rightmost derivation).
ii. Is this grammar ambiguous? Justify by an example.
iii. Is this grammar LL(1)? why?
b. Explain the problem of ambiguity for the if-else grammar
and show how to eliminate it.
c. The Operator Precedence property can solve the ambiguity
of expression grammars, justify by an example.
d. Eliminate the (immediate and indirect) left recursion for the
following grammar(hint: Apply the algorithm):
S→AB
A→CB|b
C→Sa
B→b
e. Factor out the common prefixes of the following grammar:
ET+E|T
T int | int * T | ( E )
4.
a. Convert the following grammar to be LL(1) (hint: Apply the
algorithm of indirect left recursion elimination and the
conditions of LL(1) grammar):
SE
E E+T | T
T E-T | F
F E*F | id
b. The problem of backtracking in Recursive Descent Parser can
be handled using left factoring, justify using an example.
c. Given the following LL(1) grammar:
1 S→Aa
2 A→BD
3 B→b
4 B→ε
5 D→d
6 D→ε
i. Find the FIRST sets and FOLLOW sets for the nonterminals
of the grammar and prove that the predictive parse table
for the given grammar is as follows (hint: Also, this question
can instead give you this table empty to fill in or to find it):