Course: B.Tech (Semester V) Subject Code: KCS-502
Subject Name: Compiler Design Time: 3 Hours
Total Marks: 100 Note: Attempt all sections.
Section A – Short Answer Questions (2 × 10 = 20 Marks)
Answer all in brief:
How will you group the phases of a compiler? Mention the role of semantic analysis.
What are the various parts in a LEX program? Differentiate Parse tree and Syntax tree with an example.
List the properties of intermediate representation. Differentiate between LR and LL parsers.
What is phrase level error recovery? Discuss the capabilities of Context-Free Grammar (CFG).
Define loop jamming. What is an induction variable?
Section B – Descriptive Questions (10 × 3 = 30 Marks)
Attempt any three:
Write an SDD (Syntax Directed Definition) to produce three-address code for Boolean expressions and generate the code for:
Discuss stack allocation and heap allocation strategies of the runtime environment with examples.
Explain attributed grammars and the translation scheme for converting an infix expression to postfix.
Construct NFA and DFA for the regular expression:
(0 + 1)*(00 + 11)(0 + 1)*
Explain lexical analysis and syntax analysis phases of the compiler with examples and discuss error reporting in both phases.
Section C – Long Answer Questions (10 × 5 = 50 Marks)
Question 3
(a) Construct the CLR parse table for:
A → BB
B → cB
B → d or (b) Construct the SLR parsing table for:
S → 0S0
S → 1S1
S → 10
Question 4
(a) Explain back patching and generate three-address code for:
a < b or c > d and e < f
or (b) Define Top-Down Parsing. Discuss its problems with suitable examples.
Question 5
(a) Define an Activation Record. Draw and explain the fields in a general activation record.
or
(b) Explain scope representation — scope by number and scope by location.
Question 6
(a) Define Symbol Table and discuss data structures used for symbol table implementation.
or
(b) Explain the following optimization techniques:
Copy Propagation Dead-Code Elimination
Code Motion Reduction in Strength
Question 7
(a) Explain the DAG (Directed Acyclic Graph) representation of a basic block with an example.
or
(b) Write Quadruples, Triples, and Indirect Triples for the expression:
if c < d then x = y * z else x = y + z```