Compiler Design (Past year QNs.
)
Past Year Questions from Year 2073, 2074, 2075, 2076, 2078, 2079, 2080.
Short and Very short Questions: (3 and 8 marks QNs)
1. Draw the block diagram of language processing and describe the structure of compiler.
2. Explain left recursion and show how it is eliminated. Eliminate the left recursion from the
given grammar:
E→E+T|T
T→T*F|F
F → (E) | id
3. What is three address code. Explain quadruple, triples, and indirect triples with examples.
4. Explain the role of parser. List and explain various types of error recovery strategies?
5. What is syntax directed definition? Explain inherited and synthesized attributes.
6. Explain NFA and DFA? Why they are useful in a compiler design.
7. What is code generation? List out the main issues in the design of code generator and
explain any one issue from them.
8. Write short notes on:
a. DAG
b. Dead code elimination
c. Predictive parsing
d. Token and pattern
9. Write the rule to eliminate left recursion in a grammar. Eliminate the left recursion from
the given grammar.
S → Aa | b
A → Ac | Sd |
10. Describe the error recovery scheme in compiler design.
11. Evaluate the expression for the syntax directed definition (SDD) by annotated parse tree.
Input String: 3 * 5 + 4n.
12. Explain in detail about various issues in code generation with examples.
13. What do you mean by 3 address code representation? Describe different types of 3
address code representation schemes with examples.
14. Find FIRST & FOLLOW sets of the following grammar:
E→E+T|T
T→T*F|F
F → (E) | id
15. Explain the role of lexical Analyzer.
16. Show that intermediate code for the following code segment:
while(i < 10)
{
if(i % 2 == 0)
evenSum = EvenSum + 1;
else
oddSum = oddSum + 1;
}
17. Construct a Syntax Directed Translation scheme that translates arithmetic expressions
from infix to postfix notation. Show its application to the string ‘3 * 4 + 5 * 2’.
--Made by Bishal Bhat-- 1
18. Discuss about the role of lexical analyser with possible error recovery actions.
19. Where do we use operator precedence parsing technique? Give the general precedence
table for operator precedence parsing, considering all the generalized rules.
20. Explain various code optimization techniques.
21. Construct minimum state DFA’s for the following Regular expressions:
a. (a | b) * a (a| b)
b. (a | b)* a (a | b) (a | b)
22. Describe peephole optimization technique used in code optimization of compiler design.
23. Discuss generic issues in the design of code generator.
24. Describe local and loop optimization.
25. Eliminate left recursion from the following grammar and rewrite it:
S → Aa | b
A → Ac | Sd |
26. Why regular expression is used in token specification? Write the regular expression to
specify the identifier like in C language.
27. Consider the grammar:
S → SbS | bSaS |
a. Show that the grammar is ambiguous by constructing 2 different leftmost and
rightmost derivation for sentence ‘abab’.
b. Construct the corresponding parse tree for both derivations.
28. What do you mean by S-attributed definition and how they are evaluated? Explain with
example.
29. What do you mean 3 address code representation? Write a 3-address code for the
expression ‘r = 7 * 3 + 9’ and represent this 3-address code in quadruple design.
30. Explain the role of parser. Describe non-recursive predictive parsing techniques.
31. Explain about peephole optimization and dead code optimization with example.
32. What are the different issues in the design of code generator? Explain each briefly.
33. Find FIRST and FOLLOW of the given grammar:
S → CC
C → bc | d
34. Define the terms language translator and compiler.
35. What is DAG? Mention its application in compiler design.
36. What is difference between Parse Tree and Annotated Parse Tree?
37. What is code optimization? Give name of any 2 optimization techniques.
38. What do you mean by left factoring in the grammar?
39. What is a handle in bottom up parsing?
40. Explain the role of code generator in a compiler.
41. What does a semantic analysis do?
42. Discuss the issues in design of simple code generator.
43. Why are regular expressions used in token specification? Write the regular expression to
specify the identifier like in C programming.
44. Describe an algorithm used for eliminating the left recursion. Eliminate left recursion
from the grammar:
S → Aa | b
A → Ac | Sd | a
45. Explain with a neat diagram, the model of a table drive predictive parser.
46. Translate the arithmetic expression: a + - (b + c) into quadruples, triples & indirect triples.
--Made by Bishal Bhat-- 2
47. Define syntax directed definition. Construct annotated parse tree for the input
expression ‘(5 * 3 + 2) * 5’ according to the given syntax directed definition.
Production Semantic Rule
L → En Print E.val
E→E+T E.val → E.val + T.val
E→T E.val → T.val
T→T*F T.val → T.val * F.val
T→F T.val → F.val
F → (E) F.val → (E.val)
F → digit F.val → digit.lexval
48. What are the 2 parts of a compilation? Explain briefly.
49. Write a regular expression for an identifier.
50. What are the problems with top down parsing?
51. Define LR(0) items of the production X → XYZ.
52. Draw the DAG for the statement a = (a * b + c) – (a * b + c).
53. What is the main idea of dead code elimination and constant folding.
54. What is sentinel? What is its usage?
55. Explain synthesized attribute and inherited attribute with suitable examples.
56. Write the rule to eliminate left recursion in a grammar. Prepare and eliminate the left
recursion for the grammar.
S → Aa | b
A → Ac | Sd |
57. Point out why is buffering used in lexical analysis? What are the commonly used
buffering methods?
58. Calculate the FIRST and FOLLOW of the given grammar:
S→A
A → aB | Ad
B→b
C→g
59. What do you mean by 3 address code representation? Explain with example.
60. What is type checking? Discuss static and dynamic checking of types.
61. Distinguish between synthesized and inherited attributes.
62. What are the main 2 parts of compilation? What are they performing?
63. What do you mean by copy propagation?
64. What is register allocation in compiler design?
65. Define DAG. Give an example.
66. What are the various conflicts that occur during shift reduce parsing?
67. Define operator precedence grammar. Explain what LR(k) parsing stands for.
68. What is static checking? Give some examples of static checking.
69. What do you mean by STD? Construct annotated parse tree for the input expression
‘(5*3+2)*5’ with suitable semantic action according to the following production rule.
E → En
E→E+T
E→T
T→T*F
T→F
F → (E)
F → digit
--Made by Bishal Bhat-- 3
70. Write rules to construct FIRST and FOLLOW.
71. What are the basic blocks? Write the algorithm for portioning into blocks.
72. Define 3 address code. Write quadruples, triples, and indirect triples for the expression:
(i * j) + (e + f) * (a * b + c)
73. Explain the peephole optimization technique.
74. How left factoring and right factoring is eliminated from a grammar. Explain with
example?
Long Questions: (12 marks QNs)
75. Explain briefly different storage allocation strategies.
76. Explain any 5 techniques of code optimization used in compiler design.
77. Explain the various phase of compiler design with block diagram.
78. What is LR parsing? Draw a SLR parsing table for the following grammar.
E→E*B|E+B|B
B→0|1
79. Explain Phases of compiler with a neat diagram. Draw an Oracle Process Architecture
Diagram.
80. Explain how the following statement will be translated into every phase:
Position = initial + rate * 60.
81. Explain the phases of compiler? How the following statement will be translated into
every phase:
Position = initial + rate * 60.
82. Consider the following grammar:
S → AS | b
A → SA | a
Construct the SLR parse table for the grammar. Show the actions of the parser for the
input string ‘abab’.
83. What is 3 address code representations? Translate the expression (a*b)+(c*d)+(a*b*c)
into quadruples, triples, and indirect triples.
84. Explain the various phases of compiler design in detail with practical example.
85. Construct SLR parsing table of the following gramma. Also trace the parsing for input
string ‘aa+a*’.
S → SS+
S → SS*
S→a
86. What do you mean by code optimization? Explain the basic block optimization with
example.
87. Discuss the phases of compiler indicating the inputs and outputs of each phase in
translating the statement ‘amount = principle + rate * 36.0’.
88. Construct the CLR parsing table for the given grammar.
E → BB
B → cB | d
89. Explain the following code optimization techniques with examples:
a. Constant propagation
b. Strength reduction
c. Code motion
--Made by Bishal Bhat-- 4
90. Given the grammar:
S → aABb
A→c|
B→d|
a. Compute FIRST and FOLLOW sets.
b. Construct the predictive parsing table.
c. Show the mode made by predictive parser on the input string ‘acdb’.
91. Explain in brief about different principle sources of optimization techniques with suitable
examples.
92. Write about the following in detail:
a. Left factoring
b. Dead code elimination
c. Token and pattern
93. Consider the following grammar:
S → AS | b
A → SA | a
Construct the SLR parse table for the grammar. And, Show the actions of the
parser for the input string ‘abab’.
94. Explain the role of intermediate code generator in compilation process. Write the
quadruple, triple, indirect triple for the statement a = b * – c + b * – c.
95. Explain the principle sources of code optimization with example.
96. Discuss the various phases of compiler and trace the program segment c = a + b * 4 for all
phases.
97. Construct CLR parsing table for the given grammar and parse the string w = abab.
X → YY
Y → aY | b
98. Explain the following:
a. Constant folding and constant propagation
b. Differentiate between L attribute and S attribute.
c. Three address code for:
if a < b then x = y + z
else p = q + r.
Note:
These are all the questions from year 2073 – 2080 year…. The repeating Qns. are most IMP.
***
--Made by Bishal Bhat-- 5