0% found this document useful (0 votes)
27 views16 pages

CD Previous Question Papers According To Jntuh Syllabus

The document outlines examination questions for Compiler Design for B. Tech students at Jawaharlal Nehru Technological University Hyderabad. It includes topics such as DFA construction, lexical analysis, grammar analysis, error recovery strategies, and various code generation techniques. Each question carries equal marks, and students are required to answer five questions from the provided options.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views16 pages

CD Previous Question Papers According To Jntuh Syllabus

The document outlines examination questions for Compiler Design for B. Tech students at Jawaharlal Nehru Technological University Hyderabad. It includes topics such as DFA construction, lexical analysis, grammar analysis, error recovery strategies, and various code generation techniques. Each question carries equal marks, and students are required to answer five questions from the provided options.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Code No: 136AQ R16

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD


B. Tech III Year II Semester Examinations, August - 2022
jn
COMPILER DESIGN
(Common to CSE, IT)
t
Time: 3 Hours Max. Marks: 75
uh
Answer any five questions
All questions carry equal marks
---

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.
SCC
CcC|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
---

1.a) What are the advantages of a compiler over an interpreter?


us
b) Draw the structure of a compiler and describe various phases in the compilation process
mention the output of the following statement: id1=id2+id3*50 at each phase. [5+10]

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
SR
/S
L*R
Lid
EP
RL (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]

“Copy propagation Leads to Dead code” - Justify the statement.


PA
8.a)
b) Explain Global Data Flow analysis with necessary equations. [7+8]
PE
---ooOoo---
R
SA
U
G
/S
EP
- 20
21
Code No: 136AQ R16
R18
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester Examinations, February - 2023
COMPILER DESIGN
JN
(Common to CSE, IT)
Time: 3 Hours Max. Marks: 75

Note: i) Question paper consists of Part A, Part B.


TU
ii) Part A is compulsory, which carries 25 marks. In Part A, Answer all questions.
iii) In Part B, Answer any one question from each unit. Each question carries 10 marks
and may have a, b as sub questions.
H
PART – A
(25 Marks)
U
1.a) Define linker and loader. [2]
b) Write a short note on regular expression. [3]
se
c) Explain context free grammar. [2]
d) Compute FIRSTs and FOLLOWs for the following grammar
R→R+R, R→R*R, R→R/R, R→(R), R→id [3]
d
e) What are the evaluation orders for syntax directed definitions? [2]
f) Explain the variants of syntax trees. [3]
g) What is trace based collection? [2]
pa
h) Explain the addresses in the target code. [3]
i) Define strength reduction. [2]
j) Discuss about common sub expression elimination. [3]
pe
PART – B
(50 Marks)
rs
2. Define compiler. Explain various phases of compiler with neat sketch. [10]
OR
3.a) Explain various error recovery strategies in lexical analysis.
20
b) Construct a Finite automata and scanning algorithm for recognizing identifiers,
numerical constants in ‘C’ language. [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]

10. Explain the following with an example


a) Constant Propagation
TU
b) Partial Redundancy Elimination. [5+5]
OR
11.a) Explain loop optimization techniques with example.
b) Explain various notations used in data flow analysis. [5+5]
H
U
---ooOoo---
se
d
pa
pe
rs
20
23
Code No: 156AH R18
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester Examinations, February - 2023
COMPILER DESIGN
JN
(Computer Science and Engineering)
Time: 3 Hours Max. Marks: 75

Note: i) Question paper consists of Part A, Part B.


TU
ii) Part A is compulsory, which carries 25 marks. In Part A, Answer all questions.
iii) In Part B, Answer any one question from each unit. Each question carries 10 marks
and may have a, b as sub questions.
H
PART – A
(25 Marks)
U
1.a) Define linker and loader. [2]
b) Write a short note on regular expression. [3]
se
c) Explain context free grammar. [2]
d) Compute FIRSTs and FOLLOWs for the following grammar
R→R+R, R→R*R, R→R/R, R→(R), R→id [3]
d
e) What are the evaluation orders for syntax directed definitions? [2]
f) Explain the variants of syntax trees. [3]
g) What is trace based collection? [2]
pa
h) Explain the addresses in the target code. [3]
i) Define strength reduction. [2]
j) Discuss about common sub expression elimination. [3]
pe
PART – B
(50 Marks)
rs
2. Define compiler. Explain various phases of compiler with neat sketch. [10]
OR
3.a) Explain various error recovery strategies in lexical analysis.
20
b) Construct a Finite automata and scanning algorithm for recognizing identifiers,
numerical constants in ‘C’ language. [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]

10. Explain the following with an example


a) Constant Propagation
TU
b) Partial Redundancy Elimination. [5+5]
OR
11.a) Explain loop optimization techniques with example.
b) Explain various notations used in data flow analysis. [5+5]
H
U
---ooOoo---
se
d
pa
pe
rs
20
23
Code No: 136AQ R16
us
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
B. Tech III Year II Semester Examinations, February/March - 2022
COMPILER DESIGN
ed
(Common to CSE, IT)
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]

4. Show that the following grammar is LALR(1) [15]


-2
SAa | bAc | dc | bda
Ad
0
5.a) What are the three forms of intermediate code representations? Explain them.
22
b) Give the syntax-directed definition of a simple desk calculator and construct an
annotated parse tree for the input expression (4*7+1)*2. [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]

4. Show that the following grammar is LALR(1) [15]


-2
SAa | bAc | dc | bda
Ad
0
5.a) What are the three forms of intermediate code representations? Explain them.
22
b) Give the syntax-directed definition of a simple desk calculator and construct an
annotated parse tree for the input expression (4*7+1)*2. [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]

4. Construct the LR(0) items for the following grammar:


0R2
S→ L=R|R
L→*R|id
S1
R→L
Check whether the above grammar is LR(0) grammar or not. [15]
JA/
5. State and explain the syntax directed translation scheme for the desk calculator give the
parse tree and the translation for the string (7 + 4) * 249/3 + 26. [15]
AM-
6. What is intermediate code representation? Explain quadruples, triples and indirect
triples with an example. [15]
20
7. Explain various storage allocation strategies with an example. [15]

8.a) Construct a DAG for the expression: a+a*(b-c)+(b-c)*d.


2
b) Explain various notations used in data flow analysis. [7+8]
1

---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)

2.a) Explain the procedure to convert regular expression to Finite automata.


0
b) Explain various phases in the construction of compiler with a neat sketch. [5+5]
OR
19
3.a) What is the functionality of preprocessing and input buffering?
b) Explain compiler construction tools. [5+5]

4.a) What is left recursion? Describe the algorithm used for eliminating left recursion?
PM
b) Eliminate left recursion in the following: [5+5]
EE+T|T, TT*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]
EE+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]

8.a) Explain about Heap management.


b) Define reference counting. What is the role of reference counting in garbage collection?
[5+5]
pa
OR
9.a) Give the detailed description on DAG.
b) Explain different methods for register allocation and assignment. [5+5]
pe
10.a) Explain redundancy elimination techniques.
b) Write the principal sources of optimization. [5+5]
OR
r1
11.a) Explain loop optimization technique with example.
b) Explain constant propagation with example. [5+5]
9-
---ooOoo---
05
-2
0 19
PM

You might also like