MADDA WALABU UNIVERSITY
DEPARTMENT OF COMPUTER SCIENCE
COMPILER DESIGN WORK SHEET
May, 2025
▪ Instruction
❖ Do The Following Self-Test Exam Questions 1-13 Properly.
PART I
1. Why lexical and syntax analyser are separated out?
2. What is ambiguous grammar?
3. What is recursive decent parsing?
4. What are the possible error recovery actions in lexical analyser?
5. What is function of parser?
6. Differentiate top-down parsing and bottom-up parsing
7. Draw NFA and DFA automaton for the given regular expression aa*|bb*.
8. Consider the context- free grammar G.
S → (L)|a
L → L,S|S with the input string ((a,a),a,(a))
a. Give the leftmost derivation for the string.
b. Give the rightmost derivation for the string.
c. Give the parse tree for the string.
d. Is the grammar ambiguous or unambiguous? Justify your answer.
9. Consider the following grammar G:
S→A
A → A + A | B++
B→y
a. Draw the parse tree for the input “ y+++y++”.
10. Let G be the following grammar G:
S → [ SX ] | a
X → ε | +SY | Yb
Y → ε | -SXc
a. Find FIRST and FOLLOW sets for the non-terminals in this grammar.
b. Construct predictive parsing table for the grammar above.
c. Show a top-down parse of the string [a+a-ac]
11. Consider the following grammar G:
S → ScB | B
B → e | efg | efCg
C → SdC | S
a. Justify whether the grammar is LL(1) or not?
b. If not, translate the grammar into LL(1).
c. Construct predictive parsing table for the above grammar.
12. Consider the following grammars G, parse the input string w= id + id * id.
E → TE’
E’ → +TE’ |
T → FT’
T’ → FT’ |
F → ( E ) | id
13. Given the following Grammar G:
A → SS
S → aS | b
a. Construct the SLR parsing table.
b. Write the action of an LR parse for the following string aabb