CD

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Set No: 1

Code No: V3223/R07

EW

.C
O

III B.Tech II Semester Regular & Supplementary Examinations, April/May - 2012


COMPILER DESIGN
(Computer Science and Engineering)
Time: 3 Hours
Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
*****
1. a) What are various phases of compiler .Explain each phase in detail. Write down the
output of each phase for expression a:= b+c *50
b) Define lexeme, token and pattern. Identify the lexemes that make up the tokens in the
following program segment. Indicate corresponding token and pattern.
void swap(int i, int j)
{
int t;
t=i;
i=j;
j=t;
}
[8+8]

O
R
LD

2. a) Construct the predictive parser for the following grammar


S->a|1^|(T)
T->T,S|S
Write down the necessary algorithms and define FIRST and FOLLOW.
Show the behavior of the parser in the sentences:
(i) (a,(a,a))
(ii) (((a,a),1^,(a),a).
b) Eliminate ambiguity if any from the following grammar for boolean expressions.
bexpr bexpr or bterm|bterm
bterm  bterm and bfactor|bfactor
bfactor  nst factor|(bexpr)|true|false.
Where or, and, not (, ), true, false are terminals in the grammar.
[8+8]

JN

TU

3. a) Obtain the stack implementation of shift reduce parser for the input string id1+ id2* id3
for the following grammar
E E+E
EE*E
E(E)
E id
b) Discuss about shift reduce parsing conflicts that arise during parsing.
[8+8]
4. a) Write a translation scheme to generate three address code for assignment sentences
with array and pointer references.
b) Consider the following declarations
type link = cell;
var next : link;
last : link;
p : cell;
q,r : cell;
1 of 2

Which the following expressions are structurally equivalent?


Which are name equivalent? Justify your answer.
link
pointer(cell)
pointer(link)
pointer(record((info X integer) X (next X pointer(cell)))

Set No: 1

Code No: V3223/R07

[8+8]

[8+8]

6. a) Explain any two machine dependent code optimization techniques.


b) Describe about scope of optimization in detail.

[8+8]

.C
O

5. a) Describe in detail about storage allocation for arrays, strings and records.
b) Discuss about implementation of simple stack allocation scheme.

EW

7. a) Determine the pre-dominant block of block B2 in the program flow graph from the
following code
../* Block B0*/
o to 100 /* Block B1*/
100 go to 10 /* Block B2*/
b) Describe in detail about next use information about names in basic blocks.
[8+8]

O
R
LD

8. a) Discuss in detail about the issues in the design of a code generator.


b) Explain in detail about machine dependent code optimization.

JN

TU

*****

2 of 2

[8+8]

Set No: 2

.C
O

Code No: V3223/R07


III B.Tech II Semester Regular & Supplementary Examinations, April/May - 2012
COMPILER DESIGN
(Computer Science and Engineering)
Time: 3 Hours
Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
*****
1. a) Explain how lex program will perform the lexical analysis for the following patterns in
C: identifiers, comments, numerical constants and arithmetic operators
b) Draw a block diagram of phases of a compiler and indicate the main functions of each
phase.
[8+8]

O
R
LD

EW

2. a) Consider the following grammar


E TE
E +TE|
T FT
T*FT|
F(E)|id
Consider the predictive parsing table and show the stack implementation for the input
string id+id * id
b) Find the predictive parser for the following grammar and parse the sentence (a+b) *
E E+T|T
T T*F|F
F (E)| id
[8+8]

3. a) Give the LALR parsing table for the below grammar


S L=R
SR
L *R
Lid
R L
b) What is Shift-Reduce and Reduce-Reduce conflict? How these can be resolved? With
examples explain in which condition S-R and R-R conflict can occur in SLR, canonical
LR and LALR parsers. (Make use of LR(0), LR(1))
[8+8]

JN

TU

4. a) Give a syntax directed definition to translate infix expression into infix expression
without redundant parentheses for e.g. since + and * associate to the left ((a*(b+c))*(d))
can be rewritten as a* (b+c) *d
b) Translate executable sentences of the following C program.
main()
{
int i = 1;
int a[10];
while (i <= 10)
{
a[i] = 0;
i = i + 1;
}
}
into
1 of 2

Set No: 2

Code No: V3223/R07

i) Syntax tree
ii) Postfix notation
iii) Three-address code.

[8+8]

.C
O

5. a) Describe in detail about symbol table format and organization for block structure
languages.
b) Discuss in detail about the issues of source language in run time environment.
[8+8]

6. a) What is a basic block? Write an algorithm for partitioning a sequence of three address
statements into basic blocks.
b) Explain about local optimization in detail.
[8+8]

EW

7. a) Explain in detail about global optimization.


b) Determine the definition points d; affecting the expression C = C+A
In the following code
..
A=Z; /* statement S0*/
A=B; /* statement S1*/
C=D; /* statement S2*/
C=C+A;

[8+8]

O
R
LD

8. a) Augment the code generation algorithm to incorporate the following features.


i) The parenthesis in an expression
ii) Non commutative operators like - and / etc
b) What is machine dependent code optimization? On what factors it depends? Describe
about machine dependent code optimization techniques.
[8+8]

JN

TU

*****

2 of 2

Set No: 3

Code No: V3223/R07

EW

.C
O

III B.Tech II Semester Regular & Supplementary Examinations, April/May - 2012


COMPILER DESIGN
(Computer Science and Engineering)
Time: 3 Hours
Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
*****
1. a) Construct an NFA for the regular expression r=(a|b)*abb and convert it into
equivalent DFA.
b) Consider the following fragment of C code
float i,j;
i=i*70+j+2;
Write output at all phases of compiler.
[8+8]

O
R
LD

2. a) Construct recursive descent parser for the following grammar of regular


expressions
E E+T|T
TTF|F
F F*|a|b
b) Find the FIRST and FOLLOW sets of each of the following non-terminals for the
following grammar
S aAB|bA|
A aAb|
B bB|c
[8+8]

3. a) Construct LALR parser for the below grammar


A  A
A  (A)
Aa
b) How YACC resolves parsing action conflicts? What is the new production added to
the YACC on error recovery.
[8+8]

JN

TU

4. a) For the input expression (4*7+1)*2 construct an annotated parse tree according to
syntax directed definition of desk calculator.
b) What are L-attributed grammars? Explain the steps involved in converting an Lattributed grammar into translator scheme.
[8+8]
5. a) Define symbol table? Explain the need for symbol table organization and the data
structures used for implementing a symbol table.
b) Explain about the block structures and non block structure storage allocation in
detail.
[8+8]

6. a) Explain in detail about loop optimization.


b) Explain in detail about constant folding with an example.

1 of 2

[8+8]

Set No: 3

Code No: V3223/R07

.Explain in detail where


[8+8]

JN

TU

O
R
LD

EW

.C
O

8. a) Explain in detail about register allocation and assignment of generic code


generation algorithms.
b) Show various steps in the code generation algorithm of the expression
(a + b) / (c + d)
Assuming two machine registers to be available.
*****

2 of 2

7. a) In the source code


X= a*a + 2*a*b + b*b;
Y=a*a-2*a*b + b*b;
Contains how many number of common sub expressions
they are located.
b) Discuss in detail about live variable analysis.

[8+8]

Set No: 4

Code No: V3223/R07

.C
O

III B.Tech II Semester Regular & Supplementary Examinations, April/May - 2012


COMPILER DESIGN
(Computer Science and Engineering)
Time: 3 Hours
Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
*****
1. a) Construct minimum state DFAs for the following regular expressions.
(a+b)* a (a+b)
(a+b)* a (a+b) (a+b)
b) Give general format for LEX program.
[8+8]
2. a) Consider the grammar

O
R
LD

EW

E E+T|T
T T*F|F
F (E)| id
Trace the grammar by Brute force method for each of the following strings
i) a+a
ii) a+a*a
iii) (a+a)
b) Check whether the following grammar is a LL(1) grammar
S->iEtS|iEtSeS|a
E->b
3. a) Construct the LALR parsing table for the following grammar
EE+T|T
TTF|F
FF*|a|b
b) Construct SLR parsing table for
S abS|AAab|b
AbaAb|b

[8+8]

[8+8]

JN

TU

4. a) Give the translate scheme to convert an expression grammar into three address
code.
b) Generate intermediate code generation for the following code along with the
required translation scheme
int a,b;
float c;
a=10;
switch(a)
{ case 10:c=1;
case 20:c=2;
}
[8+8]

5. a) Discuss in detail about runtime stack and heap storage allocation.


b) Explain about tree structure representation of scope information .

1 of 2

[8+8]

Set No: 4

Code No: V3223/R07

6. a) What are the applications of DAG. Explain how the following expression can be
converted in a DAG for a+b*(a+b)+c+d
b) Describe in detail about considerations for optimization.
[8+8]

.C
O

8. a)Represent DAG for register allocation in detail.


b) Describe different object code forms and illustrate this with an example.

JN

TU

O
R
LD

EW

*****

2 of 2

7. a) Discuss in detail about data flow analysis.


b) What is a flow graph? How to construct a DAG? Discuss the steps for DAG
construction?
[8+8]

[8+8]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy