Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
177 views7 pages

Theory QBank

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 7

SINHGAD TECHNICAL EDUCATION SOCIETY’S

SINHGAD INSTITUTE OF TECHNOLOGY, LONAVALA

Theory Question Bank


Academic Year 2016-17
Class: BE Computer (A & B)
Subject: Principles of Modern Compiler Design

UNIT-I Notion and Concepts


1. Write a Lex specification to read a C program and calculate number of new line
characters, words, characters, tabs and white spaces in the program.
2. Why compilation phases are divided into front-end and back-end? What are the
advantages?
3. Write regular expression for the following languages:
i. All words with 'b' as the second letter.
ii. All strings of digits that represents even numbers.
iii. All strings of digits that contain no leading zeros.
4. What is difference between an interpreter and a compiler?
5. Explain phases of compilation with example. Show input and output for each phase for
given example.
Position = initial + rate * 60
6. Whether lexical analysis detects any errors? Explain with example
7. Explain the following:
i) token ii) pattern iii) lexeme
8. What are the types of compiler?
9. Explain with example various compiler construction tools.
10. What is difference between a phase and a pass of a compiler? Explain machine
dependent and machine independent phases of compiler.
11. Explain with suitable example regular expressions, the meaning of following special
symbols in LEX that are used to specify tokens. Write the pattern that is identified by
your regular expreesions.
‘/’, ‘\’, ‘{‘, ‘?’, ‘.’, ‘[ ]’, ‘^’, ‘$’.
12. What is the difference between an interpreter and a compiler?

13. Explain the following:


i. Cross Compiler ii. Bootstrap Compiler
iii. Incremental Compiler iv. Compiler- Compiler
14. Explain following storage allocation schemes with proper examples.
i. Stack Storage Allocation
ii. Static Storage Allocation
iii. Heap Storage Allocation
15. Discuss the action taken by every phase of compiler on following string:
A=B*C+D/E
16. Explain how various phases of compiler interact with symbol table.

1
SINHGAD TECHNICAL EDUCATION SOCIETY’S

SINHGAD INSTITUTE OF TECHNOLOGY, LONAVALA

17. What are different data structures used for symbol table? Explain.

UNIT- II Parsing
1. Explain Recursive Descent parser with an example.
2. What is Shift-Reduce and Reduce-Reduce conflict? How these can be resolved?
3. Test whether the following grammar is LL(1) or not? Construct LL(1) parser table.
S-> AB | gDa
A-> ab | c
B-> dC
C-> gC | g
D-> fD | g
4. Explain in brief the function of an operator precedence parser.
5. Discuss the problems in top-down parsing. With suitable examples, explain how they can
be overcome?

6. Construct LL(1) parser table for the following grammar.


S -> iCtS | iCtSeS | a
C -> b
Is the grammar LL(1)?
7. Write a YACC program for a simple calculator.
8. Show that following grammar is LL(1) but not SLR(1)
S-> AaAb | BbBa
A-> E
B-> E
9. Construct SLR parsing table for the grammar
S-> AB | gDa
A-> ab | c
B-> dC
C-> gC | g
D-> fD | g
10. Construct a LALR (1) parser table for the following CFG.
D -> L:T
L -> L, id| id
T -> int | real
Symbols D, L and T are non-terminals, and symbols, ‘:’, ‘,’, ‘id’, ‘real’, and ‘int’ are
terminals.
11. What is the need of semantic analysis? Explain the position of type checker with
diagram.

12. Differentiate between top down parser and bottom up parser.

13. For following grammar


S-> AaBb
A-> E
B-> E
i. Compute first and follow sets
ii. Construct LL(1) parser

2
SINHGAD TECHNICAL EDUCATION SOCIETY’S

SINHGAD INSTITUTE OF TECHNOLOGY, LONAVALA

iii. Parse string “ab” with above paraser.

UNIT- III Syntax Translation Schemes

1. Differentiate between synthesized translation & inherited translation.


2. Write syntax directed translation scheme to generate three-address code for function call
and return statements in C. For the following statement in a C program, write the three-
address code that will be generated by your scheme.
X = fun(y+2*3, 0)-1
Assume that x and y are integer variables and function ‘fun’ returns an integer value.
3. Explain the following terms with suitable examples:
i. Inherited attributes ii. Synthesized attributes
iii. Marker non terminal symbols
4. Translate following assignment statement into intermediate code
A [i][j] = B [i][j] + C [i][j] * 10

5. Explain the technique of “Back Patching” for translation of flow of control statement: if-
then, if-then-else and while do.

6. Write a syntax-directed definitions to translate ‘switch’ statement. With a suitable


example, show the translation of the source language ‘switch’ statement.
7. Write quadruple, triple, indirect triple & syntax tree representation for following
expression.
1. A=B+C*D/E+-F*-G
2. A*-(B+C)

8. 1. Generate a three address code for the following program:


i) switch(a+b)
{
case 1 : x=x+1;
case 2: y=y+2;
case 3: z=z+3;
default: c=c-1;
}
ii) while(A<C and B>D) do
if((A==3) then C=C+1
else
while(A<=D) do
A=A+3
9. Write Three Address Code for given if statements:
if(v1<v2) {v3=10; }
else if(v1>v2) {while(v1>v3){v3--;}
else if(v1==v2) { v3=30; }
v4[v1]=89;

3
SINHGAD TECHNICAL EDUCATION SOCIETY’S

SINHGAD INSTITUTE OF TECHNOLOGY, LONAVALA

10. What are synthesized and inherited attributes? What are Marker Non-terminal symbols?
Give example.
11. Write syntax directed translation scheme to generate three-address code for function call
and return statements in C. For the following statement in a C program, write the three-
address code that will be generated by your scheme.
X = fun(y+2*3, 0)-1
Assume that x and y are integer variables and function ‘fun’ returns an integer value.

12. Generate three address code for the following program fragment, where a and b are
integer arrays of sizes 25*40 each, and there are four bytes per word. Variables add, i
and j are integers and are defined.

main()
{
add=0;i=j=1;
do
{
add=add+a[i][j]*b[j][i];
i=i+1;
j=j+1;
}
while(i<=25 && j<=40);
}

UNIT- IV Code Generation and Optimization

1. Explain peephole optimization with suitable example.

2. What is a DAG? Using suitable example discuss its application in code generation phase.

3. Describe any code generation algorithm you know with suitable illustration.

4. 1. Consider the following program


main ( )
{
for (j=2;j<=n;j++)
a[j]=1;
count = 0;
for (j=2;j<=n**0.5;j++)
if(a[j])
{
count++;
for(k=2*j;j<=n;k=k+j)
a[k]=0;
4
SINHGAD TECHNICAL EDUCATION SOCIETY’S

SINHGAD INSTITUTE OF TECHNOLOGY, LONAVALA

}
Printf(“%d”,count);
}
i) Translate the program into three address code statements.
ii) Generate target machine code
iii) Construct the flow graph
iv) For the flow graph, indicate the back edges and their natural loops
Move invariant computations out of the loops

5. What is the need of code optimization? Discuss principal sources of code optimization.

6. 1. Consider the following basic block. Draw the DAG representation of the block
and identify local common sub expressions. Eliminate the common expressions
and rewrite the basic block. Assume that none of the temp variables (S1, S2, …..,
S9) are needed outside the block. The basic block statements are

L10: S1=4*I

S2= addr(A)-4
S3= S2[S1]

S4=4*I

S5=addr(B)-4

S6=S5[S4]

S7= S3*S6
S8=PROD+S7

S9=I+1

I=S9

If I<=20 GOTO L10


7. 1. Consider the following three-address code. Draw its DAG representation. Show
the DAG after labeling using the labeling algorithm.
t1 = a + b
t2 = c + d
t3 = e - t2
t4 = t1 - t3
8. Generate the target code using labeled tree. Assume target machine has two registers r1
and r2. Generate the target code assuming only one register ‘r’ is available in the target
machine.
9. Explain following fundamental data flow properties:
5
SINHGAD TECHNICAL EDUCATION SOCIETY’S

SINHGAD INSTITUTE OF TECHNOLOGY, LONAVALA

i. Available expression
ii. Reaching definitions
iii. Live variables

Support your answer with proper example flow graphs wherever necessary.
10. What is “next use” information? Explain its use in code generation.
11. Explain how loopsin flow graph are identified?
12. Discuss Register allocation and assignment with respect to code generation.
13. Explain in brief following techniques.

i. Constant folding
ii. Loop unrolling
iii. Strength reduction

iv. Common sub expression elimination


UNIT- V Functional and Logic Programs

1. Explain identification with respect to context handling.

2. Write a short note on forward declaration.

3. Explain how overloading can be handled.

4. Write a note on type table.

5. Write a note on importance of source language data representation.

6. Write a note on iterator routine and co-routine.

7. Write a note on activation record with respect to routines.

8. Explain the structure of a functional compiler.

9. What is meant by desugaring? Why is this required?

10. Compare Register oriented and Stack oriented architectures.

11. Explain the structure of .jj file with one example.

UNIT- VI Parallel and Distributed Compilers

1. Write short note on nVidia CUDA compiler.

2. Write short note on data parallelism.

3. How tuple space can be implemented on distributed memory systems.

4. Explain the two machine models use by parallel and distrusted programs.

5. How cross compilation is achieved using XMLVM tool?

6. Explain the processes perform by JVM.


6
SINHGAD TECHNICAL EDUCATION SOCIETY’S

SINHGAD INSTITUTE OF TECHNOLOGY, LONAVALA

7. What are issues compilers should implement for automatic parallelization?

8. How shared variables and monitors provide support for parallelism?


9. Explain the message passing model.

10. What are the key implementation issues should consider by compiler for parallel object
oriented languages?

11. Write short note on data parallelism.

12. How the parallel programming models implementation depend on implementation of


processes and threads?

13. What are issues runtime systems should take care for message passing implementation?

14. Explain marshalling and unmarshalling of messages.

15. Write short note on cmake and nmake.

16. What does a JIT compiler do opposed to a non-JIT compiler. Explain along with
example.

You might also like