VTU Computer Science (Semester 6)
Compiler Design
December 2013
Total marks: --
Total time: --
INSTRUCTIONS
(1) Assume appropriate data and state your reasons
(2) Marks are given to the right of every question
(3) Draw neat diagrams wherever necessary


1 (a) Explain the various phases of compiler. Show the translations for an assignment statement. Position= initial+rate*60, clearly indicate the output of each phase.
12 M
1 (b) Write the regular definition for an unsigned number. Also write the transition diagram.
6 M
1 (c) What is printed by the following C code?
#define a(x+1)
int x=2;
void b() {int x=1; printf("%d ln".a);}
void c() {printf("%d ln", a);}
void main() {b(): c();}
2 M

2 (a) Describe an algorithm used for eliminating the left recursion. Eliminate left recursion from the grammar:
S→Aa|b A→Ac|Sd|a.
6 M
2 (b) Show that the following grammar is ambiguous:
E→E+E|E*E|(E)| id. Write an equivalent unambiguous grammar for the same.
6 M
2 (c) What are the key problems with top down purse? Write a recursive descent parser for the grammar:
S→cAd A→ab|a.
8 M

3 (a) Given the grammar:
S →aABb
A → c|ϵ
B → d|ϵ
i) Compute FIRST and FOLLOW sets
ii) Construct the predictive parsing table
iii) Show the move made by predictive parser on the input: acdb.
10 M
3 (b) Explain with a neat diagram, the model of a table drive predictive parser.
5 M
3 (c) What is handle pruning? Give a botton-up parse for the input: aaa*a++ and grammar: S → SS + |SS * | a.
5 M

4 (a) Given the grammar:
S → CC
C → cC|d
i) Obtain the sets of canonical collection of set of valid LR(0) items
ii) Design SLR parsing table.
10 M
4 (b) Write an algorithm used to compute LR(1) sets of items.
6 M
4 (c) Write a note on the parser Generator - Yacc.
4 M

5 (a) Explain the concept of syntax - directed definition.
5 M
5 (b) The SDD to translate binary integer number into decimal is shown below:

Construct the parse tree and annotated parse tree for the input string: 11001.
5 M
5 (c) Given a SDI for desktop calculator and show its parse stack implementation.
10 M

6 (a) Translate the arithmetic expression: a+ - (b+c) into quadruples, triples and indirect triples.
6 M
6 (b) Give a semantic action for: S → if (B) S1 else S2;
6 M
6 (c) Develop SDD to produce directed a cycle graph for an expression. Show the steps for constructing the directed acyclic graph for the expression: a+a*(b-c)+(b-c)*d
8 M

7 (a) Describe the general structure of an activation record. Explain the purpose of each field in the activation record.
8 M
7 (b) A C code to compute Fibonacci numbers recursively is shown below:
int f(int n)
{ int t, s;
if (n<=2) return 1;
s=f(n-1);
t=f(n-2);
return (s+1);
}
i) Draw the activation tree for the call: f(5)
ii) What is the largest number of activation records that ever appear together on the stack>
6 M
7 (c) Explain the performance metrics to be considered while designing a garbage collector.
6 M

8 (a) Discuss the issues in the design of a code generator.
10 M
8 (b) Write the tree address code and construct the basic blocks for the following program segment.
sum =0;
for (i=0; i<=10; i++)
sum=sum+a[i];
5 M
8 (c) Give the code generation process for operations.
5 M



More question papers from Compiler Design
SPONSORED ADVERTISEMENTS