COMPILER DESIGN IMPORTANT QUESTIONS MODEL
COMPILER DESIGN IMPORTANT QUESTIONS MODEL
COMPILER DESIGN IMPORTANT QUESTIONS MODEL
Why is buffering used in lexical analysis? What are the commonly used buffering methods?
What are the various conflicts that occur during shift reduce parsing?
List the three programming conventions and tools for memory management.
Differentiate address and register descriptor.
Explain in detail the process of compilation. Illustrate the output of each phase of the compilation for the
input “a = (b+c) * (b+c) *2”. (13)
Write about the phases of compiler and by assuming input a=b*-c+b*-c and show the output of various
phases with an example. (13)
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 - 60 . (13)
Discuss various phases of the compiler and examine with program segment for the input a=b*c - d.
(13)
Explain in detail about the two parts of compilation process. Draw the block diagram and solve for a=b+c*50.
(13)
(i) Explain about the interactions between the lexical analyser and parser with block diagram. (8)
(ii) Describe the errors encountered in different phases of compiler. (5)
(i) Explain about tokens, patterns and lexemes with example. (8)
(ii)Write the token names, attribute values for E=M*C**2. (5)
(i) List the different types of lexical errors &error-recovery actions. (7)
(ii) Give examples for tokens, patterns and lexemes. (6)
Explain in detail about input buffering techniques along with its algorithm and diagram.(13)
Explain in detail about recognition of tokens along with the regular expression and transition diagram for
relop.(13)
(i) Construct the optimized DFA for the regular expression ab*|ab along with its transition table and
transition diagram. (8)
(ii) Write the rules for computing nullable, firstpos and followpos. (5)
Convert the Regular Expression (a|b)*abb to DFA using direct method and write the algorithm for nullable,
firstpos and followpos.(13)
Convert the Regular Expression abb(a|b)* to DFA using direct method and write the algorithm for nullable,
firstpos and followpos. (13)
(i) Construct a minimized DFA to recognize the language (a|b)*ab along with its transition table and
transition diagram. (8)
(ii) Write the rules for computing nullable, firstpos and followpos. (5)
(i)Explain in detail about derivations of the grammar and derive id+id*id for an expression grammar. (8)
(ii)Write short notes on formal definition of a context-free grammar.(5)
Find the predictive parser table for the given grammar (13)
S->a|^|(T)
T->T,S|S
Evaluate the expressions for the SDD using annotated parse tree for the follow expressions.
a) 3 * 5 + 4n (6)
b) (3 + 4) * (5 + 6)n (7)
Construct a Syntax-Directed Translation scheme for an expression. Using semantic attributes for each of the
grammar symbols and semantic rules, evaluate the input: 3 * 4 + 5 * 2n. (13)
Construct a Syntax-Directed Translation scheme for desk calculator and evaluate the expression
1*2*3*(4+5)n. (13)
Construct a Syntax-Directed Translation scheme for desk calculator and evaluate the expression (9+8*(7+6)
+5)*4n. (13)
Construct the Syntax-Directed Translation scheme based on Top-Down parsing for an expression and
evaluate 3*5n. (13)
Construct a Syntax-Directed Translation scheme for desk calculator and evaluate the expression
5*6*7*(8+9)n. (13)
Develop the SDD to construct a syntax tree for a simple expression and construct the syntax tree for a – 4 + c.
(13)
Give the SDD for a simple desktop calculator and construct dependency graph for the input string 3 * 5 + 4 n.
(13)
Develop the SDD to construct a syntax tree for a simple expression and construct the syntax tree for 9 – 4 +
3. (13)
Give the SDD for a simple desktop calculator and construct dependency graph for the input string 6 * 7 + 2 n.
(13)
Explain the types of intermediate code representation and generate three address code for the following while
loop (13)
c=0
do
{
if (a < b) then
x++;
else
x–;
c++;
} while (c < 5)
Define Intermediate code, list the different ways of representing it and generate three address code for the
following code (13)
while (A < C and B > D) do
if A = 1 then C = C + 1
else
while A <= D
do A = A + B
Explain the types of intermediate code representation and generate three address code for the below segment
(13)
fact(x)
{
int f = 1;
for (i = 2; i<= x; i++)
f = f * i;
return f;
}
Describe the various forms of intermediate code representation and generate three address code for the
following segment (13)
switch (ch)
{
case 1 : c = a + b;
break;
case 2 : c = a – b;
break;
}
Define Intermediate code, list the different ways of representing it and generate TAC for the given statements
(13)
prod = 0 ;
i=1;
do
{
prod = prod + a[ i ] x b[ i ] ;
i=i+1;
} while (i<= 10) ;
Describe the various forms of intermediate code representation and write the three-address code for the
following segment (13)
switch (ch)
{
case 1 : x = y + z;
break;
case 2 : x = y – z;
break;
}
Convert the following expression into Three address codes and represent the same in the form of Quadruples,
Triples and Indirect Triples. a = b * – c + b * – c.(13)
Convert the following expression into Three address codes and represent the same in the form of Quadruples,
Triples and Indirect Triples (a + b) * (c + d) - (a + b + c). (13)
Convert the following expression into Three address codes and represent the same in the form of Quadruples,
Triples and Indirect Triples a + b + a + b. (13)
Explain in detail about storage organization along with its static versus dynamic storage allocation. (13)
(i)Explain the sequence of stack allocation processes for a function call. (6)
(ii)Write short notes on Variable-Length Data on the stack. (7)
Explain in detail about stack allocation of space with relevant example. (13)
Write the Quicksort program and construct activation tree and activation record for it. (13)
Explain in detail about various parameter passing methods with a C program to swap two numbers. (13)
List the different ways of parameter passing and write a program to swap two values using different
parameter passing methods. (13)
Compare and contrast the different parameter passing methods with an example. (13)
Write a C program for swapping two values to illustrate the following parameter passing methods
(i) Call by Value (4)
(ii) Call by Reference (3)
(iii) Call by Copy Restore (3)
(iv) Call by Name (3)
Write a C Program to swap two numbers using different parameter passing methods. (13)
What is meant by Actual parameter and Formal parameter in parameter passing methods? Write a C program
to illustrate the different parameter passing methods. (13)
Explain in detail about Principal sources of optimization with quick sort program.(13)
Why do we need code optimization? Explain the principal sources of optimization with quick sort program.
(13)
Explain in detail about primary structure-preserving transformations on basic blocks with an example.
(13)
Construct the flow graph for the quicksort fragment and optimize it.(13)
Construct the optimized flow graph for the quicksort fragment. (13)
Discuss in detail about global data flow analysis with an example. (13)
Analyze the structured control constructs of the following statements and design the Data Flow Equations
respectively (13)
(i) b=10
a=b+c
(ii) if E then S1
else S2
(iii)do S1 while E
using in, out, gen, kill design the equations.
(a) Translate the program into three-address statements of the type we have been using in this section.
Assume the matrix entries are numbers that require 8 bytes, and that matrices are stored in row-major order.
(7)
(b) Construct the flow graph for your code from (a). (3)
(c) Identify the loops in your flow graph from (b). (3)
A matrix-multiplication algorithm:
for (i=0; i<n; i++)
for (j=0; j<n; j++)
c[i][j] = 0.0;
for (i=0; i<n; i++)
for (j=0; j<n; j++)
for (k=0; k<n; k++)
c[i][j] = c[i][j] + a[i][k]*b[k][j];
Construct the flow graph for the following code and optimize it. (13)
i=m-1;j=n;v=a[n];
while(1)
{do i=i+1; while (a[i]<v);
do j=j-1; while(a[j]>v);
if(i>=j) break;
x=a[i];a[i]=a[j];a[j]=x;}
x=a[i];a[i]=a[n];a[n]=x;
(i)Explain about operations within expressions along with its semantic rules. (8)
(ii)Write the Translation of Array References. (7)
Explain about the Translation of Expressions with its semantic rules and actions. (15)
(i)Write the Three Address Code for operations within expression. (8)
(ii) Write short notes on Array references along with its semantic rules. (7)
Explain in detail about the Translation of Expressions along with its semantic rules and actions for
expressions and arrays.(15)
(i) Construct the €-NFA for a|(bc)* and find the minimized DFA. (10)
(ii) Write the algorithm for Minimizing the number of states of DFA.(5)
(i)Write the algorithm for Thompson construction, construct €-NFA for0(0|1)*0 and minimized DFA. (10)
(ii)Write the algorithm for Minimizing the number of states of DFA. (5)
(i) Construct the €-NFA using Thompson construction for ab*|ab and find the minimized DFA. (10)
(ii) Write the algorithm for Minimizing the number of states of DFA.(5)
(i) Write the Thompson construction algorithm and construct €-NFA for (a*|b*)*. (10)
(ii) Write the algorithm for Minimizing the number of states of DFA. (5)