COMPILER DESIGN IMPORTANT QUESTIONS MODEL

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

COMPILER DESIGN IMPORTANT QUESTIONS

Compare and contrast compiler and interpreter.

What is cross compiler? Give example.

What is the role of compiler?

Define compiler. Draw its basic block diagram.

Draw the block diagram of a hybrid compiler.

Define a Translator. Draw its block diagram.

List the two parts of compilation.

Mention the three-analysis part of the source program.

Mention the three-synthesis part of the source program.

Differentiate phases and passes of compiler.

List 3 reasons for why lexical analysis and parsers is separated.

What is the role of symbol table in structure of compiler?

Construct the symbol table for a=b+c*d.

Mention the reason for separating scanner and parser phase.

Mention the two processes of lexical analyser.

Define symbol table. Give example.

Write the algorithm for buffer pair.

Why is buffering used in lexical analysis? What are the commonly used buffering methods?

Differentiate buffer pairs and sentinel approach.

Write the algorithm for sentinels in input buffering.

What is an ambiguous grammar?

Write a CFG grammar to represent a palindrome.

Write a CFG for branching statements.

Write the formal definition of a CFG.

What is meant by derivations? Give its types.


Write the CFG for arithmetic expression.

Why left factoring is suitable for predictive parsing?

Write the rule for left factoring of a grammar.

Why left factoring is suitable for top-down parsing?

Define left factoring. Give example.

Write the rule to eliminate left recursion in a grammar. Give example.

Eliminate the left recursion from the following grammar


A->Ac | Aad | bd | ε

Eliminate the left recursion from the following grammar


S->Aa | b
A->Ac|Sd|ε

Eliminate left recursion from the following grammar:


S->(L)| a
L->L,S|S

Eliminate the left recursion from the following grammar


E->E+T |T

Write the algorithm to eliminate left recursion from a grammar.

Define Handle and Handle pruning?

Define Viable Prefixes. Give example.

Differentiate kernel and non-kernel items.

What are the various conflicts that occur during shift reduce parsing?

Mention the role of semantic analysis.

Define syntax directed definition?

How is the value of synthesized attribute computed?

How is the value of inherited attribute computed?

Define synthesized and inherited attributes.

Compare and contrast synthesized and inherited attributes.

Define annotated parse tree.

Differentiate syntax tree and parse tree.

What is a dependency graph?


What is the purpose of syntax directed translation.

Mention the two rules for type checking.

What is Type Checking?

Compare structural and name equivalence in type expressions.

What is Type Inference?

What is meant by coercions?

What is the advantage of coercion in semantic analysis.

List the fields in the activation record.

Give the typical sub-division of memory.

Define activation record.

Compare and contrast static and dynamic storage allocation.

List the four principles followed during calling sequences.

When procedure call occurs, what are the steps taken?

When procedure return occurs, what are the steps taken?

What is a calling sequence?

What is a return sequence?

Compare and contrast calling and return sequence?

What is a display in access-link approach?

How is access link used when a procedure is passed as a parameter?

What is the use of access link?

What is the purpose of control link?

What is a memory manager?

What are the properties of a memory manager?

List the two functions of a memory manager.

What is a memory hierarchy?

How is fragmentation minimized in a heap?

List the three programming conventions and tools for memory management.
Differentiate address and register descriptor.

What is an address descriptor?

What are the goals of a code generator?

What is a register descriptor?

Define Basic Block.

What is meant by dead-code elimination?

Define copy propagation.

Differentiate local and global common subexpression.

Give an example of code motion.

Mention the objective of code optimization.

What is meant by common subexpression elimination.

Define code motion.

Give an example of copy propagation.

What is meant by basic block.

Optimize the Source Code: a = b + c; e = c + d + b.

Give syntax tree and DAG representation : a := b *-c + b*-c.

Illustrate the uses of liveness and next-use with suitable example

In the give code, identify which is Induction Variable and eliminate it


int max = 10;
int result = 0;
for (int i = 0; i< max; i++) {
result += 2;
}
return result;

What are the properties of optimizing compiler?

What is meant by reaching definitions in data-flow analysis?

Define data-flow analysis schema.

What is meant by live-variable analysis?

Define reaching definitions in data-flow analysis.

What is meant by data-flow analysis schema?


Describe the various phases of compiler and trace it with the program segment position: = initial + rate * 60.
(13)

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 in detail about the role of lexical analyser. (8)


(ii) Explain in detail about tokens, patterns, lexemes and attributes for tokens. (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)

(i) Explain about the role of Lexical Analyzer. (5)


(ii) Explain briefly about buffer pairs. (4)
(iii) Write the lookahead code with sentinels. (4)

Explain in detail about recognition of tokens along with the regular expression and transition diagram for
relop.(13)

(i)What is meant by regular expression and regular definition.(4)


(ii)Construct the transition diagram for relop along with its tokens, their patterns and attribute values. (9)

Explain in detail specification and recognition of tokens in detail. (7+6)

Write short notes on the following topics


(i)Regular Expressions (4)
(ii)Regular Definitions (4)
(iii)Transition diagram for relop (5)

(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 the role of the Parser. (6)


(ii)Write the CFG for simple arithmetic expressions and eliminate ambiguity. (7)

(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)

(i)Construct the parse tree for id+id*id for an expression grammar.(7)


(ii)Write the leftmost and rightmost derivation for id+id*id for an expression grammar. (6)

Consider the grammar


S->aSbS|bSaS| ε
(i)Show that this grammar is ambiguous by constructing two different leftmost derivations for the sentence
abab. (4)
(ii)Construct the rightmost derivations for abab. (4)
(iii)Construct the parse tree for abab. (5)

(i)Construct an ambiguous grammar for an expression and eliminate ambiguity. (5)


(ii)Write the leftmost and rightmost derivation for id*id+id along with its parse tree using both ambiguous
and unambiguous grammar. (8)

Consider the grammar


S->(L)|a
L-<L,S|S
(i)What are the terminals, nonterminals and start symbol? (4)
(ii)Find parse trees for (a,(a,a)). (4)
(iii)Construct the leftmost and rightmost derivations for (a,(a,a)).(5)

(i) Write the productions for Dangling else grammar. (3)


(ii) Construct the predictive parsing table for it. (10)

Construct predictive parsing table for the grammar (13)


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

Find the predictive parser table for the given grammar (13)
S->a|^|(T)
T->T,S|S

Construct predictive parsing table for the grammar (13)


S->(L) | a
L->L,S | S

Construct the SLR parsing table for this grammar (13)


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

Construct the SLR parsing table for the following grammar.(13)


S->AS | b
A->SA | a

Construct SLR parsing table. (13)


S->Aa | bAc | dc | bdA
A->d

Construct the SLR parsing table for (13)


S->AaAb | BbBa
A->ε
B->ε

Construct the SLR parsing table for the grammar. (13)


S->Aa | bAc | Bc | bBa
A->d
B->d

Construct the SLR parsing table for an expression grammar. (13)


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

Construct Stack Implementation of shift reduce parsing (13)


E->E+E | E*E | num | id.
and derive the input string id1* num + id3.

Construct Stack Implementation of shift reduce parsing (13)


S → S+S
S → S-S
S → (S)
S→a
and derive the input string a1-(a2+a3).

Construct Stack Implementation of shift reduce parsing (13)


E->E+T | T
T->T*F | F
F->(E) | id
and derive the input string id1 + id2 * id3.

Construct Stack Implementation of shift reduce parsing (13)


S → S+S
S → S-S
S → (S)
S→a
and derive the input string a1-(a2+a3).

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)

Triples and Indirect Triplesa = −b + c ∗ d. (13)


Convert the following expression into Three address codes and represent the same in the form of Quadruples,

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)Write short notes on Activation Trees. Give example. (8)


(ii)Explain about Activation Records with an example.(5)

(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)

(i)Explain about downward-growing stack of activation records. (7)


(ii)Explain about division of task between caller and callee. (6)

Explain in detail about Access to Non-local Data on the stack. (13)

(i)Explain in detail about Access Links with quicksort program. (10)


(ii)What is meant by nesting depth? (3)

(i)Write short notes on Data access without nested procedures. (7))


(ii)Write short notes on Access links for procedure parameters.(6)

(i)Explain in detail about storage organization. (5)


(ii)Explain in detail about stack allocation of space. (8)

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)

(i)Explain in detail about Issues in the design of code generator. (8)


(ii)Construct DAG for (5)
a=b+c
t1 = a * a
b = t1 + a
c = t1 * b
t2 = c + b
a = t2 + t2

(i)Explain the five issues in the design of code generator. (8)


(ii)Construct DAG for (5)
a=b*c
d=b
e=d*c
b=e
f=b+c
g=f+d

Write short notes on


(i) Instruction Selection in the code generator (4)
(ii) Register Allocation with an example. (4)
(iii) Write the optimal machine-code sequences for (5)
t=a+b
t=t*c
t=t/d

(i)Explain about the issues in the design of a code generator. (8)


(ii)Construct DAG for( ( ( a + a ) + ( a + a ) ) + ( ( a + a ) + ( a + a ) ) ) (5)

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 code-improving transformations with an example. (13)

Write in detail about function-preserving transformations with an example. (13)

Explain in detail about primary structure-preserving transformations on basic blocks with an example.
(13)

Explain in detail about semantics-preserving transformation with Quicksort program. (13)

Construct the flow graph for the quicksort fragment and optimize it.(13)

Perform code optimization for quicksort program.(13)

Explain the code optimization performed in the quicksort fragment. (13)

Construct the optimized flow graph for the quicksort fragment. (13)

Explain in detail about peephole optimization. (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.

Explain in detail about peephole optimization with an example. (13)

(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];

Explain in detail about data flow analysis with an example. (13)

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;

Explain in detail about optimization of basic blocks. (13)

Explain in detail about global data flow analysis. (13)

Explain in detail about peephole optimization with example. (13)


(i)Write the Three-address code for expressions along with its semantic rules. (8)
(ii)Write the Semantic actions and rules for array references. (7)

Explain in detail about Translation of Expressions.(15)

(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)

Explain in detail Lexical Analyzer Generator. (15)

Write short notes on


(i) The memory hierarchy of a computer. (5)
(ii) Locality in Programs. (5)
(iii) Reducing Fragmentation. (5)

Explain in detail about parser generator YACC. (15)

(i)Explain about the memory hierarchy of a computer.(5)


(ii)Explain about the Manual Deallocation Requests. (5)
(ii)Explain in detail about Locality in Programs. (5)

Construct the LALR parsing table for (15)


S->CC
C->cC | d

Show that the following grammar (15)


S->Aa|bAc|dc|bda
A->d
Is LALR(1) but not SLR(1).

Construct the LALR parsing table for (15)


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

Show that the following grammar (15)


S->Aa| bAc| Bc| bBa
A->d
B->d
Is not LALR(1).

Construct the LALR sets of items for the grammar (15)


S->SS+|SS*|a

Construct the LALR sets of items for the grammar (15)


S->aAd|bAd|aBe|bAe
A->c
B->c

(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)

You might also like