You are on page 1of 39

PANIMALAR INSTITUTE OF TECHNOLOGY

DEPARTMENT OF CSE

CS6660 –COMPILER DESIGN

ANNA UNIVERSITY QUESTION PAPERS

MAY/JUNE 2007
NOV/DEC 2007
MAY/JUNE 2008
NOV/DEC 2008
MAY/JUNE 2009
NOV/DEC 2010
APR/MAY 2011
NOV/DEC 2011
MAY/JUNE 2012
NOV/DEC 2012
MAY/JUNE 2013
NOV/DEC 2013
MAY/JUNE 2014
NOV/DEC 2014
MAY/JUNE 2015
NOV/DEC 2015
MAY/JUNE 2016
NOV/DEC 2016
B.E./B. Tech. DEGREE EXAMINATION, MAY/JUNE 2007
Sixth Semester
(Regulation 2004)
Computer Science and Engineering
CS-2352-PRINCIPLES OF COMPILER DESIGN
(Common to B.E (Part-Time) Fifth Semester Regulation 2005)

Time: Three hours Maximum:100 marks

Answer ALL questions

PART A-(10x2=20 marks)

1. Define a preprocessor.
2. What are the issues in Lexical Analysis?
3. Eliminate the left recursion from the following grammar
A Ac/Aad/bd/c.
4. What are the disadvantages of operator precedence parsing?
5. Write the properties of intermediate language.
6. What is back patching?
7. What are the applications of DAG?
8. Give the primary structure preserving transformations on Basic Blocks.
9. What do you mean by code motion?
10. Draw the diagram of the general activation record and give the purpose of any
two fields.
PART B-(5x16=80 marks)

11. (a) (i) Write about the phases of compiler and by assuming an input and
show the output of various phases. (10)
(ii) Explain briefly about compiler construction tools. (6)
Or

(b) (i) Construct the NPA from the (a/b)*a(a/b) using thompson‟s construction
algorithm. (10)
(ii) Explain about Input buffering technique. (6)

12. (a) (i) Construct predictive parsing table for the grammar (10)
S (L)/a
L L,S/S.
(ii) What are the different strategies that a parser can employ to recover
from syntax errors? (6)
Or
(b) (i) Construct the CLR parsing table from (10)

2
S AA
A Aa/b.
(ii) Write Operator precedence parsing algorithm. (6)

13. (a) (i) Write about implementation of three addressing statements (8)
(ii) Give the syntax-directed definition for flow of control
statements. (8)
Or
(b) (i) How Back patching can be used to generate code for Boolean expressions
and flow of control statements. (10)
(ii) Write short notes on procedure calls. (6)

14. (a) (i) Write in Detail about the issues in the design of a code generator. (10)
(ii) What are steps needed to compute the next use information? (6)
Or
(b) (i) Discuss briefly about DAG representation of basic blocks. (10)
(ii) Explain the characteristics if peephole optimization. (6)

15. (a) (i) Describe the principal sources of optimization. (8)


(ii) Write about Data flow analysis of structural programs. (8)
Or
(b) (i) What are the different storage allocation strategies? Explain. (10)
(ii) Write short notes on parameter parsing. (6)

3
B.E./B. Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2007
Sixth Semester
(Regulation 2004)
Computer Science and Engineering

CS-2352-PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100marks

Answer ALL questions

PART A-(10x2=20 marks)

1. What are the functions of preprocessor?


2. Define a symbol table.
3. What is an ambiguous grammar?
4. What is a predictive parser?
5. What are the notations used to represent an intermediate language?
6. Give the ways of representing three address statements.
7. What are basic blocks and flow graphs?
8. What are the limitations of static allocation?
9. Define Activation tree.
10. What is inline expansion?

PART B-(5x16=80 marks)

11. (a) (i) Explain in detail about the role of lexical analyzer with the possible error
recovery actions. (6)
(ii) What is a compiler? Explain the various phases of compiler in detail, with
a neat sketch. (10)
Or
(b) (i) Give the minimized DFA for the following expression (10)
(a/b)*abb
(ii) Draw the transition diagram for the unsigned numbers. (6)

12. (a) (i) Explain the role of parser in detail. (4)


(ii) Construct predictive parsing table for the grammar (12)
E E+T|T , T T*F|F, F (E)|id.
Or
(b) (i) Give the LALR parsing table for the grammar. (12)
S L=R|R
L *R|id
R L
(ii)What are the reasons for using LR parser technique? (4)

13. (a) (i) Explain about the different type of three address statements. (8)

4
(ii) What are the methods of translating Boolean expression? (8)
Or
(b) (i) Write short notes on back patching. (8)
(ii) Explain procedure calls with an example. (8)

14. (a) (i) Construct the DAG for the following basic blocks: (6)
d:=b*c
e:=a+b
b:=b*c
a:=e-d.
(ii) Explain in detail about primary structure-preserving transformations on
basic blocks. (10)

Or
(b) (i) Describe in detail about a simple code generator with the appropriate
algorithm. (8)
(ii) Explain in detail about run-time storage management. (8)

15. (a) (i) Explain in detail about principal sources of optimization. (10)
(ii) Describe in detail about optimization of basic blocks with example. (6)
Or
(b) (i) describe n detail about storage organization. (10)
(ii) explain in detail the various methods of passing parameters (6)

5
B.E./B. Tech. DEGREE EXAMINATION, MAY/JUNE 2008
Sixth Semester
(Regulation 2004)
Computer Science and Engineering

CS-2352-PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Answer ALL questions

PART A-(10x2=20 marks)

1. Differentiate compiler and interpreter.


2. Write short notes on buffer pair.
3. Construct a parse tree of (a+b)c for the grammar E->E+E|E*E|(E)|id.
4. Eliminate immediate left recursion for the following grammar
E->E+T|T,T->T* F|F,F->(E)|id
5. Write short notes on global data flow analysis
6. Define back patching with an example
7. Give syntax directed translation for the following statement Call p1(int a,int b)
8. How can you find the leaders in basic block?
9. Define Code motion
10. Define basic block and flow graph

PART B-(5x16=80 marks)

11. (a) (i) Explain the phases of compiler, with the neat schematic (12)
(ii) Write short notes on compiler construction tools (4)

Or

(b) (i) Explain grouping of phases (8)


(ii) Explain specification of tokens (8)

12. (a) Find the SLR parsing table for the given grammar and the parse the sentence
(a+b)c E->E+E|E*E|(E)|id

Or

(b) Find the predictive parser for the grammar the parse the sentence
(a+b)c E->E+T|T,T->T*F,F->(E)|id

13. (a) Generate intermediate code for the following code segment along with the

6
required syntax directed translation scheme (8)

(i) if (a>b)
x=a+b
else
x=a–b

where a & x are of real and b of int type data

(ii) int a,b ;


float c;
a = 10;
switch (a)
{
case 10 : c = 1;
case 20 : c = 2;
}

Or

(b) (i) Generate intermediate code for the following code segment along with the
required syntax directed translation scheme (8)

i=1;s=0;
while (i<=10)
s = s + a [i] [i] [i]
i= i+1

(ii) Write short notes on back-patching (8)

14. (a) (i) Explain the various issues in the design of code generation (8)
(ii) Explain code generation phases with simple code generation algorithm(10)

Or

(b) (i) Generate DAG representation of the following code and list out the
application of DAG representation: (12)

i=1;s=0;
while (i <= 10)
s = s + a [i] [i]
i= i+1

(ii) Write short notes on next-use information with suitable example

7
15. (a) (i) Explain-principle sources of optimization (8)

(ii) Write short notes on : (8)


(1) Storage optimization
(2) Parameter passing

Or

(b) (i) Optimize the following code using various optimization technique:
(12)

i=1;s=0;
for (i = 1 ; i <= 3 ; i++)
for (j = 1 ; j <= 3 ; j++)
c[i][j] = c[i][j] + a[i][j] + b[i][j]

(ii) Write short notes on access to non-local names. (4)

B.E./B. Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2008


Sixth Semester
(Regulation 2004)
Computer Science and Engineering

CS-2352-PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100marks

Answer ALL questions

PART A-(10x2=20 marks)

1. What is language processing system?


2. What are the error recovery actions in a lexical analyzer?
3. Eliminate left recursion from the following grammar.
S->(L)|a; L->L,S|S
4. What is CLR?
5. Translate the expression a-(b+c) into three address code
6. List out the three functions that are used to manipulate list of labels in back
patching
7. What is constant folding?
8. What is DAG? What are the applications of DAG in compiler?
9. What is flow graph?

8
10. What are the criteria used for code-improving transformations?

PART B - (5*16=80)

11. (a) (i) Discuss about the input buffering scheme in lexical analyzer. (6)
(ii) Construct a NFA using Thompson‟s construction algorithm for the regular
expression (a|b)*abb(a|b)* and convert it into DFA. (10)

Or
(b) (i) Illustrate the compiler‟s internal representation of the changes in the source
program, as translation progresses by considering the translation of the
statement A:=B+C*50 (8)

(iii) Construct a DFA directly from the regular expression (a|b)*abb without
constructing NFA (8)

12. (a) (i) Give definition for FIRST(X) and FOLLOW(A) procedures used
in construction predictive parser (4)
(ii)What is an operator grammar? Draw the precedence graph for the following
table (12)

a ( ) , $

a > > >

( < < = <

) > > >

, < < > >

$ < <

Or

(b) (i) Write a note on error recovery in predictive parsing (4)


(ii) Write the LR parsing algorithm. Check whether the grammar is SLR(1) or not.
Justify the answer with reasons.
S->L=R|R;L->*R/ID;R->L (12)

13. (a) (i) What are the various data structures used for symbol table construction and
explain any one in detail (8)

(ii) Let A be a 10X10 array with low 1 = low =2 = 1. Let w = 4. Draw an


annotated parse tree for the assignment statement X:= A[y,z]. Give the sequence

9
of three address statement generated. (8)

Or
(b) How would you generate the intermediate code for the flow of control
statements? Explain with examples. (16)

14. (a) (i) Explain peephole optimization with example. (8)


(ii) Explain the DAG representation of the basic block with the example. (8)

Or

(b) (i) What is a three address code? What are its types? How it is implemented? (12)
(ii) Construct the DAG for the following basic block.
D:= B*C; E:= A+B; B:=B*C; A:=E-D (4)

15. (a) (i) Explain about Code Generation Algorithms (8)


(ii) Explain the various storage allocation strategies (8)

Or

(b) Why do we need code optimization? Explain the principle sources of


optimization. (16)

10
B.E/B. Tech DEGREE EXAMINATION, MAY/JUNE 2009.
Sixth Semester
(Regulation 2004)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Answer All questions

Part A - (10*2=20 marks)

1. What are the issues to be considered in the design of lexical analyzer?


2. Define concrete and abstract syntax with example.
3. Derive the string and construct a syntax tree for the input string ceaedbe using
the grammar S->SaA|A, A->AbB|B, B->cSd|e
4. List the factors to be considered for top-down parsing.
5. Why is it necessary to generate intermediate code instead of generating target
program itself?
6. Define back patching.
7. List the issues in code generation.
8. Write the steps for constructing leaders in basic blocks.
9. What are the issues in static allocation?
10. What is meant by copy-restore?

PART B - (5*16=80)

11. (a) (i) Explain the need for dividing the compilation process into various phases and
explain its functions.
(ii) Explain how abstract stack machine can be used as translators.

(or)
(b) What is syntax directed translation? How it is used for translation of expressions?
(16)
12. (a) Given the following grammar S->AS|b, A->SA|a Construct a SLR parsing table
for the string baab (16)
(or)

(b) Consider the grammar E->E+T,T->T*F,F->(E) | id. Using predictive parsing the
string id+id*id. (16)

13. (a) Explain in detail how three address codes are generated and implemented.

(or)

11
(b) Explain the role of declaration statements in intermediate code generation.

14. (a) Design a simple code generator and explain with example.

(or)
(b) Write short notes on:

Peep hole optimization

Issues in code generation

15. (a) Explain with an example how basic blocks are optimized.

(or)

(b) Explain the storage allocation strategies used in run time environments.

B.E./B.Tech. DEGREE EXAMINATION , NOVEMBER /DECEMBER 2010

12
EIGHTH SEMESTER
INFORMATION TECHNOLOGY
CS 2352 - PRICIPLES OF COMPILER DESIGN
(Common to sixth semester Computer Science and Engineering)
(Regulation 2004)
(Common to B.E.(Part time)fifth semester Computer Science and Engineering
Regulation 2005)

Time : Three hours Maximum: 100


marks

ANSWER ALL THE QUESTIONS.


PART A - (10 X 2 = 20 marks )

1. What is Sentinel? What is its purpose?


2. Define the term : lexeme, pattern.
3. Differentiate Top down approach from bottom up approach to parsing, with an
example.
4. Differentiate SLR parser from LALR parser.
5. What is the use of reusing the temporary names? Give example.
6. Define short circuit code.
7. What is peep-hole optimization?
8. How would you calculate the cost of an instruction?
9. What is dead (uselesss) code elimination?
10. How would you map names to values?

PART B --- ( 5 x 16 = 80 marks)

11. (a) (i) Write an algorithm to construct an NFA into regular expression.
(ii) Explain breifly the design of a Lexical Analyzer.

Or

(b) (i) What are the software tools used to manipulate source program.
(ii)What is the purpose of input buffering? Explain the process in detail.
(iii)Draw the transition diagram for relational operators.

12. (a)(i) Construct LR(0) parsing table for the given grammar.
(1) E -> E * B
(2) E -> E + B
(3) E -> B
(4) B -> 0
(5) B -> 1

(ii) Write an algorithm for the construction of LR(1) or CLR items for the

13
grammar G. (6)

Or
(b) Construct a Operator precedence table for the given grammar.
S -> L = R / R
L -> * R / id
R -> L
Also construct Operator Precedence function table from the parsing table.

13. (a) Explain the addressing array elements and translation scheme.

Or
(b) Generate the Three address code and syntax tree for the following expression
using Numerical Representation method.
(i) a or b and not c.
(ii) while ( i < 10)
{
X = 0;
I = i + 1;
}
(iii) a< b or c < d and e < f.

14. (a) Discuss the runtime storage of a code generator.

Or

(b) Explain in detail the basic and flow graphs with example.

15.(a) Discuss in detail the source language issues to be taken into account.

Or

(b) Explain the access to non local names.

14
B.E/B. Tech DEGREE EXAMINATION, APRIL/MAY 2011.
Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Part A - (10*2=20 marks)

1. What is an interpreter?
2. Define token and lexeme.
3. What is handle pruning?
4. What are the limitations of static allocation?
5. List out the benefits of using machine-independent intermediate forms.
6. What is a syntax tree? Draw the syntax tree for the following statement:
a : = b* a – a* c + b a - a* c.
7. List out the primary structure preserving transformations on basic block.
8. What is the purpose of next-use information?
9. Define dead-code elimination.
10. What is loop optimization?

PART B - (5*16=80)

11. (a) (i) Describe the various phases of complier and trace the program segment a : = b
+ c * a - 4 for all phases. (10)
(ii) Explain in detail about compiler construction tools. (6)

Or

(b) (i) Discuss the role of lexical analyzer in detail. (8)


(ii) Draw the transition diagram for relational operators and unsigned numbers in
Pascal. (8)

12. (a) (i) Explain the error recovery strategies in syntax analysis. (6)
(ii) Construct a SLR construction table for the following grammar.

E ->E + T
E ->T
T ->‟T * F
T ->F
F ->(E)
F ->id

15
Or

(b) (i) Distinguish between the source text of a procedure and its activation at run time.
(8)
(ii) Discuss the various storage allocation strategies in detail. (8)

13. (a) (i) Define three-address code. Describe the various methods of implementing
three-address statements with an example. (8)
(ii) Give the translation scheme for converting the assignments into three address
code. (8)
Or
(b) (i) Discuss the various methods for translating Boolean expression. (8)
(ii) Explain the process of generating the code for a Boolean expression in a single
pass using back patching. (8)

14. (a) (i) Write in detail about the issues in the design of a code generator.(10)
(ii) Define basic block. Write an algorithm to partition a sequence of three-address
statements into basic blocks. (6)

Or

(b) (i) How to generate a code for a basic block from its dag representation? Explain. (6)
(ii) Briefly explain about simple code generator. (10)

15. (a) (i) Write in detail about function-preserving transformations. (8)


(ii) Discuss briefly about Peephole Optimization. (8)

Or

(b) (i) Write an algorithm to construct the natural loop of a back edge. (6)
(ii) Explain in detail about code-improving transformations. (10)

16
B.E./B.Tech. DEGREE EXAMINATION , NOVEMBER /DECEMBER 2011

CS 1352 - PRICIPLES OF COMPILER DESIGN

Time : Three hours Maximum: 100 marks

ANSWER ALL THE QUESTIONS.


PART A - (10 X 2 = 20 marks )

1. What is the role of lexical analyzer?


2. Give the transition diagram for an identifier?
3. Define handle pruning?
4. Mention the two rules for type checking?
5. Construct the syntax tree for the following assignment statement: a:=b*-c+b*-c.
6. What are the types of three address statements?
7. Define basic blocks and flow graphs?
8. What is DAG?
9. List out the criteria for code improving transformation?
10. When does dancing reference occur?

PART – B (5 X 16 = 80 MARKS)

11. (a) (i) Describe the various phases of compiler and trace it with the program segment
(position :=initial+rate*60 )
(ii) State the compiler construction tools. Explain them.
Or
(b) (i) Explain briefly about input buffering in reading the source program for
finding the token.
(ii) Construct the minimized DFA for the regular expression (0+1)*(0+1)10.

12. (a) Construct a canonical parsing table for the grammar given below. Also explain \
the algorithm used.
E->E+T E->T T->T*F T->F F->(E) F->id.
Or
(b) What are the different storage allocation strategies? Explain.

13. (a) (i) Write down the translations scheme to generate code for assignment
statement. Use the scheme to generating three address code for the assignment

17
statement g:=a+b-c*d. (8)
(ii) Describe the various methods of implementing three-address statements. (8)
Or
(b) (i) How can Back patching be used to generate code for Boolean expression and
flow of control statements? (10)
(ii) Write a short note on procedure calls? (6)

14. (a) (i) Discuss the issues in the design of code generator. (10)
(ii) Explain the structure-preserving transformations for basic blocks. (6)
Or
(b) (i) Explain in detail about the simple code generator. (8)
(ii) Discuss briefly about the Peephole optimization. (8)

15. (a) Describe in detail the principal sources of optimization. (16)


Or
(b) (i) Explain in detail optimization of basic blocks with example. (8)
(ii) Write about Data flow analysis of structural programs. (8)

18
B.E/B. Tech DEGREE EXAMINATION, MAY/JUNE 2012
Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Part A - (10*2=20 marks)

1. Mention few cousins of the compiler.


2. What are the possible error recovery actions in Lexical Analyzer?
3. Define an ambiguous grammar.
4. What is dangling reference?
5. Why are quadruples preferred over triples in an optimizing compiler?
6. List out the motivations for back patching.
7. Define flow graph
8. How to perform register assignment for outer loops?
9. What is the use of algebraic identities in optimization of basic blocks?
10. List out two properties of reducible flow graph

PART – B (5 X 16 = 80 MARKS)

11. (a) (i) What are the various phases of compiler ? . Explain each phase in detail.
(ii) Briefly explain the compiler construction tools
Or
(b) (i) What are the issues in Lexical analysis?
(ii) Elaborate in detail the recognition of tokens.

12. (a) (i) Construct The predictive parser for the following grammar.
S->(L) / a L - > L,S / S
(ii) Describe the conflicts that may occur during shift reduce parsing

Or

19
(b) (i) Explain the detail about the specification of a simple type checker
(ii) How to subdivide a run-time memory into code and data areas.
Explain?

13. (a) (i) Describe the various types three-address statements.


(ii) How names can be looked up in the symbol table? Discuss.
Or
(b) (i) Discuss the different methods of translating Boolean Expressions in detail
(ii) Explain the following grammar for a simple procedure call statement S - > call
id(Elist)

14. (a) (i) Explain in detail about the various issues in the design of code generator. (10)
(ii) Write an algorithm to partition a sequence of three address statements into
basic blocks. (6)
Or
(b) (i) Explain the code generation algorithm in detail.
(ii) Construct the dag for the following basic block

d=b* c e=a+b
b=b*c a=e-d

15. (a) (i) Explain the principal sources of optimization in detail.


(ii) Discuss the various peephole optimization techniques in detail

Or
(b) (i) How to trace data-flow analysis of structured program ? Discuss.
(ii) Explain the common sub expression elimination, Copy propagation and
transformations for moving loop invariant computation in detail

20
B.E/B. Tech DEGREE EXAMINATION, NOV/DEC 2012
Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Answer ALL questions


Part A - (10*2=20 marks)

1. Write the regular expression for identifier and number


2. Compare Syntax tree and Parse tree
3. Write the rule to eliminate left recursion in a grammar
4. Mention the role of semantic analysis
5. Draw syntax tree for the expression a=b*-c+b*-c
6. Define back patching
7. List the advantages of DAG
8. What are the uses of register and address descriptors in code generation?
9. Define live variable
10. What is data flow analysis?

PART – B (5 X 16 = 80 MARKS)

11. (a) Explain in detail about the phases of compiler and translate the statement
(position :=initial+rate*60 )
Or
(b) Compare NFA and DFA. Construct a DFA directly from an augmented regular
expression ((€/a)b*)*.

12. (a) Construct non recursive predictive parsing table for the following grammar.
E->E or E | E and E | not E | (E) |0 |1.

Or
(b) Construct SLR parsing table for the grammar

E->E+T |T
T->TF |F
T->F*| a| b

21
13. (a) (i) Translate the following switch statement into intermediate code.

Switch E
begin
case V1:S1
case V2:S2
case Vn-1 : Sn-1
default :Sn
end

(ii) Generate three address code for Boolean expression a<b or c<d and e<f.

Or
(b) (i) Translate the executable statements of the following C program into three
Address code.

main()
{
Int i,a[10];
i=1;
while (i<=10)
{
a[i]=0;i=i+1;}
(ii)Discuss how compilers generate code for procedure calls.

14.(a) (i) Discuss the characteristics of peephole optimization.


(ii) Generate code for the following assignment using the code generator
algorithms := (a-b) + (a-c) + (a-c).

Or
(b) Explain in detail register allocation and assignment.

15.(a) Discuss in detail about global data flow analysis.

Or
(b) (i) Explain the three technique for loop optimization with examples.

(ii)Explain constant folding and copy propagation with examples.

22
B.E/B. Tech DEGREE EXAMINATION, MAY/JUNE 2013
Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Part A - (10*2=20 marks)

1. Define Token, Patterns and Lexeme.


2. Mention the issues in a lexical analyzer.
3. Eliminate immediate left recursion for the following grammar.
A->Ac/Aad/bd/€
4. Give examples for static check.
5. What are the various ways of representing intermediate language?
6. What is back patching?
7. Define basic blocks and flow graphs.
8. Given any four applications of DAG.
9. What is constant Folding?
10. What are the properties of optimizing compilers?

PART – B (5 X 16 = 80 MARKS)

11. (a) (i) Write in details about the cousins of the compiler (8)
(ii) Explain in detail about the role of lexical analyzer with the possible
error recovery actions. (8)
Or
(b) (i) what are the phases of the compiler? Explain the phases in detail.
Write down the output of each phase for the expression a=b*c+50-d.
(10)
(ii) Elaborate the specification of tokens (6)

12. (a) (i) Construct The predictive parser for the following grammar. (10)
S->(L) / a L - > L,S / S
(ii) List all LR(0) items for the following grammar (6)
S->AS/b A->SA/a.
Or
(b) (i) What are the different storage allocation strategies? Explain (8)
(ii) Specify a type checker which can handle expressions, statements and
Functions. (8)

23
13. (a) (i) What are the various methods of implementing three address
statements? Explain with example. (8)

(ii) Explain about back patching with an example (8)

Or

(b) (i) Write down the translation scheme to generate three address code for the
assignment statement?
(ii) How would you generate intermediate code for the flow of the control
statements?

14 (a) (i) Discuss briefly about simple code generation algorithm


(ii) For the flow graph shown below, write the three address statements and
construct the DAG

(1) T1=4*i
(2) T2 =a[T1]
(3) T3=4*i
(4) T4=b[T3]
(5) T5=T2*T4
(6) T6=prod+T5
(7) Prod=t6
(8) T7=i+1
(9) i=T7
(10) if i<= 20 goto (1)
Or

(b) (i) Explain the concept of register allocation and assignment (8)
(ii) Discuss labeling algorithm with an example (8)

15 (a) Write the principle sources of optimization

Or

(b) (i) Explain the data-flow analysis of structured programs


(ii) Write the global common subexpression elimination algorithm with example (8)

24
B.E/B. Tech DEGREE EXAMINATION, NOV/DEC 2013
Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Part A - (10*2=20 marks)

1. How will you group the phases of compiler?


2. Write the regular expression of identifier and whitespace.
3. Eliminate the left recursion for the grammar.
S-> A a | b
A-> A c | S d |
4. What is meant by coercion?
5. Define backpatching.
6. Translate the arithmetic expression a * _ (b +c) into syntax tree and postfix
notation.
7. What is the use of Next-use information?
8. List the fields in an activation record.
9. Define loop unrolling with example.
10. What is Optimizing compiler?

PART –B (5*16=80 marks)

11.(a) (i) Explain the different phases of a compiler in detail.


(ii) Discuss the cousins of compiler.

Or
(b) (i) Draw the DFA for the augumented regular expression (a |b) * # directly using syntax
tree.
(ii) Discuss input buffering techniques in detail.

12.(a) Design an LALR parser for the following grammar and parse the input id= id.

S->L = R| R
L-> *R | id
R-> L

25
Or
(b ) (i) Discuss in detail about storage allocation strategies.

(ii) Explain about various parameter passing methods in procedure calls.

13.(a) (i) Write the translation scheme for flow of control statements.
(ii) Explain and compare in detail the various implementation forms of three address code.

Or
(b) (i) write the grammar and translation scheme for procedure call statements.
(ii) draw the DAG for the following three address code.
d = b*c
e= a+b
b=b*c
a=e-d.

14.(a) (i) Discuss runtime storage management in detail.


(ii) Write short notes on structure preserving transformation of basic blocks.
(b) Construct DAG and three address code for the following C program.

i=1;
s=0;
while (i < =10)
{
s=s + a [i] [i]
i=i+1
}

15. (a) (i) Write in detail about loop optimization.


(ii) Discuss the characteristics of peephole optimization.

Or
(b) Discuss in detail about global data flow ananlysis.

26
Question Paper Code: 71391

B.E/B. Tech DEGREE EXAMINATION, MAY/JUNE 2014


Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Part A - (10*2=20 marks)

1. State any two reasons as to why phases of compiler should be grouped


2. Why is buffering used in lexical analysis ? what are the commonly used buffering
methods?
3. Define Lexeme.
4. Compare the features of DFA and NFA
5. What is the significance of intermediate code?
6. Write the various three address code form of intermediate code
7. Define symbol table
8. Name the techniques in loop optimization
9. What do you mean by Cross-Compiler
10. How would you represent the dummy blocks with no statements with no
statements indicated in global data flow analysis?

PART –B (5*16=80 marks)

11. (a) (i) Define the following terms : Compiler, Interpreter, Translator and
differentiate between them. (6)
(ii) Differentiate between lexeme, token and pattern (6)
(iii) What are the issues in lexical analysis? (4)

Or

(b) Explain in detail the process of compilation. Illustrate the output of each phase
of compilation for the input “a=(b+c)*(b+c)*2”

12. (a) Consider the following grammar


S→AS| b
A→SA|a

27
Construct the SLR parse table for the grammar. Show the actions of the parser for the
input string “abab”
Or
(b) (i) What is an ambiguous grammar? Is the following grammar ambiguous? Prove
E→E+E|E*E|(E) |id. The grammar should be moved to the next line,centered.

(ii). Draw NFA for the regular expression ab*/ab.

13. (a) How would you convert the following into intermediate code? Give a suitable
example.
(i) Assignment statements. (8)
(ii) „Case‟ statements. (8)
Or

(b) (i) Write notes on backpatching.


(ii) Explain the sequence of stack allocation processes for a function call.

14. (a) Discuss the various issues in code generation with examples.
Or
(b) Define a Directed Acyclic Graph. Construct a DAG and write the sequence of
instructions for the expression a+a*(b-c)+(b-c)*d.

15.(a) Discuss in detail the process of optimization of basic blocks .Give an example.
Or
(b) What is data flow analysis and explain data abstraction with examples.

28
B.E/B. Tech DEGREE EXAMINATION, NOV/DEC 2014
Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Part A - (10*2=20 marks)

1. What is the role of lexical analyser?


2. Write regular expression to describe a languages consist of strings made of even
numbers a and b.
3. List out the various storages allocation strategies.
4. Write a CF grammar to represent palindrome.
5. What are the types of intermediate languages?
6. Give syntax directed translation for case statement.
7. Differentiate between basic block and flow graph.
8. Draw DAG represent a[i]=b[i]; a[i]=&t.
9. Represent the following in flow graph
i=1; sum=0; while(i<=10){sum+=i;i++}
10. What is global data flow analysis?

PART B –(5*16=80 marks)

11. (a) (i) Explain the need for grouping of phases of complier. (8)
(ii) Explain a language for specifying the lexical analyser
(8)
OR
(b) (i) Write short notes on complier construction tools. (8)
(ii) Explain – specification and recognition of tokens. (8)

12. (a) (i) Explain the specification of simple type checker


(8)
(ii) Explain – runtime environment with suitable example
(8)

OR

29
(b) Find the LALR for the given grammar and parse the sentence (a+b)*c
E E+T|T,TT*F|F,F(E)|id.

13. (a) Generate intermediate code for the following code segment along with the
required syntax directed translation scheme
While(i<10)
If(i%2==0)
Evensum =evensum+i;
Else
Oddsum=oddsum+i; (16)

OR
(b) Generate intermediate code for the following code segment along with the
required syntax directed translation scheme. (16)
s=s+a[i][j];

14. (a) (i) Explain register allocation and assignment with suitable example. (8)
(ii) Explain – code generation phase with simple code generation
algorithm
(8)

(b) (i) Generate DAG representation of the following code and list out the
application of DAG representation. (8)
i=1; while(i<=10) do
sum+=a[i];
(ii) Explain – generation code from DAG with suitable example. (8)

15. (a)(i) Explain – principle sources of optimization. (8)


(ii) Illustrate optimization of basic block with an example
(8)
OR
(b) Explain peephole optimization and various code improving transformation

30
B.E/B. Tech DEGREE EXAMINATION, APR/MAY 2015
Sixth Semester
(Regulation 2008)
Computer Science and Engineering

CS 2352 - PRINCIPLES OF COMPILER DESIGN

Time: Three hours Maximum: 100 marks

Part A - (10*2=20 marks)

1. Describe the error recovery schemes in the lexical phase of a complier.


2. Write a regular definition to represent date in the following format:
JAN 5th 2014
3. What is the role of passer?
4. Construct a decorated parse tree according to the syntax directed definition , for
the following input statement ( 4 + 7.5 * 3 ) / 2
5. Write the 3 address code for : x = * y; a = & x.
6. Place the above generated 3 address code in Triplets and Indirect Triplets.
7. What role does the target machine play on the code generation phase of the
complier?
8. How is Liveness of a variable calculated
9. Generate code for the following C statement assuming three register are available
:x=a/(b+c)-d*(e+f).
10. Write the algorithm that orders the DAG nodes for generating optimal target code
.
PART B - ( 5 X 16=80 Marks )

11. (a) Prove that the following two regular expressions are equivalent by
showing that the minimum state DFA‟s are same .

I. (a/b)* (8)
II. (a*/b*)* (8)
Or

31
(b) (i) Describe the error recovery schemes in the lexical phase of a
complier. (8)
(ii) Mention any four compiler construction tools with their benefits
and drawbacks. (8)

12. (a) (i) Generate SLE Parsing Table for the following grammar (12)

S -> Aa | bAc | Bc | bBa


A -> d
B -> d

And parse the sentence “bdc” and “dd”.

(ii) Mention in detail any 4 issues in storage organization . (4)

(b) (i) Write down the algorithm to eliminate left recursion and left –
factoring and apply both to the following grammar (8)

E-> E+T|E T|T


T-> a|b|b|(E)

(ii) Give a syntax directed definition to differentiate expressions


formed by applying the arithmetic operators + and * to the
variable x and constant ; expression : x*(3 * x + x * x). (8)

13 (a) For the given program fragment A[i,j]=B[i,k]do the following :

(i) Draw the annotated parse tree with the translation scheme to convert to
three address code (6)
(ii) Write the 3-address code (6)
(iii) Determine the address of A[3,5] where, all are integer arrays with size of
A as 10 x10 and B as 10 x 10 with k=2 and the start index position of all
arrays is at 1. (Assume the base address) (4)

Or

(b) (i) Apply Back patching to generate intermediate code for the
following input
x:2+y;
If x<y then x:=x+y;
repeat
y:=y * 2;
while x>10 do x:=x/2

32
until x<y
Write the semantic rule and derive the Parse tree for the given
code (12)
(ii) What is an Activation Record? Explain how its relevant to the
intermediates code generation phase with respect to procedure
declarations. (4)

14 (a) (i) Write the Code Generation Algorithm using Dynamic Programming
and generate code for the statement x=a/(b-c)-s*(e+1)[assume all
instructions to be unit cost (12)
(ii) What are the advantages of DAG representation ? Give example. (4)
(Or)
(b) (i) Write the procedure to perform Register Allocation and Assignment
with Graph Coloring.
(ii) Construct DAG and optimal target code for the expression
x=((a+b)/(b-c))-(a+b)*(b-c)+/.

15 (a) Perform analysis of available expressions on the following code by converting


into basic blocks and compute global common sub expression elimination
(i) i:=0
(ii) a:=n_3
(iii)IF i<a THEN loop ELSE end
(iv) LABLEL Lop
(v) b:=i_4
(vi) c:=p+b
(vii) d:=M[c]
(viii) e:=d_2
(ix) f:=i_4
(x) g:=p+f
(xi) M[g]:=e
(xii) I:=i+1
(xiii) a:=n_3
(xiv) IF i<a THEN loop ELSE end
(xv) LABLEL end (16)

(b) (i) Explain Loop optimization in details and apply it to the code in 5(a)
(10)
(ii) What are the optimization techniques applied on procedures calls? Explain
with example (6)

33
Question Paper Code: 21391
B.E/B.Tech. DEGREE EXAMINATION, NOV/DEC 2015
CS 2352/CS 62/10144 CS 602 – PRINCIPLES OF COMPILER DESIGN
(Regulation 2008/2010)

Time: Three hours Maximum :100 marks

Answer ALL questions.


PART A- (10*2=20 MARKS)
1. State the interactions between the lexical analyzer and the parser.
2. What are the components of Lex?
3. Define the error recovery strategies?
4. State the kinds of data that appear in activation record?
5. What are synthesized attributes?
6. What is short circuit code?
7. Define the dead code elimination.
8. What are the issues in the design of code generator?
9. What are the global common sub expressions?
10. What are the control- flow constraints?
PART B – (5*16 = 80 MARKS)
11. (a) (i) State and explain the architecture of a transition – diagram- based lexical
analyzer. (8)
(ii) How to minimize the number of states od DFA. Explain it with (8)
example.
Or
(b) (i) Explain the procedure for construction of an NFA from a regular (8)
expression
(ii) What are the function computed from the syntax tree. Explain each
function with example. (8)
12. (a) (i) Distinguish between context free grammar and regular
expressions. (8)
(ii) What are the conflicts during shift – reduce parsing? Explain
Or

34
(b) (i) What are the storage allocation strategies? Explain them with example.
(ii) Distinguish between static and dynamic storage allocations.
13. (a) (i) Distinguish between quadruples and triples with examples.
(ii) What are the rules for type checking? Give an example.
Or
(b) (i) State and explain the algorithm for unification
(ii) Explain the one pass code generation using back patching with
Examples.
14. (a) (i) Generate code for the following three-address statements assuming stack
allocation where register SP points to the top of stack.
Call p
Call q
Return
Call r
Return
Return
(ii) What are local common sub expressions? Explain the procedure to
eliminate the local common sub expression.
Or
(b) (i) Explain the procedure for register allocation by graph coloring with an
example.
(ii) Explain the steps carried out for generating code from dags with suitable
Examples.
15. (a) (i) Explain the procedure to find the induction variable in loops and
optimize their computation. What is the function of strength reduction?
(ii) What is peephole optimization? State and explain the characteristic of
peephole optimization.

Or
(b) (i) What is data flow abstraction? Explain it with a program illustrating the
data Flow abstraction.
(ii) What is live-variable analysis? Explain it with example.

35
B.E./B.Tech DEGREE EXAMINATION,MAY/JUNE 2016
Sixth Semester
Computer Science and Engineering
CS6660-COMPILER DESIGN
(Regulation 2013)
Time: Three Hours Maximum: 100 Marks
ANSWER ALL QUESTIONS
PART-A (10*2=20 MARKS)
1. What are two parts of a compilation? Explain briefly?
2. Illustrate diagrammatically how a language is processed
3. Write a grammar for branching statements
4. List the operations on languages.
5. Write the algorithm for FIRST and FOLLOW in parser
6. Define ambiguous grammar
7. What is DAG?
8. When do Dangling references occur?
9. What are the properties of optimizing compiler?
10. Write three address code sequence for the assignment statement
d:=(a-b)+(a-c)+(a-c).
PART-B (5*16=80 MARKS)
11. (a) Describe the various phases of compiler and trace it with the program segment
( position :=initial + rate*60).
OR
(b) (i) Explain language processing system with neat diagram (8)
(ii) Explain the need for grouping of phases (4)
(iii) Explain various error encountered in different phases of compiler (4)
12. (a) (i) Differentiate between lexeme ,token and pattern (6)
(ii) What are the issues of lexical analysis? (4)
(iii) Write notes on regular expression (6)
OR
(b) (i) Write notes on regular expression to NFA.Construct Regular expression to NFA for
the Sentence ( a|b) * a (10)
(ii) Construct DFA to recognize the language ( a/b )*ab (6)
13. (a) (i) Construct stack implementation of shift reduce parsing for the grammar (8)
E->E+S
E->E*E
E->( E )
E->id and the input string id1+id2*id3
(ii) Explain LL(1) grammar for the sentence S->iEts | iEtSeS | a E->b (8)
OR
(b) (i) Write an algorithm for Non recursive predictive parsing (6)
(ii) Explain Context Free grammars with examples (10)

36
14. (a) (i) Construct a syntax directed definition for constructing a syntax tree for
assignment statements (8)
S->is: =E
E->E1+E2
E->E1*E2
E->-E1
E-> ( E1 )
E->id

(ii) Discuss specification of a simple type checker (8)


OR
(b) Discuss different storage allocation strategies (16)
15. (a) Explain principal sources of optimization with examples (16)
OR
(b) (i) Explain various issues in the design of code generator (8)
(ii) Write note on simple code generator (8)
------------------------------

37
QUESTION PAPER CODE : 80303
B.E./B.Tech DEGREE EXAMINATION,NOV/DEC 2016
Sixth Semester
Computer Science and Engineering
CS6660-COMPILER DESIGN
(Regulation 2013)
Time: Three Hours Maximum: 100 Marks
ANSWER ALL QUESTIONS
PART-A (10*2=20 MARKS)

1. What is a symbol table?


2. List the various compiler construction tools.
3. List the rules that form the BASIS.
4. Differentiate tokens,patterns,lexemes.
5. Construct a parse tree for -(id + id )
6. What is meant by handle pruning?
7. Write down syntax directed definition of a simple desk calculator.
8. List dynamic storage allocation techniques
9. Identify the constructs for optimization in basic bl9ock.
10. What are the characteristics of peephole optimization?

PART-B (5*16=80 MARKS)

11. (a) (i) Explain the phases of compiler with a neat diagram. (10)
(ii) Write notes on compiler construction tools. (6)

Or
(b) (i) Explain the need for grouping of phases. (8)
(ii) Explain the various errors encountered in different phases of a compiler.(8)

12. (a) (i) Discuss the role of Lexical analyzers in detail with necessary examples. (8)
(ii) Discuss how finite automata is used to represent tokens and perform lexical
analysis with examples.

Or
(b) (i) Conversion of regular expression (a/b)*abb to NFA. (8)
(ii) Write an algorithm for minimizing the number of states of a DFA. (8)

13. (a) (i) Construct parse tree for the input string w=cad using topdown parser. (6)

S→cAd
A→ab|a
(ii) Construct parsing table for the grammar and find moves made by

38
predictive parser on input 1d+id*id and find FIRST and FOLLOW.(10)

E→E+T
E→ T
T→T*F
T→F
F→(E)/id

Or
(b) (i) Explain ambiguous grammer G: E→E+E| E*E| (E) | -E| id for the sentence
id+id*id. (6)
(ii) Construct SLR parsing Table for the following grammer:
G: E→E+T| TT→T*F| FF→(E) | id. (10)

14.(a) (i) A Syntax-Directed Translation scheme that takes strings ofa‟s, b‟s and c‟s as
input and produces as output the number of substrings in the input string that
correspond to the pattern a(a|b)*c+(a|b)*b. For example the translation of the
input string “abbcabcababc” is”3”.

(1) Write a context – free grammer that generate all strings os a‟s,b‟s and c‟s.
(2) Give the semantic attributes for the grammer symbols.
(3) For each production of the grammer present a set of rules for evaluation of
the semantic attributes. (8)

(ii) Illustrate type checking with necessary diagram. (8)

Or
(b) Explain the following with respect to code generation phase.
(i) Input to code generator
(ii) Target program
(iii) Memory management
(iv) Instruction selection
(v) Register allocation
(vi) Evaluation order. (16)

15.(a) (i) Write an algorithm for constructing natural loop of a back edge. (8)
(ii) Explain any four issues that crop up when designing a code generator. (8)

Or
(b) Explain global data flow analysis with necessary equations. (16)

39

You might also like