Professional Documents
Culture Documents
Knowled PDF
Knowled PDF
DEPARTMENT OF CSE
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)
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)
3
B.E./B. Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2007
Sixth Semester
(Regulation 2004)
Computer Science and Engineering
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)
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
11. (a) (i) Explain the phases of compiler, with the neat schematic (12)
(ii) Write short notes on compiler construction tools (4)
Or
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
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
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
7
15. (a) (i) Explain-principle sources of optimization (8)
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]
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 ( ) , $
$ < <
Or
13. (a) (i) What are the various data structures used for symbol table construction and
explain any one in detail (8)
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)
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)
Or
10
B.E/B. Tech DEGREE EXAMINATION, MAY/JUNE 2009.
Sixth Semester
(Regulation 2004)
Computer Science and Engineering
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:
15. (a) Explain with an example how basic blocks are optimized.
(or)
(b) Explain the storage allocation strategies used in run time environments.
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)
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.
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
14
B.E/B. Tech DEGREE EXAMINATION, APRIL/MAY 2011.
Sixth Semester
(Regulation 2008)
Computer Science and Engineering
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
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)
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
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)
18
B.E/B. Tech DEGREE EXAMINATION, MAY/JUNE 2012
Sixth Semester
(Regulation 2008)
Computer Science and Engineering
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?
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
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
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.
Or
(b) Explain in detail register allocation and assignment.
Or
(b) (i) Explain the three technique for loop optimization with examples.
22
B.E/B. Tech DEGREE EXAMINATION, MAY/JUNE 2013
Sixth Semester
(Regulation 2008)
Computer Science and Engineering
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)
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?
(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)
Or
24
B.E/B. Tech DEGREE EXAMINATION, NOV/DEC 2013
Sixth Semester
(Regulation 2008)
Computer Science and Engineering
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.
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.
i=1;
s=0;
while (i < =10)
{
s=s + a [i] [i]
i=i+1
}
Or
(b) Discuss in detail about global data flow ananlysis.
26
Question Paper Code: 71391
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”
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.
13. (a) How would you convert the following into intermediate code? Give a suitable
example.
(i) Assignment statements. (8)
(ii) „Case‟ statements. (8)
Or
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
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)
OR
29
(b) Find the LALR for the given grammar and parse the sentence (a+b)*c
E E+T|T,TT*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)
30
B.E/B. Tech DEGREE EXAMINATION, APR/MAY 2015
Sixth Semester
(Regulation 2008)
Computer Science and Engineering
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)
(b) (i) Write down the algorithm to eliminate left recursion and left –
factoring and apply both to the following grammar (8)
(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)+/.
(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)
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
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)
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)
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