You are on page 1of 5

GALGOTIAS COLLEGE OF ENGINEERING AND

TECHNOLOGY
1,KnowledgePark-II,GreaterNoida,U.P.
Assignment Sheet-1

Name of the Faculty : Mr. Ravikant Nirala

Subject : Compiler Design Subject Code: KCS-502

Branch : Computer Science & Engg.

This Assignment corresponds to Unit No. I

1. What is a Cross Compiler? How a Boot Strapping of a compiler done to a second machine? Suppose,
you have a Pascal to C translator written in C and a working C compiler. Use T diagram to describe
the steps you would take to create a working Pascal compiler.

2. Differentiate between the following:


(a) Compilers and interpreters
(b) Regular expression and Context free grammar.

3. Discuss the action taken by every phase of the Compiler on the string:-
A=B*C+D/E
4. Describe the Algorithm for subset construction and computation of є-closure.
5. What do mean by Left Factoring and Left Recursion?
6. What are lexical phase errors, syntactic phase errors and semantic phase errors? Explain with
suitable example.
7. What do you mean by ambiguous grammar? Show that the following grammar is ambiguous.
S->aSbS/bSaS/∈
GALGOTIAS COLLEGE OF ENGINEERING AND
TECHNOLOGY
1,KnowledgePark-II,GreaterNoida,U.P.
Assignment Sheet-2

Name of the Faculty : Mr. Ravikant Nirala

Subject : Compiler Design Subject Code: KCS-502

Branch : Computer Science & Engg.

This Assignment corresponds to Unit No. II

1. Construct an LR (0) parsing table for the following grammar:


S→A)
S→A, P\ (P, P P→ {num,
num}

2. Show that the following grammar is LR (1) but not LALR (1).
G: S→Aa\bAc\Bc\bBa
A→d
B→d

3. Define Parser. What are the major tasks for Parser?


4. Whether the given grammar is LL (1) or not?
S→iCtS\iCtSeS\a
C→b

5. Differentiate between LL and LR grammars?


6. Show that “every SLR (1) grammar is unambiguous, but there are many unambiguous grammar that
are not SLR (1)”.
7. State the problems associated with the top down parsing. State and eliminate the problem associated
with following grammar for top down parsing:-
E→E+T\T T→T*F\F
F→ (E)\id
GALGOTIAS COLLEGE OF ENGINEERING AND
TECHNOLOGY
1,KnowledgePark-II,GreaterNoida,U.P.
Assignment Sheet-3

Name of the Faculty : Mr. Ravikant Nirala

Subject : Compiler Design Subject Code: KCS-502

Branch : Computer Science & Engg.

This Assignment corresponds to Unit No. III

1) Translate the following programs into three address code


(a) int i; i=1; while(a<10) do
if x>y then a=x+y
else a=x-y
(b) for (i=1;i<=10;i++) if a<b then x=y+z
(c) while(a<c and b>d) do
if a=1 then c=c+1;
else
while (a<=d) do
a=a+3;
(d) Switch (a+b)
{
Case 2:{x=y; break;}
Case 5:{a=b+3; break;}
Default: {a=2;}
}
break;
Case 9:{x=y-1;break;}
Default:{a=2;}
}
2.) Consider the following grammar for array references. Give syntax directed translation scheme to
generate three address codes for addressing array elements. Translate the statement X=A[i,j].where
lower bounds of i and j are 1 and 1 ,upper bounds are 10 and 20 respectively. Grammar:
S→L:=E
E→E+E\(E)\L
L→Elist,J\id
Elist→Elist,E\id\E
3.) Describe how a for statement can be systematically turned into a corresponding while statement.
Does it make sense to use this to generate code?
4.) Write the syntax directed translations to go along with the LR parser for the following:
L→idList
elist→elist[E]\[E]
E→E+T\T
T→T*F\F
F→id

5) Why are quadruples preferred over triples in an optimizing compiler?


GALGOTIAS COLLEGE OF ENGINEERING AND
TECHNOLOGY
1,KnowledgePark-II,GreaterNoida,U.P.
Assignment Sheet-4

Name of the Faculty : Mr. Ravikant Nirala

Subject : Compiler Design Subject Code: KCS-502

Branch : Computer Science & Engg.

This Assignment corresponds to Unit No. IV


1) Explain Activation Record and display structure. Show the activation records and display
structures just after the procedure called at lines marked x and y have started their execution.
Be sure to indicates which of the two procedure named A you are referring to:
Program Test;
Procedure A;
Procedure B;
Procedure A;
……………….
end A;
begin
Y:A;
end B;
begin
b;
end A;
begin
X=A;
End Test;
2.) Activations of functions within a program are allocated a stack frame. What is the layout of a
typical stack frame on the stack? Identify the kinds of data values which are stored there.

3.) Describe the representation of scope information in the symbol table .Consider the following
program structure and gives its symbol table organization:-
Program main
Var x,y: integer
Procedure P
Variable X,a : Boolean
Procedure Q
Var x,y,z : real

4.) Explain the following Storage Allocation Strategies:


(i) Stack Allocation
(ii) Heap Allocation
GALGOTIAS COLLEGE OF ENGINEERING AND
TECHNOLOGY
1,KnowledgePark-II,GreaterNoida,U.P.
Assignment Sheet-5

Name of the Faculty : Mr. Ravikant Nirala

Subject : Compiler Design Subject Code: KCS-502

Branch : Computer Science & Engg.

This Assignment corresponds to Unit No. V

1) What is DAG? Explain DAG representation. Give the algorithm for construction of DAG.
Also explain how it helps in elimination of common sub expression.

2) Discuss the principal sources of code optimization with the help of suitable examples. What is
the need of code optimization, illustrate.

3) Explain the global data flow analysis. What is its use in code optimization?

4) Explain the loop optimization technique with suitable.

5) What are the problems in code generation?

6) Write an algorithm to partition a sequence of three address statements into basic blocks.

7) Discuss in detail the process of optimization of basic blocks. Give an example

8) How to subdivide a run-time memory into code and data areas. Explain.

9)

You might also like