Compiler
Compiler
B. Tech.
(SEM VI) CARRY OVER THEORY EXAMINATION 2017-18
Compiler Design
Time: 3 Hours Total Marks: 100
Note: 1. Attempt all Sections. If require any missing data; then choose suitably.
2. Any special paper specific instruction.
SECTION A
b). Construct the NFA for the regular expression a/abb/a*b+ by using Thompson’s construction
methodology.
c). Eliminate left recursion from the following grammar
SAB , ABS | b , BSA | a
d). Discuss conversion of NFA into a DFA . also give the algorithm used in this conversion.
e). Explain non recursive predictive parsing. Consider the following grammar and construct the
predictive parsing table
ETE’
E’+TE’|€
TFT’
T’*FT’|€
FF*|a|b
SECTION C
3. Attempt any one part of the following: 10 x 1 = 10
a). Give Operator –precedence parsing algorithm. Consider the following grammar and build up
operator precedence table. Also parse the input string (id+(id*id))
EE+T|T
TT*F|F
F(E)|id
b). For the grammar
SaAd |bBd |aBe |bAe Af , Bf
Construct LR(1) Parsing table .also draw the LALR table from the derived LR(1) parsing table.
BTECH
(SEM VI) THEORY EXAMINATION 2018-19
COMPILER DESIGN
Time: 3 Hours Total Marks: 70
Note: 1. Attempt all Sections. If require any missing data; then choose suitably.
SECTION A
A
f. What are the various types of intermediate code representation?
PT
g. Define peephole optimization.
U
G
.2
SECTION B
AR
62
2. Attempt any three of the following: 7 x 3 = 21
M
5.
a. Write the quadruples ,triple and indirect triple for the following expression:
KU
11
(x+y)*(y+z)+(x+y+z)
5.
Y
|4
b. What are the problems with top down parsing? Write the algorithm for FIRST
JA
and FOLLOW.
46
VI
c. Perform Shift Reduce Parsing for the given input strings using the grammar
8:
R
S->(L)|a
:3
D
L->L,S|S
13
i) (a,(a,a))
ii) (a,a)
9
01
d. What is global data flow analysis? How does it use in code optimization?
-2
ay
S-> cB | ccA
4-
A->cA | a
|1
B-> ccB | b
SECTION C
3. Attempt any one part of the following: 7x1=7
(a) Convert following NFA to equivalent DFA and hence minimize the number
of states in the DFA.
(b) Explain the various parameter passing mechanisms of a high level language.
a:=b*-c+b*-c
(b) Distinguish between static scope and dynamic scope. Briefly explain access to
non-local names in static scope.
A
PT
5. Attempt any one part of the following: 7x1=7
(a) U
Write short notes on the following with the help of example:
G
(i) Loop unrolling
.2
(ii) Loop Jamming
AR
62
(iii) Dominators
(iv) Viable Prefix
M
5.
KU
11
(b) Draw the format of Activation Record in stack allocation and explain each field
in it.
5.
Y
|4
JA
(a) Write down the translation procedure for control statement and switch
8:
R
statement
:3
D
13
(b) Define Syntax Directed Translation. Construct an annotated parse tree for the
expression (4 * 7 + 1) * 2, using the simple desk calculator grammar.
9
01
(a) Explain in detail the error recovery process in operator precedence parsing
ay
method.
M
(b) Explain what constitute a loop in flow graph and how will you do loop
4-
B.TECH.
THEORY EXAMINATION (SEM–VI) 2016-17
COMPILER DESIGN
SECTION – A
1. Attempt the following: 10 x 2 = 20
(a) State any two reasons as to why phases of compiler should be grouped.
(b) Write regular expression to describe a language consist of strings made of even
numbers a & b.
(c) Write a CF grammar to represent palindrome.
(d) Why are quadruples preferred over triples in an optimizing compiler?
(e) Give syntax directed translation for case statement.
(f) What is a syntax tree? Draw the syntax tree for the following statement: c b c b a − ∗ +
−∗=
(g) How to perform register assignment for outer loops?
(h) List out the criteria for code improving transformations.
(i) Represent the following in flow graph i=1;sum=0;while (i<=10){sum+=i;i++}
(j) What is the use of algebraic identities in optimization of basic blocks?
SECTION – B
2. Attempt any five of the following questions: 5 x 10 = 50
(a) Explain in detail the process of compilation. Illustrate the output of each phase of
compilation of the input “a=(b+c)*(b+c)*2”..
(b) Construct the minimized DFA for the regular expression (0+1)*(0+1) 10.
(c) What is an ambiguous grammar? Is the following grammar ambiguous? Prove
EE+|E(E)|id.The grammar should be moved to the next line ,centered.
(d) Draw NFA for the regular expression ab*/ab.
(e) How names can be looked up in the symbol table? Discuss.
(f) Write an algorithm to partition a sequence of three address statements into basic blocks.
(g) Discuss in detail the process of optimization of basic blocks. Give an example
(h) How to subdivide a run-time memory into code and data areas. Explain
SECTION – C
Attempt any two of the following questions: 2 x 15 = 30
3 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”.
4 How would you convert the following into intermediate code? Give a suitable example.
i) Assignment Statements. ii) Case Statements
5 Define a directed acyclic graph. Construct a DAG and write the sequence of
instructions for the expression a+a*(b-c)+(b-c)*d.
Printed Page: 1 of 2
Subject Code: KCS502
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0
BTECH
(SEM V) THEORY EXAMINATION 2023-24
COMPILER DESIGN
TIME: 3 HRS M.MARKS: 100
Note: 1. Attempt all Sections. If require any missing data; then choose suitably.
SECTION A
1. Attempt all questions in brief. 2 x 10 = 20
Q no. Question Marks CO
a. Define bootstrapping in the context of compilers. 2 1
b. Which phase of compiler is optional and why? 2 1
c. Explain the concept of shift-reduce parsing. 2 2
d. Differentiate Parse tree and Syntax tree with an example. 2 2
e. Define syntax-directed translation schemes. 2 3
f. What are the two types of attributes that are associated with a grammar 2 3
symbol?
g. Discuss how scope information is represented in a symbol table. 2 4
h. What is mean by Activation record? 2 4
i. Discuss two design issues in code generation. 2 5
90
1
j. Explain the concept of global data-flow analysis. 2 5
13
_2
2.
SECTION B
P1
24
2. Attempt any three of the following: 10x3=30
a. Describe the relationship between finite state machines and regular 10 1
4D
5.
expressions. Discuss how regular expressions are used in lexical analysis
.5
P2
|1
support optimization.
:2
program execution. Explain how it is used for storing local variables and
4
SECTION C
|2
1|Page
QP24DP1_290 | 24-01-2024 13:27:35 | 117.55.242.131
Printed Page: 2 of 2
Subject Code: KCS502
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0
BTECH
(SEM V) THEORY EXAMINATION 2023-24
COMPILER DESIGN
TIME: 3 HRS M.MARKS: 100
1
13
E→id
_2
2.
P1
arithmetic expressions.
24
4D
5.
6. Attempt any one part of the following: 10x1=10
.5
P2
a. Define Symbol table? Explain about the data structures used for symbol 10 4
17
table.
Q
1. x = a + b
2. y = x * c
4
02
3. z = y – d
Apply common sub expression elimination to optimize the basic block.
-2
basic block:
4-
1. x = a + b
|2
2. y = c - d
3. z = x * y
2|Page
QP24DP1_290 | 24-01-2024 13:27:35 | 117.55.242.131
Printed Pages:02 Sub Code: KIT-052
Paper Id: 231849 Roll No.
B. TECH.
(SEM V) THEORY EXAMINATION 2022-23
COMPILER DESIGN
Time: 3 Hours Total Marks: 100
Note: Attempt all Sections. If require any missing data; then choose suitably.
SECTION A
2
90
13
_2
2.
SECTION B
P1
24
2. Attempt any three of the following: 10 x 3= 30
5.
3D
.5
(a) Construct a DFA that accepts a language L over input alphabets ∑ = {a, b} such that
P2
(b) Define the following terms and give suitable example for it.
|1
i) Handle
ii) Handle pruning
3
:3
C→ cC | d
(d) Explain various data structures used in symbol table management.
3
(e) Define DAG. Explain DAG representation of basic block with example.
02
-2
SECTION C
01
(a) What is an activation record? Explain how they are used to access local and global
variables.
(b) Explain syntax directed translation scheme for Infix to Postfix conversation with
example.
(a) Generate three address code for the following code segment
While (a<b) do
If (c<d) then x= y+z
(b) Explain different error recovery techniques with suitable example.
2
7. Attempt any one part of the following:
90 10 x 1= 10
13
_2
2.
(a) What is intermediate code? Explain different types of intermediate
P1
24
coderepresentations. Also discuss importance of intermediate code.
(b) Explain in detail about the data-flow schemas on basic block and the transfer
5.
3D
.5
P2
17
Q
|1
3
:3
: 29
13
3
02
-2
01
8-
|1
B. TECH.
(SEM V) THEORY EXAMINATION 2022-23
COMPILER DESIGN
SECTION A
2
90
13
(j) What is induction variable?
_2
2.
P1
24
SECTION B
5.
3D
.5
2. Attempt any three of the following: 10 x 3 = 30
P2
(a) Write SDD to produce three-address code for Boolean expressions and 17
Q
|1
obtain the three-address code for the statement given below:
7
while a < b do
:2
if c < d then
29
x=y*z
:
else
13
x=y+z
(b) Discuss the stack allocation and heap allocation strategies of the runtime
3
02
(d) Construct the NFA and DFA for the following regular expression.
8-
(0+1)*(00+11)(0+1)*
|1
(e) Explain the lexical analysis and syntax analysis phases of the compiler
with a suitable example. Explain the reporting errors in these two phases
as well.
SECTION C
2
90
(a) What is an activation record? Draw diagram of general activation
13
record and explain the purpose of different fields of an activation
_2
2.
record.
P1
24
and scope by location.
5.
3D
.5
P2
|1
symbol table.
(b) Explain the following:
7
(a) Explain in the DAG representation of the basic block with example.
-2
(b) Write quadruple, triples and indirect triples for following expression :
01
a = b * – c + b * – c.
8-
|1
B.TECH.
(SEM V ) THEORY EXAMINATION 2021-22
COMPILER DESIGN
SECTION A
1. Attempt all questions in brief. 2 x 10 = 20
a. What is the difference between parse tree and abstract syntax tree?
b. Explain the problems associated with top-down Parser.
c. What are the various errors that may appear in compilation process?
d. What are the two types of attributes that are associated with a grammar symbol?
e. Define the terms Language Translator and compiler.
f. What is hashing? Explain.
g. What is do you mean by left factoring the grammars? Explain.
h. Define left recursion. Is the following grammar left recursive?
E → E+E | E*E| a| b
1
90
i. What is an ambiguous grammar? Give example.
13
j. List down the conflicts during shift-reduce parsing.
_2
2.
1P
24
SECTION B
2O
5.
2. Attempt any three of the following: 10 x 3 = 30
.5
P2
|1
B→ aB / b
b. What is an activation record? Explain how it is related with runtime storage organization?
59
c. Write the quadruple, triple, indirect triple for the following expression
0:
(x + y)*(y + z) + (x + y + z)
:0
T →T *F/F
n
Ja
F →F /a/b
2-
SECTION C
|1
1
90
13
t2:=a[t1]
_2
if t2<10 goto B2
2.
1P
24
6. Attempt any one part of the following: 10 x 1 = 10
2O
5.
a. Test whether the grammar is LL(1) or not, and construct parsing table for it.
.5
P2
S1AB / ε
17
A1AC/0C
Q
|1
B0S
C1
59
b. Distinguish between static scope and dynamic scope. Briefly explain access to non local
0:
a. What are the various issues in design of code generator & code loop optimization?
2
02
b. Generate the three address code for the following code fragment.
-2
while(a>b)
n
{
Ja
if(c<d)
2-
x=y+z;
|1
else
x=y-z;
}
B TECH
(SEM-V) THEORY EXAMINATION 2020-21
COMPILER DESIGN
Time: 3 Hours Total Marks: 100
Note: 1. Attempt all Sections. If require any missing data; then choose suitably.
SECTION A
P
f. Discuss about non-linear type intermediate code. 2 CO 3
0Q
1
g. Write short note on “Activation Record” 2 CO 4
13
29
2.
i. Discus about constant folding. 2 CO 5
0E
24
j. Discuss about designing issues of code generator. 2 CO 5
P2
SECTION B
5.
_Q
.5
2. Attempt any three of the following: 17 3 x 10 = 30
TU
a=b+c*70.
4 8
S→AA, A→aA|b
:1
directed definition.
02
SECTION C
5-
P
case 1: x=x+1
0Q
1
case 2: y=y+2
13
29
case 3: z=z+3
2.
default: c=c-1
0E
24
P2
5.
_Q
symbol table.
4
fact(n)
Fe
{
int f=1;
5-
f=f*i;
return f;
}
b. Define a DAG. Construct a DAG for the expression: 10 CO 5
p+p*(q-r)+(q-r)*s
2|Page
AKTU_QP20E290QP | 25-Feb-2021 09:18:48 | 117.55.242.131