Compiler Design - Sample Questions
Compiler Design - Sample Questions
5. A given grammar is not LL(1) if the parsing table of a grammar may contain
a) any blank field
b) duplicate entry of same production
c) more than one production rule in a cell
d) any field mentioned as error
1
8. Which of the following software tool is a LALR Parser generator?
a) Lex
b) Yacc
c) Both Lex and Yacc
d) Neither Lex nor Yacc
9. YACC builds up
a) SLR Parsing Table
b) LALR Parsing Table
c) CLR Parsing Table
d) LL Parsing Table
10. Which of the following derivations does a top-down parser use while parsing an input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation,
d) Rightmost derivation in reverse
11. Which of the following derivations does a bottom-up parser use while parsing an input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation,
d) Rightmost derivation in reverse
14. Which of the following grammar rules violate the requirements of an operator grammar? P, Q, R are non-
terminals and r, s, t are terminals.
1. P → Q R
2. P → Q s R
3. P → ε
4. P → Q t R r
a) 1 only
b) 1 and 3 only
c) 2 and 3 only
d) 3 and 4 only
2
15. Parse tree is generated in the phase of
a) Syntax Analysis
b) Semantic Analysis
c) Code Optimization
d) Intermediate Code Generation
3
21. Which data structure is mainly used in shift-reduce parsing?
a) stack
b) queue
c) array
d) pointer
E→E+n
E→E*n
E→n
For a sentence n + n × n, the handles in the right-sentential form of the reduction are
S → ACB | CbB | Ba | BD
A → ae | BC
B→b|ε
C→c|ε
D→d
The FIRST(S) is
a) { a,b,c,d }
b) { a,b,c,d,ε }
c) { a,b,c,ε}
d) { a,b,d,ε }
24. A grammar that produces more than one parse tree for some sentence is called as
a) Ambiguous
b) Unambiguous
c) Regular
d) All of these
4
Short / Long Answer Type Questions:
5
17. Consider the following grammar G:
S → iEtS | iEtSeS | a
E→b
Find an equivalent left-factored grammar of the above grammar.
18. Consider the following grammar G:
A → aAB | aBc | aAc
Find an equivalent left-factored grammar of the above grammar.
19. Construct a LL(1) Parsing Table for the following grammar:
E → E+T | T
T → T*F | F
F → (E) | id
Explain the LL(1) Parser’s action by describing the moves it would make on an input id*id+id
20. Prepare a LL(1) Parsing Table for the following grammar:
E → E+T | T
T → T*F | F
F → id
Explain the LL(1) Parser’s action by describing the moves it would make on an input id+id*id$
21. What is operator grammar? Explain with an example.
22. Compute the collection of LR(0) item the following grammar.
E → E+T | T
T → T*F | F
F → id
Construct the SLR parsing table using the SLR algorithm
23. Compute the collection of LR(0) item sets for the following grammar.
S → CC
C → cC | d
Construct the SLR parsing table using the SLR algorithm
24. Deduce the collection or set of LR(1) items for the following grammar.
S→ AA
A → aA | b
Prepare the CLR parsing table using the CLR algorithm.
25. What do you mean by Inherited Attribute and Synthesized Attribute for Syntax Directed Translation?
Explain with examples.
26. What do you mean by S-attributed and L-attributed Syntax Directed Translation? Explain with
examples.
27. Explain dependency graph with suitable example.
28. Generate an annotated parse tree for the string “3+5−2” using the grammar:
E → E+T | E−T | T
T → 0 | 1 | 2 | 3| 4 | 5| 6 | 7 | 8 | 9
29. What is syntax tree? Translate the expression a*(b+c/d) into syntax tree.
30. Translate the expression
a=–b*(c+d/b)−(e*f)
into
i) 3-address code ii) Quadruple iii) Triple iv) Indirect Triple
31. Translate the following expression
x=(a+b)*(c+d)+(a+b+c)
into
i) 3-address code ii) Quadruple iii) Triple iv) Indirect Triple
6
32. Construct the DAG for the following basic block
d:= b*c
e:= a+b
b:= b*c
a:= e-d
33. Sketch out the DAG for the following basic block
x=a+b*−c+b*-c
34. Write short notes on Context Free Grammar.
35. Write short notes on Ambiguous Grammar.
36. Write short notes on Lex.
37. Write short notes on Yacc
38. Write short notes on Parse Tree.
39. Write short notes on Annotated Parse Tree.
40. Write short notes on Peephole Optimization.