CD Previous Question Papers According To Jntuh Syllabus
CD Previous Question Papers According To Jntuh Syllabus
1.a) Give the DFA for the language described by the regular expression: a|abb|a+b*a*.
us
b) Write a LEX program that recognizes the tokens of a C language and returns the token
found. [7+8]
ed
2.a) List the errors encountered in each phase of compilation and explain them.
b) Explain the role of lexical analyzer in compiler construction. [7+8]
3.a) What is left-recursion? Write the algorithm to eliminate left recursion from a grammar.
pa
Explain the same with an example.
b) Consider the following grammar:
R R‘|’R | R.R | R* | (R) | a | b (Note the first vertical bar is the or symbol)
i) Show that this grammar generates all regular expressions over the symbols a and b.
pe
ii) Construct a parse tree for the sentence a | b*c. [7+8]
4. Consider the following grammar G and construct CLR parse table by generating
ra
collection of item sets.
SCC
CcC|d. [15]
ug
5.a) What are the common three-address code implementations? Explain them with an
example.
-2
b) Construct the Syntax Directed Definition to convert infix notation into postfix notation.
[8+7]
02
6. Explain in detail about Syntax Directed Translation for declaration statements with an
illustrative example. [15]
2
7.a) Explain the issues to be considered while designing a good code generator.
b) What is peephole optimization? Explain with examples. [7+8]
8. Explain in detail the principles sources of optimization. Give proper examples for each.
[15]
---ooOoo---
Code No: 156AH R18
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester Examinations, August - 2022
COMPILER DESIGN
jn
(Computer Science and Engineering)
Time: 3 Hours Max.Marks:75
t
Answer any five questions
uh
All questions carry equal marks
---
2.a) Design the LEX program that recognizes the tokens of a C language and returns the
ed
token found.
b) Give the DFA and NFA to accept the strings containing a, b such that the string
contains even number of a’s and odd number of b’s. [7+8]
pa
3.a) Remove the left recursion for the following grammar and also find FIRSTS and
FOLLOWs.
E→E + T | T
pe
T→T * F | F
F → (E)/id
b) Write the steps/algorithm to construct the predictive parser table and explain with an
example. [7+8]
ra
4.a) Construct the Recursive Descent Parser with backtracking for the following grammar:
S→aSbS | bSaS | ℇ
ug
b) Compute LR(0) items for the following grammar and construct SLR parser table: [7+8]
S→L=R | R
L→ *R | id
-2
R→L
5.a) Construct the syntax directed definition to convert infix notation into postfix notation.
02
b) Describe different ways of implementing intermediate code generation of a three-
address statement. [8+7]
2
6.a) Explain how an L-attributed grammar is converted into a translation scheme.
b) Compare and contrast S-Attributed definitions with L-Attributed definitions. [8+7]
7. How is stack storage allocation strategy different from heap allocation strategy?
Describe them mentioning their merits and demerits. [15]
8. Explain the foundations and basic notations used in data-flow analysis for optimizations
with examples. [15]
---oo0oo---
R18
U
Code No: 156AH
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
SE
B. Tech III Year II Semester Examinations, August/September - 2021
COMPILER DESIGN
(Computer Science and Engineering)
Time: 3 Hours Max. Marks: 75
D
Answer any five questions
All questions carry equal marks
---
PA
1.a) State the reasons for separating Lexical analysis and Syntax analysis.
b) Discuss how Finite Automata is used to recognize tokens and perform lexical analysis
with example. [7+8]
PE
2.a) How to specify the Tokens? Differentiate Token, Lexeme and Pattern with suitable
examples.
b) Explain various Error Recovery strategies in Lexical analysis. [7+8]
R
3.a) What do you mean by Ambiguous Grammar? Check whether the following grammar is
Ambiguous or not
SA
S→aAB,
A→bC/cd,
C→cd,
B→c/d
U
b) Write a note on Yacc. [8+7]
G
4. Construct CLR parsing table for the following Grammar
S L=R
SR
/S
L*R
Lid
EP
RL (Write all necessary procedures). [15]
5.a) Give Syntax Directed Translation scheme for Simple Desk Circulator.
b) Convert the following arithmetic expression into Syntax Tree and Three Address Code
b*3(a+b). [7+8]
- 20
6.a) Differentiate Synthesized and Inherited Attributes with example.
b) Generate Intermediate code for the following code segment along with the Syntax
Directed Translation Scheme.
21
if (a > b)
x = a + b;
else
x = a - b;
Where ‘a’ and ‘x’ are of real and ‘b’ of int type data. [7+8]
U
7.a) What is Flow-Graph? Explain how the given program can be converted into Flow-
SE
Graph?
b) Construct DAG for the following basic block:
d:= b+c
e:= a+b
D
b:=b*c
a:=e-d [8+7]
4.a) What is left recursion? Describe the algorithm used for eliminating left recursion.
23
b) Eliminate left recursion in the following grammar:
E → E + T / T, T → T * F / F, F → (E) / id [5+5]
OR
5.a) Write an algorithm for computing LR(K) item sets.
b) Differentiate between Top down and Bottom up parsing techniques. [5+5]
6.a) Construct a Quadruple, Triple and Indirect triple for the statement
a + a * (b – c) + (b – c) * d
b) How are inherited attributes differ from synthesized attributes? [6+4]
OR
7. Give syntax directed translation scheme for simple desk calculator. [10]
8. Explain various storage allocation strategies with an example. [10]
OR
9.a) What is a basic block? How to construct a basic block?
JN
b) Explain peephole optimization with an illustrative example. [5+5]
4.a) What is left recursion? Describe the algorithm used for eliminating left recursion.
23
b) Eliminate left recursion in the following grammar:
E → E + T / T, T → T * F / F, F → (E) / id [5+5]
OR
5.a) Write an algorithm for computing LR(K) item sets.
b) Differentiate between Top down and Bottom up parsing techniques. [5+5]
6.a) Construct a Quadruple, Triple and Indirect triple for the statement
a + a * (b – c) + (b – c) * d
b) How are inherited attributes differ from synthesized attributes? [6+4]
OR
7. Give syntax directed translation scheme for simple desk calculator. [10]
8. Explain various storage allocation strategies with an example. [10]
OR
9.a) What is a basic block? How to construct a basic block?
JN
b) Explain peephole optimization with an illustrative example. [5+5]
1.a) Write down the steps in constructing DFA for the regular expression (a/b)*aab(a/b)*.
b) Explain with an example how lex program perform lexical analysis for the arithmetic
pe
operators and identifiers in C? [7+8]
2.a) Give the basic structure of a compiler and explain various components in brief.
rf
b) Describe the analysis-synthesis model of a compiler. [7+8]
3.a) What is left-factoring? Write the algorithm to eliminate left-factoring from a grammar.
eb
Explain the same with an example.
b) Consider the following grammar.
bexpr bexpr or bterm | bterm
/m
bterm bterm and bfactor | bfactor
bfactor not bfactor | ( bexpr) | true | false
i) Construct a parse tree for the sentence not (true or false)
ar
ii) Is this grammar ambiguous? Why? [7+8]
6. Explain about syntax directed translation of Boolean expressions with and without
back patching. [15]
jn
7.a) What is an activation record? Describe various components in an activation record
tu
considering a sample c program.
b) Write down the code generation algorithm and explain briefly. [8+7]
h
us
8. How to construct the basic block and compute DAG for the code fragment? Explain
with the following code fragment. [15]
procedure fun(x,y,z)
ed
begin
y=z+1;
z=z+x;
end fun
pa
begin main()
a=2;
b=3;
fun(A+B,A,B);
pe
print(A);
end main
rf
---ooOoo---
eb
/m
ar
-2
0 22
jn
tu
h
Code No: 156AH R18
us
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester Examinations, February/March - 2022
COMPILER DESIGN
ed
(Computer Science and Engineering)
Time: 3 Hours Max. Marks: 75
Answer any five questions
All questions carry equal marks
pa
---
1.a) Write down the steps in constructing DFA for the regular expression (a/b)*aab(a/b)*.
b) Explain with an example how lex program perform lexical analysis for the arithmetic
pe
operators and identifiers in C? [7+8]
2.a) Give the basic structure of a compiler and explain various components in brief.
rf
b) Describe the analysis-synthesis model of a compiler. [7+8]
3.a) What is left-factoring? Write the algorithm to eliminate left-factoring from a grammar.
eb
Explain the same with an example.
b) Consider the following grammar.
bexpr bexpr or bterm | bterm
/m
bterm bterm and bfactor | bfactor
bfactor not bfactor | ( bexpr) | true | false
i) Construct a parse tree for the sentence not (true or false)
ar
ii) Is this grammar ambiguous? Why? [7+8]
6. Explain about syntax directed translation of Boolean expressions with and without
back patching. [15]
jn
7.a) What is an activation record? Describe various components in an activation record
tu
considering a sample c program.
b) Write down the code generation algorithm and explain briefly. [8+7]
h
us
8. How to construct the basic block and compute DAG for the code fragment? Explain
with the following code fragment. [15]
procedure fun(x,y,z)
ed
begin
y=z+1;
z=z+x;
end fun
pa
begin main()
a=2;
b=3;
fun(A+B,A,B);
pe
print(A);
end main
rf
---ooOoo---
eb
/m
ar
-2
0 22
jn
tu
h
Code No: 136AQ R16
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester (Special) Examinations, January/February - 2021
COMPILER DESIGN
(Common to CSE, IT)
us
Time: 2 Hours Max. Marks: 75
Answer any five questions
All questions carry equal marks
---
ed
1. Give the structure of a compiler and explain various phases of compilation. [15]
2. Compute Firsts and Follows and construct LL(1) parser table for the following
pa
grammar after eliminating ambiguity.
R → R + R, R → R * R, R → R / R, R → (R), R → id. [15]
pe
3.a) How are inherited attributes differ from synthesized attributes?
b) Construct the SDD to convert infix notation to postfix notation. [5+10]
4.a) What is a type checker? Give the specification of a simple type checker.
rj
b) Write the quadruples, triples and indirect triples for the expression: [7+8]
a * b – (c – d) + b * a – (c – d )
an
5. Explain various storage allocation strategies and also mention their merits and demerits.
[15]
-fe
6.a) What is a Basic Block? How to construct a Basic block?
b) Explain Peephole optimization with an illustrative example. [7+8]
b-
7. Explain the principal sources of code optimization with merits and demerits of each.
[15]
20
8. Explain the following:
a) Basic elements of Data-Flow Analysis.
b) Register Allocation. [8+7]
21
---ooOoo---
Code No: 136AQ
R16
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester Examinations, March/April - 2021
COMPILER DESIGN
U
(Common to CSE, IT)
Time: 3 hours Max. Marks: 75
Answer any five questions
SE
All questions carry equal marks
---
1. How to design and implement a lexical analyzer? Explain with an example. [15]
D2
2. Discuss the phases of a compiler indicating the inputs and outputs of each phase in
4P-
translating the statement “amount = principle + rate * 36.0”. [15]
3. Test whether the grammar is LL(1) or not and construct a predictive parsing table for
0A3P
it?
S→AaAb|BaBa|a|b
A→€
-E2
b→€ [15]
---ooOoo---
Code No: 136AQ
R16
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester Examinations, May - 2019
us
COMPILER DESIGN
(Common to CSE, IT)
Time: 3 hours Max. Marks: 75
ed
Note: This question paper contains two parts A and B.
Part A is compulsory which carries 25 marks. Answer all questions in Part A. Part B
consists of 5 Units. Answer any one full question from each unit. Each question carries
10 marks and may have a, b, c as sub questions.
pa
PART - A
(25 Marks)
pe
1.a) Define regular expression. [2]
b) Define linker and loader and explain briefly. [3]
c) Define ambiguous grammar. [2]
r1
d) Compare SLR, CLR and LACR. [3]
e) What is coercion? [2]
f) How to find evaluation order for SDD’s? [3]
9-
g) What are the limitations of static allocation? [2]
h) Write the fields and uses of symbol table. [3]
i) What is common sub-expression elimination? Explain. [2]
05
j) What are induction variables? What is induction variable elimination? [3]
PART - B
-2
(50 Marks)
4.a) What is left recursion? Describe the algorithm used for eliminating left recursion?
PM
b) Eliminate left recursion in the following: [5+5]
EE+T|T, TT*F|F, F(E)|id
OR
5.a) What is ambiguous grammar? Show that following grammar is ambiguous or not.
A→A+A|A−A|A*A|a
b) Verify whether the following grammar is LL(1) or not? [5+5]
EE+T|T
T T* F / F
F (F) |a|b.
6.a) What are three address codes? Explain different types of representations of three
address code.
us
b) Write three codes for x:=A[y, z] [5+5]
OR
7.a) What is type checker? Explain the specification of a simple type checker.
ed
b) Explain translation schema for array elements. [5+5]