0% found this document useful (0 votes)
88 views10 pages

CD Question Bank

The document contains questions related to compiler design. It covers topics like phases of a compiler, lexical analysis, parsing, syntax analysis, intermediate code generation, code optimization and other compiler construction concepts. Each question has two subparts focusing on different aspects of compiler design.

Uploaded by

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

CD Question Bank

The document contains questions related to compiler design. It covers topics like phases of a compiler, lexical analysis, parsing, syntax analysis, intermediate code generation, code optimization and other compiler construction concepts. Each question has two subparts focusing on different aspects of compiler design.

Uploaded by

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

COMPILER DESIGN QUESTION BANK

1. a) Discuss the phases of a compiler indicating the inputs and outputs of each phase in
translating the statement “a=p+r*36.0”. [7M]
b) Discuss about the role of lexical analyzer. Explain with program. [7M]
2. a) Explain the boot strapping process with suitable examples and diagrams. [7M]
b) Construct an FA equivalent to the regular expression (0+1)*(00+11)(0+1)* [7M]
3. a) Explain various building blocks used to design a language translator. [7M]
b) Differentiate between
i) Phase and a pass ii) single-pass and multi-pass compiler. [7M]
4. a) Explain about input buffering schemes in lexical analysis. [7M]
b) Write a regular expression for identifiers and reserved words. Design the transition
diagrams for them. [7M]
5. a) Explain how lex program will perform the lexical analysis for the [7M]
following patterns in C: Identifiers, comments, numerical constants and arithmetic
operators.
b) Construct NFA equivalent to regular expression r= (a + b)* ab [7M]
(aa+bb) and convert it into DFA.
6. a) Explain various data structures used in lexical analysis. [7M]
b) Write a Regular Expression for identifier, reserved words & relation operators. [7M]
Design a transition diagram for each of them.
7. a ) Write about tokens generated by lexical analyzers. Describe the lexical errors [7M]
and various error recovery strategies with suitable examples.
b) Define Regular Expression. Explain the properties of Regular Expressions. [7M]
Discuss with suitable examples.
8. a) What is LEX? Discuss the usage of LEX in Lexical Analyzer generation. [7M]
b) Construct a Finite Automata and Scanning algorithm for recognizing [7M]
identifiers, numerical constants in C language.
9. a) Describe the need and functionality of linkers, assemblers and loaders. [7M]
b) State the steps to convert a regular expression to NFA. Explain with an [7M]
example.
10. a) How to generate object code for X=Y+Z*15 through different [10M]
phases of compiler?
b) Construct a Finite Automaton for the Regular Expression [4M]
(00+11)*010*10.
11. a) Define lexeme, token and pattern. Identify the lexemes that [7M]
make up the tokens in the following program segment. Indicate
corresponding token and pattern. void swap(inti, int j) { int t;
t=i; i=j; j=t; }
b) Write regular expressions for the following languages: Explain [7M]
operations on Regular expressions.
i) All strings over the English alphabet that contain the five
vowels in order.
ii) All strings of a’s and b’s that do not contain the subsequence
abb.
12. a) How to generate object code for X=Y+Z*15 through different [10M]
phases of compiler?
b) Construct a Finite Automaton for the Regular Expression [4M]
(00+11)*010*10.
UNIT-2

1. a) Define Context Free Grammar. Explain how it is suitable for parsing? Explain [7M]

the recursive descent parser with example.

b) Design a non-recursive predictive parser for the following grammar: [7M]

S → AaAb | BbBb

A→e

B→e where a, b, e are terminals.

2. a) Given the following grammar: E -> E + E | E - E | E * E | E / E | - E | int Show [7M]

two different left-most derivations with the help of parse trees for the string

int + int * int / int. What does this tell you?

b) Explain left recursion and left factoring with examples. [7M]

3. a) What are the preprocessing steps required for constructing Predictive parsing [7M]

table. Explain with example.

b) Define a Parser. What is the role of grammars in Parser construction? Construct

the Predictive parsing table for the grammar G: E → E+T |T, E →T*F |F, F →

(E) |id. [7M]

4. a) What is an LL(1) grammar? Can you convert every context free grammar into [7M]

LL(1). How to check the grammar is LL(1) or not? Explain the rules,

b) Consider the following grammar

E → T + E|T

T→V*T|V

V → id
Write down the procedures for the non-terminals of the grammar to make a

recursive descent parser. [7M]

5. a) Compute FIRST and FOLLOW for the grammar: [7M]

S → S S + \ S S * \ a.

b) Write about various types of top down parsing. Discuss about the error recover

in predictive parsing. [7M]

6. a) Give an algorithm to eliminate productions containing useless symbols and [7M]

ambiguous productions from a grammar.

b) Construct predictive parse table for the following grammar. [7M]

E → E + T/T

T → T *F/F

F → F /a/b

7. a) Verify whether the following grammar is LL(1) or not? [7M]

E→E+T|T

T → T* F / F

F → (F) |a|b.

b) Construct recursive descent parser for the given grammer. [7M]

bexpr bexpr OR bterm | bterm

bterm bterm AND bfactor | bfactor

bfactor  NOT bfactor | (bexpr) | TRUE | FALSE

8. a) Explain the rules to perform preprocessing steps of top down [7M]

parser. Explain with given grammar G. S Aa| bAc| Bc| bBa

A  d B d.

b) Discuss about error recovery strategies in predictive parsing. [7M]


9. a) Given the following grammar: E -> E + E | E - E | E * E | E / E | - E | int Show [7M]

two different left-most derivations with the help of parse trees for the string

int + int * int / int. What does this tell you?

b) Explain left recursion and left factoring with examples.

10. a) What are the preprocessing steps required for constructing Predictive parsing [7M]

table. Explain with example.

b) Define a Parser. What is the role of grammars in Parser construction? Construct

the Predictive parsing table for the grammar G: E → E+T |T, E →T*F |F, F →

(E) |id. [7M]

UNIT-3
1. a) Explain the structure of the LR Parsers and Difference between LR and LL [7M]

Parsers.

b) What is an LR(0) item? Construct an SLR parsing table for the grammar G: [7M]

S→ L=R |R, L → *R | id, R → L. Is it SLR(1) grammar?

2. a) What are different intermediate code forms? Discuss different Three Address [7M]

code types and implementations of Three Address statements.

b) Write a note on simple type checker and list the different types of type [7M]

checking.

3. a) List and explain different types of LR Parsers. Differentiate LR(0) and LR(1) [7M]

items and their associated parsers.

b) Construct Canonical LR parsing table for the following grammar. S→L=R | R [7M]

L→*R | id

R→L
4. a) Define LR(k) parser. Explain the model of LR parser and various functions [7M]

used in it for parser construction.

b) How to handle ambiguity through LR parsers? Discuss about the Dangling –

Else ambiguity. [7M]

5. a) Give syntax directed translation scheme for simple desk circulator. [7M]

b) Show that the following grammar: [7M]

S → Aa|bAc|Bc|bBa

A→d

B→d

Is LR(1) but not LALR(1).

6. a) Write the rules used to construct SLR Parser. Give example. [7M]

b) Generate the three address code for the following code fragment. [7M]

a=b+1 x=y+3 y=a/b a=b+c

7. a) What is an LALR(1) grammar?. Construct LALR parsing table for the [7M]

following grammar: S→ CC, C → cC , C → c|d .

b) Write and explain the LR Parsing algorithm..

8. a) Write the quadruple, triple, indirect triple for the expression - [7M]

(a*b) + (c+d)-(a+b+c+d).

b) For the grammar below: E → E + T | T, T → num .num | num [7M]

Give an SDD to determine the type of each term T and

expression E.

9. a) Differentiate inherited and synthesized attributes with an [7M]

example.

b) Write Syntax directed definition for constructing syntax tree of [7M]


an expression derived from the grammar E  E + T | E – T | T

T (E) | id | num.

10. a) Discuss the evolution order of SDTs. Also write its applications [7M]

b) Write the SDD for a simple type declaration and draw the [7M]

annotated parse tree for the declaration float a, b, c.

UNIT -4
1. a) What are the principles associated with designing calling sequences and the

layout of activation records? [7M]

b) What is the role of code Optimizer in compiler? Is it a mandatory phase?

Explain the various sources of optimization.

2. a) Explain how data flow equations are set up and solved for improving code. [7M]

b) Discuss basic blocks and flow graphs with an example. [7M]

3. a) Give the general structure of an activation record? Explain the purpose of [7M]

each component involved in it.

b) Explain various machine independent code optimization techniques. [7M]

4. a) Write a short note on peephole optimization and various operations used in it. [7M]

b) Describe Loop unrolling? Describe its advantage with your own examples. [7M]

5. a) Explain static and stack storage allocations? [7M]

b) Translate the arithmetic expression a[i]=b*c-b*d into a syntax tree, quadruples [7M]

and triples.

6. a) Write pseudocode for finding sum of ‘n’ numbers. And identify basic blocks [7M]

then construct the flow graph for it. Explain the rules used for this.

b) Explain the following peephole optimization techniques; [7M]

i) Elimination of Redundant Code

ii) Elimination of Unreachable Code


7. a) Discuss in detail the role of dead code elimination and strength [7M]

reduction during code optimization of a compiler

b) Draw and explain the Runtime memory organization static [7M]

storage allocation strategy with pros and cons.

8. a) What is a leader of basic block? Write and explain the algorithm [7M]

used to find leaders. Draw flow graph for matrix multiplication.

b) Explain in detail about global common sub expression [7M]

elimination technique.

9. a) What is a Flow Graph? Explain how a given program can be [7M]

converted in to a Flow graph?

b) With an example explain the following loop optimization [7M]

techniques: (i) Code motion (ii) Induction variable elimination

and (iii) strength reduction.

10. a) What is code optimization? Explain about various levels and [7M]

types of optimizations.

b) What is meant by activation of procedure? How it can be [7M]

represented with activation tree and record? Explain with

quick sort example.

UNIT -5
1. a) Explain various storage allocation strategies with its merits and demerits. [7M]

b) Define activation records. Explain how it is related with runtime storage

allocation.

2. a) What is runtime stack? Explain the storage allocation strategies used for [7M]

recursive procedure calls.

b) What is a flow graph? Explain how flow graph can be constructed for a given
program.

Main()

{ int sum, n, i;

sum=0;

for i:=1 to n do

sum:=sum+i;

write(sum);

} [7M]

3. a) Give an example to show how DAG is used for register allocation. [7M]

b) Generate code for the following C statements: [7M]

i) x=f(a)+f(a) ii) y=x/5;

4. a) Generate code for the following C program using any code generation [7M]

algorithm.

main()

int I;

int a[10];

while(i<=10)

a[i]=0;

b) Explain the main issues in code generation. How to handle them? Discuss. [7M]

5. a) Discuss about register allocation and assignment in target code generation. [7M]

b) Discuss how induction variables can be detected and eliminated from the given

intermediate code

B2: i:= i+1


t1:=4*j

t2:=a[t1]

if t2<10 goto B2 [7M]

6. Explain the code generation algorithm in detail with an example. [14M]

7. a) Discuss basic blocks and flow graphs with an example [7M]

b) Generate code for the following: [7M]

i) x=f(a)+f(a)+f(a) ii) x=f(f(a)) iii) x=++f(a) iv) x=f(a)/g(b,c)

8. a) Explain the main issues in code generation. [7M]

b) Explain the following terms: [7M]

i) Register Descriptor ii) Address Descriptor iii) Instruction Costs

9. a) Give an example to show how DAG is used for register allocation. [7M]

b) Generate code for the following C program using any code generation [7M]

algorithm.

main()

int I;

int a[10];

while(i<=10)

a[i]=0;

10. a) Explain various issues that affect the efficiency of generated [7M]

code.

b) What are the different object code forms in code generation and [7M]

explain.

You might also like