Compiler Design July 2023
Compiler Design July 2023
Compiler Design July 2023
1 of 2
|''|'||||''|'''|||'|
Code No: R2032052 R20 SET -1
{ int sum, n, i;
sum=0;
for i:=1 to n do
sum:=sum+i;
write(sum);
}
UNIT-V
9. a) What is an induction variable, invariant variable, deadcode? Explain with an [7M]
example.
b) Discuss Global Register Allocation in code generation. [7M]
(OR)
10. a) Give an example to show how DAG is used for register allocation. [7M]
b) Generate code for the following C statements: [7M]
i) x=f(a)+f(a) ii) y=x/5;
2 of 2
|''|'||||''|'''|||'|
Code No: R203147C
R2031011
R2031351
R203135A
R203147A
R203105O
P2031051
R2032052 R20 SET
SET
RA--22
III B. Tech II Semester Regular Examinations, July -2023
COMPILER DESIGN
(Computer Science and Engineering)
Time: 3 hours Max. Marks: 70
1 of 2
|''|'||||''|'''|||'|
Code No: R2032052 R20 SET -2
8. a) Explain how data flow equations are set up and solved for improving code. [7M]
b) Discuss basic blocks and flow graphs with an example. [7M]
UNIT-V
9. a) Generate code for the following C program using any code generation [7M]
algorithm.
main()
{
int I;
int a[10];
while(i<=10)
a[i]=0;
}
b) Explain the main issues in code generation. How to handle them? Discuss. [7M]
(OR)
10. a) Discuss about register allocation and assignment in target code generation. [7M]
b) Discuss how induction variables can be detected and eliminated from the given [7M]
intermediate code
B2: i:= i+1
t1:=4*j
t2:=a[t1]
if t2<10 goto B2
2 of 2
|''|'||||''|'''|||'|
Code No: R2031011
R2031351
R203135A
R203147A
R203147C
R203105O
P2031051
R2032052 R20 SET
SET
RA--32
III B. Tech II Semester Regular Examinations, July -2023
COMPILER DESIGN
(Computer Science and Engineering)
Time: 3 hours Max. Marks: 70
Answer any FIVE Questions ONE Question from Each unit
All Questions Carry Equal Marks
*****
UNIT-I
1. a) Explain various building blocks used to design a language translator. [7M]
b) Differentiate between [7M]
i) Phase and a pass ii) single-pass and multi-pass compiler.
(OR)
2. a) What is LEX? Discuss the usage of LEX in Lexical Analyzer generation. [7M]
b) Construct a Finite Automata and Scanning algorithm for recognizing [7M]
identifiers, numerical constants in C language.
UNIT-II
3. a) Define Context Free Grammar. Explain how it is suitable for parsing? Explain [7M]
the recursive descent parser with example.
b) Design a non-recursive predictive parser for the following grammar: [7M]
S → AaAb | BbBb
A→e
B→e where a, b, e are terminals.
(OR)
4. a) Given the following grammar: E -> E + E | E - E | E * E | E / E | - E | int Show [7M]
two different left-most derivations with the help of parse trees for the string
int + int * int / int. What does this tell you?
b) Explain left recursion and left factoring with examples. [7M]
UNIT-III
5. a) Define LR(k) parser. Explain the model of LR parser and various functions [7M]
used in it for parser construction.
b) How to handle ambiguity through LR parsers? Discuss about the Dangling – [7M]
Else ambiguity.
(OR)
6. a) Give syntax directed translation scheme for simple desk circulator. [7M]
b) Show that the following grammar: [7M]
S → Aa|bAc|Bc|bBa
A→d
B→d
Is LR(1) but not LALR(1).
UNIT-IV
7. a) Give the general structure of an activation record? Explain the purpose of [7M]
each component involved in it.
b) Explain various machine independent code optimization techniques. [7M]
(OR)
1 of 2
|''|'||||''|'''|||'|
R20 SET -3
Code No: R2032052
8. a) Write a short note on peephole optimization and various operations used in it. [7M]
b) Describe Loop unrolling? Describe its advantage with your own examples. [7M]
UNIT-V
9. Explain the code generation algorithm in detail with an example. [14M]
(OR)
10. a) Discuss basic blocks and flow graphs with an example [7M]
b) Generate code for the following: [7M]
i) x=f(a)+f(a)+f(a) ii) x=f(f(a)) iii) x=++f(a) iv) x=f(a)/g(b,c)
2 of 2
|''|'||||''|'''|||'|
Code No: R2032052
R2031011
R2031351
R203135A
R203147A
R203147C
R203105O
P2031051 R20 SET
SET
RA--42
UNIT-IV
7. a) Explain static and stack storage allocations? [7M]
b) Translate the arithmetic expression a[i]=b*c-b*d into a syntax tree, quadruples [7M]
and triples.
(OR)
1 of 2
|''|'||||''|'''|||'|
Code No: R2032052 SET -4
R20
8. a) Write pseudocode for finding sum of ‘n’ numbers. And identify basic blocks [7M]
then construct the flow graph for it. Explain the rules used for this.
b) Explain the following peephole optimization techniques; [7M]
i) Elimination of Redundant Code
ii) Elimination of Unreachable Code
UNIT-V
9. a) Explain the main issues in code generation. [7M]
b) Explain the following terms: [7M]
i) Register Descriptor ii) Address Descriptor iii) Instruction Costs
(OR)
10. a) Give an example to show how DAG is used for register allocation. [7M]
b) Generate code for the following C program using any code generation [7M]
algorithm.
main()
{
int I;
int a[10];
while(i<=10)
a[i]=0;
}
2 of 2
|''|'||||''|'''|||'|