0% found this document useful (0 votes)
12 views

Question Bank

The document outlines various topics related to compiler design, including phases of a compiler, lexical analysis, parsing techniques, symbol tables, and code generation. It includes specific tasks such as writing LEX programs, constructing parsing tables, and generating intermediate code. Additionally, it discusses error recovery methods and optimization techniques in compiler implementation.

Uploaded by

pranaymagar0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Question Bank

The document outlines various topics related to compiler design, including phases of a compiler, lexical analysis, parsing techniques, symbol tables, and code generation. It includes specific tasks such as writing LEX programs, constructing parsing tables, and generating intermediate code. Additionally, it discusses error recovery methods and optimization techniques in compiler implementation.

Uploaded by

pranaymagar0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT 1

1. What do you mean by phase & pass of a complier? Explain lexical analysis phase of a compiler in
detail.
2. Discuss various phases of compiler in brief for the given expression, a= b * c + d / e
Give output of each phase of compiler including symbol table and memory representation.
3. Draw NFA for the regular expression
a*((aa/bb)*b

4. Define about phase and pass of a complier and discuss role of lexical analyzer in detail.
Discuss the use of Cross Compiler and explain the process of bootstrapping.
5. State names of Compiler Writing tools and state the use of each.
6. Write a LEX program that recognizes :-
i) Keyword if, while, for
ii) Identifier
iii) Operator + | - | * | /

7. Give Cousins of Compiler in detail.


8. What is role of Lexical Analyzer in compiler design.
9. State translator. Give difference between compiler and interpreter.
10. State following terms.
i) Cross compiler.
ii) Bootstrapping.
Also, provide suitable example.
11. Discuss phases of compiler using the given statement
Product = initial + rate * 60
12. Write a Lex program to count number of newlines, tabs, spaces & alphabets.

Unit 2

1. Give short note on-Representation of the scope information in the symbol table.
2. What is an ambiguous and unambiguous grammar.
3. Construct an LL(1) parsing table for the following grammar-
𝑆 → 𝑎𝐵𝐷ℎ
𝐵 → 𝑐𝐶
𝐶 → 𝑏𝐶 | ∈
𝐷 → 𝐸𝐹
𝐸 →𝑔| ∈
𝐹 →𝑓| ∈

4. Discuss working of top down parser and justify the given statement- “The order in which
alternatives are tried affects the language accepted by the parser.”

5. Give implementation of Shift Reduce Parser for the given string id + id * id


𝐸 →𝐸+𝑇|𝑇
𝑇 →𝑇∗𝐹|𝐹
𝐹 → 𝑖𝑑
6. State the various attributes that should be stored in symbol table? Discuss various data structure for
implementation of symbol table.

7. State Handle. Show the handle of each sentential form for the string id + id * id
𝐸 → 𝐸 + 𝐸 | 𝐸 ∗ 𝐸 |𝑖𝑑
8. Check whether a given grammar is LL(1) or not.
𝑆 → 1𝐴𝐵 | ∈
𝐴 → 1𝐴𝐶 | 0𝐶
𝐵 → 0𝑆
𝐶 →1

9. Consider the following grammar-


𝑆 → 𝐶𝐶
𝐶 → 𝑐𝐶
𝐶 →𝑑
Construct SLR(1), CLR(1) parsing table.

9. State the contents of the symbol table for the given procedure-
i. Assuming that only one symbol table is maintained
ii. Assuming that new symbol table is built for each block on stack

Program main
Var x, y: integer
Procedure P:
Var x, a: Boolean
Procedure Q:
Var x, y,z: real
Begin
…..
End
Begin
……
End
Begin
…….
End

10. Generate LALR(1) parsing table for the following grammar:


𝑆 → 𝐴𝑎 |𝑏𝐴𝑐 |𝑑𝑐 | 𝑏𝑑𝑎
𝐴 →𝑑

11. Consider the following grammar-


𝑆 → 𝐴𝑎𝐴𝑏
𝑆 → 𝐵𝑏𝐵𝑎
𝐴 →∈
𝐵 →∈
Construct LR(1),LALR(1) parsing table.

12. Is Left recursive grammar suitable for top down parsing? Eliminate left recursion from given
grammar.
𝑆 → 𝑎𝐵𝐷ℎ
𝐵 → 𝐵𝑏 | 𝑐

UNIT 3

1. State the use of following functions in SDTS,


i) gene code ii) backpatch
iii) Merge iv) Make list
2. Write SDTS & obtain three address code for the following statement.
if (p> q and r <s)
then
=
Else
=/v

Draw annotated parse tree.


3. Write Synthesized attributes and draw annotated parse tree for the given grammar.
𝐸 →𝐸+𝑇
𝐸 →𝑇
𝑇 →𝑇∗𝐹
𝑇 →𝐹
𝐹 → 𝑖𝑑
Evaluate the given arithmetic expression using SDTS 2+3*5
3. Define following terms-
i) Inherited attribute
ii) Synthesized attribute

4. Give SDTS for the following statement A[i,B[k]]=B[i+k]+ A[i,k].Assume array A is of size 20 x 30 and
B is of size 30, and bpw = 04

5. Justify how translations is carried out by using Syntax Directed Definitions.

6. Generate SDTS for the arithmetic Expressions. Also draw annotated parse tree.
7. Generate SDTS for the following statement.
if(p>q and r<=s)
then
u=u*v;
else
u=u/v;
Draw annotated parse tree.

8. State concept of L-attributed definitions. & Write translation scheme for While loop.

9. Give role of semantic analyzer. Discuss translation of constructs using Syntax Directed
Translation.

10. Justify the purpose of syntax tree. Draw Syntax tree for the given grammar for the string
id + id * id

𝐸 →𝐸+𝐸
𝐸 →𝐸∗𝐸
𝐸 → 𝑖𝑑

11. Discuss inherited and synthesized attributes with an example

UNIT-4

1. When error is detected in Top-Down parser? How LL(l) parser recovers from error.
2. Write short note on phrase level error recovery in LR parsing.
3. Consider the following lexically nested C code:
int a,b;
int foo() { int a,c;}
int bar() { int a,d; /* HERE*/}
4. How can symbol tables represent the state of each scope at the point marked HERE? Draw a
diagram.
5. Write short note on Run-Time support as provided by compiler.
6. Discuss different symbol table organization for block structured language.
7. Give error recovery in predictive parsing.
8. Give different types of intermediate codes? Comment following statement into all intermediate
code
a= SQRT(b* b- 4* a *c)/ 2* a

9. Differentiate syntactic & semantic errors ,suggest method to recover from these errors.

10. Generate three address code for given program fragment


while(A>B AND C>D) do
if G < H then
x=y+z
else
x=y–z

11. List out various ways to represent Three Address code.

12. Give different types of intermediate codes? Explain using expression: a*(b+c)/d+e/f

13. Implement phrase Level error recovery routines For LR Parsing by considering given grammar.
E →E+E| EE|(E)| id

UNIT-5

1. Give Data Flow Equations? Compute IN and OUT equations for following graph

2. Give labeling algorithm and determine number of registers required to evaluate following
instructions set
T1= a + b
T2= c + d
T3= e + f
T4= T2 + T3
T5= T4 + T1
3. Compute IN and OUT equations for following graph.
4. How algebraic properties are used to reduce register requirement during code generation.

5. Consider some interlock code optimization without any data flow analysis by treating each
extended n if it is a basic block. Give algorithms to do the following Optimizations within as
extended basic block. In each case, indicate what effect on other extended basic blocks a change
within one extended basic block can have.
1) Common sub- expression elimination
2) Constant folding
3) Copy Propogation

6. Construct the DAG for the following basic block:


d:= b*c
e:=a+b
b:=b*c
a:=e-d

7. Generate the code for following expression using simple code generation algorithm
x = (a + b) −((c+d) −e).

8. Write short note on:


1) Common subexpression elimination
2) Dominator node
3) Loop Jamming
4) Loop Unrolling
5) Reducible flow graph

You might also like