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

CD250 Questions

Uploaded by

Uday Kiran
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)
10 views

CD250 Questions

Uploaded by

Uday Kiran
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/ 23

QUESTION BANK (Unit-wise)

UNIT-I:

Overview of Compilation: Phases of Compilation – Lexical Analysis, Regular


Grammar and regular expression for common programming language
features, pass and phases of translation, interpretation, bootstrapping, data
structures in compilation – LEX/ lexical analyzer generator.

1. Explain the input buffer scheme for scanning the source program. How the use of
sentinels can improve its performance? Describe in detail. (Apr 14)

2. a) Consider the following fragment of C code: (Apr 13)


float i, j;
i = i * 70 + j + 2;
Write the output at all phases of the compiler for the above `C' code.
b) Write short notes on: input buffering.

3. a) Describe the steps involved for creating a lexical analyzer with Lex. (Apr 12)
b) Explain the boot strapping process. What is the advantage of using this process?

4. Describe various phases of a compiler? Differentiate a phase and pass? Compare


multipass and singlepass compiler? (May 11)

5. Explain with one example how LEX program perform lexical analysis for the
following patterns in `C': identifier, comments, numerical constants, arithmetic
operators. (May 10)

6. a) Construct an NFA for regular expression R= (aa |b)*ab convert it into an equivalent
DFA(May 10)
b) Write a LEX program for identifying the keywords and identifiers from the file?

7. a) Explain the different phases of a compiler, showing the output of each phase, using
the example of the following statement: position : = initial + rate * 60.
(May 09)
b) Compare compiler and interpreter with suitable diagrams.

8. a) Write a short notes on token specification. (May 09)


b) Draw a NFA for a * | b *.

9. a) Construct a DFA for (a * + b *) abb. (May 09)


b) Write a lex program to identify comments in the program.

10.a) What is LEX? Explain, in detail, different sections of LEX program. (May 09)
b) Write regular expressions for the following patterns. Use auxiliary definitions
wherever
convenient.
i.The set of words having a,e,i,o,u appearing in that order, although not
necessarily consecutively.
ii. Comments in C.

11. Compare compiler and interpreter with suitable diagrams. . (Apr 08)

12. Explain the different phases of a compiler, showing the output of each phase, using the
example of the following statement: (Apr 08)
position : = initial + rate * 60 .

13. Consider the following fragment of ‘C’ code: (Apr 08)


float i,j;
i =i *70 +j +2;
Write the output at all phases of the compiler for the above ‘C’ code. .

14. Write short notes on: input buffering . (Apr 08)

15. a) Explain, in detail, lexical alyzer generator. (Apr 08)


b) Describe the lexical errors and various error recovery strategies with suitable
examples

16. Explain the input buffer scheme for scanning the source program. How the use of
sentinels can improve its performance? Describe in detail. (Apr 2008)

17. Construct minimum state DFA s for the following regular expressions (Feb
07)
i. (a+b)*a(a+b) ii. (a+b)*a(a+b)(a+b) iii. (a/b)*a(a/b)(a/b)(a/b) .

18. Write a procedure for constructing a deterministic finite automata from a non-
deterministic Automata, explain with one example . (Feb 07)

19. a) Write a procedure that combines two NFAs into a single NFA. The operations to be
performed are those of concatetion, union and closure. (Feb 07)
b) Write a procedure that detects all extraneous states in a DFA. .

20. Write regular expressions and NFA for the following patterns. Use auxiliary
definitions where convenient. (Mar 06)
i. The set of words having a,e,i,o,u appearing in that order , although not necessarily
consecutively.
ii. Comments as in C. .

21. Construct minimum state DFAs for the following regular expressions (Apr 05)
i. (a/b)* a (a/b) ii. (a/b)* a (a/b) (a/b) iii. (a/b)* a (a/b)(a/b)(a/b). .
22. Describe the languages denoted by the following regular expressions .(Apr 05)
i. (0/1) * 0(0/1) (0/1) ii. 0*10*10*10* iii. (00/11)_ ((01/10)(00/11)_ (01/10)
(00/11)_ )_

23. a)What is the string generated by the grammar A → (A)A (Apr 11)
b) Explain the basic method of LL(1) parsing and hence explain how very simple
grammar generates strings of balanced parentheses.

24. a) Explain the reasons for separating lexical analysis phase from syntax analysis.
(Apr 11)
b) Eliminate ambiguities from the following grammar.
S--> iEtSeS|iEtS|a
E--> b|c|d:

25. a) Consider the grammar given below. (Apr 11)


E → E + E|E – E| E*E|E/E|a|b
Obtain left most and right most derivation for the string a+b * a+b.
b) Explain back tracking with example.

26 Explain with one example how LEX program perform lexical analysis for the
following patterns in `C': identifier, comments, numerical constants, arithmetic
operators. (Apr 11)

27 a) Construct predictive parse table for the following grammar. (Apr 11)
E → E + T|T
T → T F|F
F → F|a|b
b) What are the limitations of recursive descent parser?

28 a) Construct predictive parse table for the following grammar. (May 10)
E → E + T|T
T → T F|F
F → F |a|b
b) What are the limitations of recursive descent parser?

29 What do you mean by left most derivation? Explain with an example. (May 10)

30 a) What is the string generated by the grammar A → (A)A. (May 10)


b) Explain the basic method of LL(1) parsing and hence explain how very simple
grammar generates strings of balanced parentheses.
31. What is an ambiguous grammar?
With an example illustrate how we can not uniquely parse a given sentence for an
ambigious grammar. (May 10)

32. a) What are the difficulties in top down parsing? Explain in detail. (May 09)
b) Consider the following grammar
S ! (L) |a
L ! L, S |S

33. Construct leftmost derivations and parse trees for the following sentences: (May
09)
i. (a,(a,a))
ii. (a,((a,a),(a,a)))

34. a) Construct predictive parse table for the following grammar. (May 09)
E ! E + T| T
T ! T _ F| F
F ! F _ |a |b
b) What are the limitations of recursive descent parser?

35. a) What is recursive descent parser? Construct recursive descent parser for the
following grammar.
E ! E + T|T (May 09)
T ! TF|F
F ! F_|a|b
b) What is ambiguous grammar? Eliminate ambiguities for the grammar:
E ! E + E|E_E|(E)|id. [8+8]

36. a) Consider the grammar given below. (May 09)


E ! E+E | E-E | E*E | E/E | a | b
Obtain left most and right most derivation for the string a+b * a+b.
b) Explain back tracking with example.

37. What is ambiguous grammar? Eliminate ambiguities for the grammar: (Apr 08)
E ! E+E|E* E|(E)|id.

38. a) What is recursive descent parser? Construct recursive descent parser for the
Following grammar.
E ! E+T|T . (Apr 08)
T ! TF|F
F ! F* |a|b
b) Consider the following grammar .
E ! T+E|T
T ! V*T|V
V ! id
Write down the procedures for the nontermils of the grammar to make a recursive
descent parser.

39. Construct predictive parsing table for the following grammar. . (Apr 08)
E ! TE'
E' ! +TE'|e
T ! FT' [16]
T' ! *FT' |e
F ! (E)|id

40. a) Consider the following grammar . (Apr 08)


S ! 0A|1B|0|1
A ! 0S|1B|1
B ! 0A|1S
b) Construct leftmost derivations and parse trees for the following sentences
0101
1100101
20. a) Define LL(1) grammar. . (Feb 07)
b) Construct LL(1) parse table for the following grammar
bexpr ! bexpr or bterm/bterm
bterm ! bterm and bfactor|bfactor
bfactor ! notfactor|(blxpr)|true|false
Whereor,and,not,(,),true,falsearetermilsinthegrammar.

41. Convert the following grammar into LL(1) grammar (Mar 06)
R ! R“|'R|RR|R _ |(R)|a|b

42. Elimite ambiguities from the following grammar (Mar 06)


S ! iEtSeS|iEtS|a E ! b|c|d

43. What are the limitations of recursion descent parser? (Apr 05)

44. Construct predictive parse table for the following grammar. (Apr 05)
E ! E + T|T
T ! TF|F
F ! F _ |A|B

45. What is an LL(1) grammar. Can you convert every context free grammar into LL(1).

46. The grammar S ! aSa|aa generates all even length strings of a’s except for the empty
string-show that the prete free method of top down parsing succeeds of 2,4 and 8a’s
but fails on 6a’s. Also find out what are the even strings that are passed by the
technique.
. (Apr 05)
47 . Write a Lex program that copies a file, replacing each nonnull sequence of white
space by a single blank.
48. Write a Lex specification for the tokens of Pascal and use the Lex compiler jto
construct a lexical analyzer for Pascal
49. Construct a tool that produces a lexical analyzer from a regular expression
description of a set of tokens
50. What is a problem with 1-pass compiler. Explain its advantages and
disadvantages.
UNIT-II :

Top down Parsing: Context-free grammars, Top down parsing –


Backtracking, LL(1), Recursive Descent Parsing, Predictive parsing,
preprocessing steps required for predictive parsing. Bottom up Parsing: Shift
Reduce parsing, LR and LALR parsing, Error recovery in parsing, handling
ambiguous grammar, YACC – automatic parser/ generator.

1. a) Explain LALR parsing, justify how it is efficient over SLR parsing. (Apr 14)
b) What is phrase level error recovery?

2. a) Construct SLR parsing table for the following grammar. (Apr 13)
S --> AS|b
A --> SA|a
b) What are the actions of shift reduce parse.

3. Explain shift-reduce parsing with stack implementation. (Apr 12)

4. a) What is yaac? (Apr 11)


b) Explain error recovery in yaac?
c) Explain yacc grammar rules?

5. a) What are the actions of shift-reduce parsers? (May 10)


b) Construct SLR parsing table for the following grammer.
S→ AS | b
A → SA | a

6. a) Construct LALR parsing table for the following grammar (May 10)
S - > CC
C - > cC|d

7. Give the algorithm to generate the canonical collection of LR(0) items. (May 10)

8. a) What is an SLR Grammar? (May 10)


b) Construct LALR(1) Parse table from the following grammar
S - > Aa|bAc|dc|bda..
9. Construct SLR parsing table for the following grammar. (Apr 09)
S ! AS|b
A ! SA|a

10. Construct LALR parsing table for the following grammar (Apr 09)
S ! CC
C ! cC|d

11. a) What are the common conflicts that can be encountered in shift – reduce parser.
(Apr 09)
(b) Construct SLR parsing table for the following grammar.
R ! R ′|′ R |RR |R∗ |(R) |a |b

12. a) Explain canonical LR parsing. (Apr 09)


b) Explain briefly, precedence functions. Construct the precedence graph using the
following precedence table.
+ * ( ) id $
f230440
g135050

13. a) What is an operator grammar? Give an example. (Apr 08)


b) Write an operator precedence parsing algorithm.

14. a) Define LR(k) parser. Draw and explain model of LR parser. (Apr 08)
b) Write LR parsing algorithm.

15. Construct SLR parsing table for the following grammar. (Apr 08)
A ! SA|a

16. a) What is an LR(0) grammar. (Feb 07)


b) Construct SLR passing table for the following grammar
R ! R‘1'R|RR|R |(R)|a|b

17. What is LR(1) parsing? (Feb 07)

18. Construct SLR parse table for the following grammar. (Mar 06)
S ! Aa|bAc|dc|bda
A!d

19. Distinguish SLR, LALR grammar. (Mar 06)

20. Construct LALR parse table for the following grammar. (Apr 05)
S ! Aa|bAc|Bc|bBa
A!d
B ! d.

21. Construct SLR passing table for the following grammar. (Apr 05)
E ! E + T/T
T ! TF/F
F ! F_|a|b.

22. Distinguish top down and bottom up parsing. (Apr 05)


23. Construct operator precedence parser for the following grammar for reference
expressions. (Apr 05)
R ! R‘10R|RR|R_|(R)|a|b.

24. a) What is an LR(0) grammar. (Apr 05)


b) Construct SLR passing table for the following grammar
R ! R‘10R|RR|R _ |(R)|a|b

25. LL(1) language is defined as the language for which there exist some LL(1) grammar
generating the language. Consider the following statement:
“There exist an algorithm to determine whether the given grammar is LL(1), but
there exist no algorithm to determine whether a given language is LL(1)”.
Comment on the truth/falsehood of the above statement.
26. Is the following language LL(1)?
{ancbn | n1}
27. Show that a grammar with no  production in which each alternative begins with
a distinct terminal is always LL(1).
28. Show that no left recursive grammar is LL(1)

29 What is ambiguous grammar; test whether following grammar is ambiguous.


L->L; L|S
S->a
30 Explain the methods to remove ambiguity?
31 What is Non recursive predictive parser, Explain the difference between
predictive & Non- predictive parser?
B4 What is FIRST & FOLLOW, What r the preprocessing steps required for
predictive parsing FIRST and FOLLOW ?

32 The grammar S ! aSa|aa generates all even length strings of a’s except for the
empty string-show that the prete free method of top down parsing succeeds of 2,4
and 8a’s but fails on 6a’s. Also find out what are the even strings that are passed
by the technique.
33 What is ambiguous grammar? Explain the process of elimiting ambiguities from
a grammar with a suitable example.
34 What is recursive descent parser. Write recursive descent Parser for the following
grammar?
E →TE' .
E' → TE' /t
T → FT '
T '→ *FT ' /t
F → (E)/id
35 (a) Define LL(1) grammar.
(b) Construct LL(1) parse table for the following grammar
. bexpr ! bexpr or bterm/bterm
bterm ! bterm and bfactor|bfactor
bfactor ! notfactor|(blxpr)|true|false
Whereor,and,not,(,),true,falsearetermilsinthegrammar.
36. Show that no LR(1) grammar can be ambiguous
37. Show that SAa | bAc | Bc | bBa,
Ad, Bd is LR(1) but not LALR(1).
38. Write a YACC desk calculator program that will evaluate Boolean expressions.
39. Show that every LL(1) grammar is LR(1) grammar.

40 what is operator precedence parsing, construct a operator precedence parser for


the following grammar
E->EAE/(E)/-E/id
A->+/-/*/
41 Explain about the LR parser briefly & also explain the algorithm also?
42 Design SLR(1) parser for the following grammar
S->aAb|bB
A->Aa| є
B->Bb| є
43 What is the difference between SLR, CLR, and LALR parser; explain advantages
& disadvantages For each of them?

44 Construct operator precedence parser for the following grammar for reference
expressions.
R ! R‘10R|RR|R_|(R)|a|b. .
45 What is LR(1) parsing.
46 Distinguish top down and bottom up parsing.
47 Construct SLR passing table for the following grammar. . .
E  E + T/T
T T*F/F
F  F_|a|b.

48 .Find the SLR parsing table for the given Grammer :


E->E+E| E*E | (E) | id
And parse the sentence (a+b)*c.
OR
49.Construct an LALR Parsing table for the following grammer:
E->E+T|T
T->T*F|F
F->id

50. Write the Differences Between top down and bottom up parsing.

UNIT-III :

Semantic Analysis: Intermediate forms of source programs – abstract syntax


tree, polish notation and three address codes. Attributed Grammars, Syntax
Directed Translation, Conversion of popular programming languages
constructs into Intermediate code forms, Type checker. Symbol Tables:
Symbol table format, organization for block structures languages, hashing,
tree structures representation of scope information
1. a) Let A be a 10 * 20 array with low1 = low2 = 1. Therefore n1=10 and n2=20. Take
w to be 4. Give the annotated parse tree for the assignment x : = A [ y, z ].(Apr 14)
b) Give the semantic rules for declarations in a procedure?

2. a) Give a, c are 2 dimensional real arrays and b is a 2 dimensional integer array and i,
j are integer variables, write the 3-address code for the following program fragment
(Apr 13)
for (i = 0; j = 0; i < 10ANDj < 10; i + +; j + +)
f
C[i][j]=a[i][j]+b[i][j];
}

3. a) Explain SDD for Boolean expressions with and without back patching. (Apr 12)
b) Write the SDD for “Do - While" statement and explain?

4. a) Differentiate between L-attributed and S-attributed grammars. (Apr 11)


b) Define S-attributed and L-attributed definition.

5. a) Write a regular expressions and NFA for the following patterns. Use auxiliary
definitions where convenient? (May 10)
i. The set of words having a, e, i, o, u appearing in that order, although not having
necessarily consecutively.
ii.Comments in C.
b) Differentiate Interpreter and Compiler?

6. a) Write the quadruples, triples and indirect triples for the expression (May 10)
i. (a + b) * (c + d) *(a + b + c)
ii. a * (b + c)
b) Write a top-down translation scheme to produce quadruples for Boolean
Expression.

7. a) Why are quadruples preferred over triples in an optimizing compiler. Explain. (May
10)
b) Give the triple representation of an array operation x : = y [ i ]
c) Give the syntax directed definition of if else statement.

8. a) Translate the following code segment into quadruples. (May 10)


While A < C and B < D
if A=1 then C: = C+1
else while A<= D do A: = A+2
b) Explain the different statements allowed in TAC with examples.

9. a) Write the three-address code for the following code. (May 10)
fact(x)
{ int f=1;
for (i=2, i >=x, i++)
{
f=f*i;
return f;
}
b) Write an algorithm for identifying leaders and partition the code into basic blocks
and apply it on the above derived three-address code.

10. a) What is back patching? (May 10)


b) Explain back patching with reference to the three address code generated for the
expression p > q and q < t.

12. a) What is a syntax tree? Write syntax directed definition for constructing a syntax
tree for an
expression. The grammar for an expression is given below. (Apr 09)
E ! E + T |E − T |T
T ! (E) |id |num
b) Write a detail notes on type conversion.
13. a) Write a S - attributed grammar to connect the following grammar with prefix
rotator (Apr 09)
L!E
E ! E+T | E-T | T
T ! T*F | T/F | F
F!P"F|P
P ! (E)
P ! id.
b) Construct triples of an expression: a _−(b + c).

14. a) Which of the following recursive type expressions are equivalent? Justify your
answer?
(Apr 09)
e1=integer ! e1; e2=integer ! ( integer ! e2 ); e3=integer ! ( integer !e1).
b) Suppose that the type of each identifier is a sub range of integers for expressions
with the operators +,-,*,div and mod as in pascal. Write type-checking rules that
assign to each sub expression, the subrange its value must lie in.

15. Write type expressions for the following types. (Apr 09)
a) An array of pointers to reals, where array index ranges from 1 to 100.
b) A two dimensional array of integers (i.e. an array of array) whose rows are indexed
from 0 to 9 and whose columns are indexed from -10 to 10.
c) Functions whose domains are functions from integers to pointers to integers and
whose ranges are records consisting of an integer and a character. (April/May 2009)

16. Write a note on the specification of a simple type checker.


(Apr 08)

17. Write short notes on the following: . (Apr 08)


a) S-attributed definitions. b) L-attributed definitions. c) Dependency
graph.

18 Write the quadruple , triple, indirect triple for the statement a:=b*-c+b*-c.
(Apr 08)
19. Write type expression for the following types. (Feb 07)
a) An array of pointers to real, where the array index ranges from 1 to 100.
b) A two dimensional array of integers (i.e an array of arrays) whose rows are indexed
from 0 to 9 and whose columns are indexed from 10 to 10.

20. Apply the translation scheme on the following expression a< b or c< d and e< f.
(Mar 06)

21. Give a syntax-directed translator scheme for converts the statements of the
following grammar into three address code: . (Mar 06)
S!while expr do begin S and
|S; S
|break

22. a) Discuss about the overloading of functions and operators with an examples.
(Mar 06)
b) Write a notes on polymorphic functions.

23. Give a syntax-directed translator scheme for converts the statements of the
following grammar into three address code (Apr 05)
while expr do begin S and
;S
break
|other`
L!id

24. What are S-attributed and L-attributer grammars. . (Apr 05)

25. Write a S-attributed grammar to connect the following grammar with prefix rotator
(Apr 05)
L!E .
E!E+T
E!E-T
E!T
T!T*F
T!T/F
T!F
F!P" F
F!P
P!(E)
P!id.

26. Which of the following recursive type expressions are equivalent ? Justify your
answer? (Apr 05)
e1 = integer ! e1 e2 = integer !(integer ! e2) e3 = integer !(integer ! e1)
27. Suppose that the type of each identifier is a sub range of integers for expressions
with the operators +, -,*, div and mod as in pascal. Write type checking rules that
assign to each sub expression, the sub range its value must lie in.
(Apr 05)

28. What are the advantages and disadvantages of Structural equivalence? Explain
through example.

(Apr 05)

29. What are the advantages and disadvantages of me equivalence. Explain through
examples. (Apr 05)

30. Which among the following expressions are Structurally equivalent? Which are me
equivalent? Justify your
answer. (Apr 05)
i. link ii. pointer(cell) iii. pointer(link)

31. Give a detail analysis on generic function and polymorphic function.


(Apr 05)

32. How do you check the expressions in polymorphic functions? Explain through an
example. (Apr 05)

33. a)What is dangling reference in storage allocation? Explain with an example. (Apr
05/08)
b)Consider the following array declaration in ‘c’;
float a[100][100];
Assume that the main memory in byte addressable and that the array is stored starting
from the memory address 100. What is the address of a[40][50]?

34 a) What is the use of Symbol table in compilation process? List out various attributes
stored in the symbol table. (Apr 11)
b) Explain different schemes of storing name attribute in symbol table.

35. Explain how storage allocation is done for arrays, strings and records? (Apr 11)

36. What is a symbol table? Describe any two methods of implementing a symbol
table. (Apr 11)

37. List the various data structures that can be used to organize a symbol table?
Compare the performance.
(Apr 11)
38 a) Explain the importance of each attribute stored in symbol table? (Apr 11)
b) Compare the performance of different symbol table organization.

39 Explain activation tree and draw activation tree for any sorting method. (May 10)

40 a) Convert the following grammar into LL(1) grammar (May 10)


S→ ABC A →a A| C B → b C → c
b) Construct LL(1) parse table for the above grammer.

41. Explain symbol table organization using hash tables? Construct hash based
structure for symbol table for the variable in the following program. (May 10)
int main()
{
int a1, a2, c1, c2;
char b1;
float d1, d2;
____
____
}

42. Explain the terms: (May 10)


a) Activation record
b) Activation trees
c) Block structure
d) Non block structured languages

43. Explain activation trees and draw activation tree for quick sort program. (May 10)

44. Explain the following with an example. (May 09)


a) Indirection in symbol table entries
b) Self organizing symbol tables.

45. Draw and explain the symbol table organization for C language with a program
block. (May 09)

46. Explain the importance of the following attributes of a symbol table. (May 09)
a) Variable name
b) Object time address
c) Type of a symbol table
d) Link field.

47. a)What is heap storage allocation? Explain in detail. (May 09)


b) Explain about implicit and explicit storage requests.

48. a) What is an ordered and unordered symbol table? What is the function of symbol
table in the compilation process? Explain. (Apr 08)
b) What are the various attributes of a Symbol Table?
49. Compare three different storage allocation strategies. (Apr 08)

50. Write an algorithm to perform the table lookup and insertion operation for hashed
symbol table.

(Apr 08)

UNIT-IV :

Block Structure and Non-Block Structure Storage Allocation: Static, Runtime


stack and heap storage allocation, storage allocation for arrays, strings and
records. Code Optimization: Consideration for optimization, scope of
optimization, local optimization, loop optimization, frequency reduction,
folding, DAG representation

1. Write importance of loop optimization technique. With example explain loop


unrolling and frequency reduction. (Apr 14)

2. What is a DAG? Explain role of DAG in optimization with example. (Apr 13)

3. What is local and global optimization? Explain with example any three local
optimization techniques. (Apr 12)

4. a) What is local and global optimization? (Apr 11)


b) Consider the following part of code.
int main()
{
int n,k=0;
scanf(“%d",&n);
for(i=2; i<n;i++)
{
if((n % i) == 0) break;
}
k=1;
if( i==n)
printf(“number is prime");
else
printf(“number is not prime");
}
i. Identify the basic blocks in the given program.
ii. Draw the domination tree for the program

5. Explain with example the various techniques in loop optimization. (Apr 11)

6. Write the iterative algorithm for reaching definition. Compute in and out for the
following figure 1.(Apr 11)
7. Write the procedure for identifying the basic blocks with example. For the same
example draw domination tree. (May 10)

8. What is a basic block? With an example explain the procedure to identifying basic
blocks in a given program. (May 10)

9. Write the importance of global code optimization. Explain redundant sub


expression elimination technique across different blocks with example (May 10)

10. Explain with example the various techniques in loop optimization. (May 10)

11.a) Explain in detail the Optimization technique “strength reduction”. (Apr 09)
b)What is a DAG. Explain its applications.

12. a) Write the three-address code for the following code. (Apr 09)
begin
PROD: = 0;
I: =1;
do
begin
PROD:=PROD + A[I]∗B[I];
I:=I+1;
End
while I<=20
end
b) Write an algorithm for partition of basic blocks and apply it on the above derived
three-address
code.

14. Explain different principal sources of optimization technique with suitable examples.
(Apr 09)

15. a) What is DAG? Construct the DAG for the following basic block (Apr 09)
D := B_C
E :=A+B
B := B+C
A := E-D
b) What are the legal evaluation orders and names for the values at the nodes for the
DAG of problem (a).
i. Assuming A, B and C are alive at the end of the basic block?
ii. Assuming only A is live at the end?

16. Explain different principal sources of optimization technique with suitable


examples. (Apr 08)

17. a) What is code optimization? What are its advantages? (Apr 08)
b) What are the problems in optimizing compiler design?
18. Explain in detail the optimization technique “Strength Reduction”. (Feb 07)

19. Explain any two machine dependent code optimization techniques. (Mar 06)

20. What is a DAG? Explain its application. (Mar 2006)

21. Write detailed notes on: Peephole optimization. (Apr 05)

22. Give a detailed account on loop optimization techniques. (Apr 05)

23. Explain in detail the optimization technique “Strength Reduction”. (Apr 05)

24. Explain how redundant sub expression elimination and dead code elimination
techniques are applied across different blocks with examples. (Apr 11)

25. Explain about global data flow analysis? List the data flow equations for reaching
definitions for structured programs (Apr 11)

26 Explain the formulation of data flow equations for reaching definition in


structured programs. Describe the procedure to compute in and out values. (Apr
11)

27 Define the following terms: (May 10)


a) Reaching definition
b) Live variables
c) Flow graphs
d) Global optimization

28 a) What is next use information explain in detail? (May 10)


b) Write about target code forms. Explain how the target code can be generated from
the given three address code.

29 Describe the procedure to compute in and out values using data flow equations for
reaching definition in structured programs. (May 10)

30 a) Explain in detail the procedure that eliminate global common sub - expression.
(Apr 09)
b) What are the applications of du and ud chains?

31. Consider the following program which counts the primes form 2 to n using the sieve
method on a suitably large array (Apr 09)
begin
read n
for i : = 2 to n do
a[i] : = true / * initialize */
count: = 0;
for i : 2 to n ** .5 do
if a [i] then /* i is a prime */
begin
count := count +1
for j : = 2 * i to n by i do
a[j] : =false
/ * j is divisible by i */
end ;
print count
end
a) Propagate out copy statements wherever possible.
b) Is loop jumping possible? If so, do it.
c) Eliminate the induction variables wherever possible.

32 a) Generate the flow-graphs for the following expressions: (Apr 09)


S-> id: = E |S; S| if E then S else S | do S while E
E-> id + id |id
b) Mention data-flow equations for reaching definitions for the above expressions.

33 a) What is an Induction variable? Explain with an example. (Apr 09)


b) Discuss how induction variables can be detected and how transformation can be
applied.

34. Explain about data flow analysis of structured programs (Apr 08)

35. What is global data flow analysts? (Apr 08)

36. a) Explain reducible and non-reducible flow graphs with an example. (Apr 08)
b) Explain structural loops and inner loops of a flow graph with an example.

37. Explain briefly about folding. (Apr 08)

38. A flow graph is useful for understanding code generation algorithm? (Apr 08)
Justify your answer with an example.

39. a) Write and explain live variable analysis algorithm. (Apr 2008)
b) Explain the use of algebraic transformations with an example

40. a) What are loop invariant components? Explain how they effect the efficiency of a
program. (Mar 06)
b) Explain how Redundant sub expression elimination can be done at global level in a
given program.

41. What are the application of du-and ud? (Mar 06)

42. Explain all code optimization technique give examples?


43 What is dead code elimition?Explain it with one Example?
44 Explain about machine dependent and machine independent code optimization
techniques.?
45 Describe the algoarithm to partition three adress code into basic blocks?

46 Explain different principal sources of optimization technique with suitable


examples.
47 Give a detailed account on loop optimization techniques.
48 Write detailed notes on: Peephole optimization.
49 Explain the strength reduction loop optimization technique in detail.
50 Explain about data flow analysis of structured programs

UNIT-V :

Data Flow Analysis: Flow graph, data flow equation, global optimization,
redundant sub expression elimination, Induction variable elements, Live
variable analysis, Copy propagation. Object Code Generation: Object code
forms, machine dependent code optimization, register allocation and
assignment, generic code generation algorithms, DAG for register allocation

1. Explain the following terms. (Apr 14)


a) Register descriptor
b) Address descriptor
c) Instruction costs
d) Flow graphs

2. a) Write about the issues in the design of code generator. (Apr 13)
b) Write about target code forms. Explain how the instruction forms effect the
computation time.
3. Generate the code for the following C statements using its equivalent three
address code. (Apr 12)
a) a = b + c
b) x = a/(b+c) d*(e+f)
c) *A=p
d) A=B+C

4. Explain machine dependent code optimization with example. (May 11)

5. a) Write about global register allocation strategy for loops. (May 10)
b) Explain code generation from DAG. For the following instructions construct DAG.
t1:=a / b
t2:=a/b
t3:=e - t2
t4:=t1 -t3
t5:=e+t2
t6:=t4 * t5

6. Explain DAG and its use. Write the procedure to construct the DAG for a statement.
(May 10)

7. a)Explain the different issues in the design of a code generator.


(Apr 08)
b)Generate code for the following Cstatements:
i. x= f(a) + f(a) + f(a)
ii. x= f(a)/g(b,c)
iii. x= f(f(a))
iv. x= ++f(a)

8. Explain the concept of object code forms. (Feb 07)

9. Generate code for the following ’C’ statements (May 09)


a) x = f(a) + f(a) + f(a)
b) x = f(a) / g(b,c)
c) x = f(f(a))
d) x = ++f(a)

10. State and explain different machine dependent code optimization techniques.
(Apr 09)

11. a) What are the various addressing modes available? Give some example machine
instructions which reduces memory access time. (Apr 09)
b) Explain the concept of label tree of code generation.

12. a) Explain with an example the abstract machine code form of Intermediate code.
(Apr 08)
b) Explain the role of intermediate code generator in compilation process.

13. Generate optimal machine code for the following C program.


(Feb 07)
main()
{
int i, a[10];
while(i<=10)
a[i] =0
}

14. Generate code for the following statements for the target machine (Target Machine
is a byte addressable machine with four bytes to a word and N general purpose
registers.) Assuming all variables are static. Assume 3 registers are available.
(Mar 06)
a) x = a [I ] +1 [4] b) a[ I] = b [c[I ]] [4]
c) a[I] [J] = b[I] [k] * c[k] [J] d) a[I] = a[I] + b[J] [4]
15. a) Augment the code generation algorithm to incorporate the following features.
(Mar 06)
i. The parenthesis in an expression
ii. Non commutative
operators like ‘-‘ and ‘/’ etc
b) Show various steps in the code generation algorithm of the expression (a + b) / (c +
d). Assuming two machine registers to be available.

16. Write about the various object code forms. (Apr 05)
17. Explain with an example the abstract machine code form of Intermediate code.
(Apr 05)

18. Explain with an example how abstract machine code can be generated for a given
if-then-else statement. (Apr 05)

19. Define Address Descriptor and Register Descriptor. (Apr 05)

20. Augment the code generation algorithm to incorporate the following features.
(Apr 05)
i. The parenthesis in an expression
ii. Non commutative operators like ‘-‘ and ‘/’ etc

21. Show various steps in the code generation algorithm of the expression.
(Apr 05)
(a + b) / (c + d)
Assuming two machine registers to be available.

22. Generate code for the following C program:


main ( )
{
int i;
int a[10];
while (i <= 10)
a[i] = 0;
}

23. Generate code for the following C statements:


a) x = f(a) + f(a) + f(a)
b) x = f(a)/g(b,c)
c) x = f(f(a))
d) x = ++f(a)
e) *p++ = *q++

24. Construct the dag for the following basic block:


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

25. Explain about Generic code generation algorithm?


26. Define Address Descriptor and Register Descriptor.
27. Write and explain Heuristic Ordering algorithm for DAG with one example.
28. Describe various Register allocation optimization techniques with an example.

29. Write and explain about object code forms?


30. a)Explain the different issues in the design of a code generator.

b)Generate code for the following C statements:


i) x= f(a) + f(a) + f(a)
ii) x= f(a)/g(b,c)
iii) x= f(f(a))
iv) x= ++f(a)
31. Generate code for the following statements for the target machine (Target
Machine is a byte addressable machine with four bytes to a word and N general
purpose registers.) Assuming all variables are static. Assume 3 registers are available.

a) x = a [I ] +1 [4] b) a[ I] = b [c[I ]] [4]


c) a[I] [J] = b[I] [k] * c[k] [J] d) a[I] = a[I] + b[J] [4]

32. Construct DAG for the following basic block:


d: = b+c
e: = a+b
b: =b*c
a: = e-d
33. Consider the grammar rule E-> E1-E2 for arithmetic expressions. The code generated
is targeted to a CPU having a single user register. The subtraction operation requires
the first operand to be in the register. If E1 and E2 do not have any common sub
expression, in order to get the shortest possible code. (GATE 2004)
(a). E1 should be evaluated first.
(b). E2 should be evaluated first.
(c). Evaluation of E1 and E2 should necessarily be interleaved.
(d). Order of evaluation of E1 and E2 is of no consequence.

34. Generation of intermediate code based on an abstract machine model is useful in


compilers because
(GATE 1994)
a) it makes implementation of lexical analysis and syntax analysis easier
b) syntax-directed translations can be written for intermediate code generation
c) it enhances the portability of the front end of the compiler
d) it is not possible to generate code for real machines directly from high level language
programs

35.What are the properties of code generation phase? Also explain the Design Issues of this
phase.
36. What are basic blocks? Write the algorithm for partitioning into Blocks.
37. Write a short note on:
a. Flow graph (with example)
b. Dominators
c. Natural loops
d. Inner loops
e. Reducible flow graphs
38.Consider the following program code:
Prod=0;
I=1;
Do{
Prod=prod+a[i]*b[i];
I=i+1;
}while (i<=10);
a. Partition in into blocks
b. Construct the flow graph
39. What is code optimization? Explain machine dependent and independent code
optimization.
40. What is common sub-expression and how to eliminate it? Explain with example.
41. Write a short note with example to optimize the code:
a. Dead code elimination
b. Variable elimination
c. Code motion
d. Reduction in strength
42. What is control and data flow analysis? Explain with example.

43. Write about all issues in code generation. Describe it.


44. Explain the target machine architecture?
45. Explain optimization techniques on Basic Blocks with simple examples?
46. Describe the various strategies in register allocation.
47. Explain the peephole optimization Technique?.
48. Construct the DAG for following statement. a+b*c+d+b*c
49. Construct the DAG for the following basic blocks

1. t1:=4*i
2. t2:=a[t1]
3. t3:=4*i
4. t4:=b[t3]
5. t5:=t2*t4
6. t6:=prod+t5
7. prod:=t6
8. t7:=i+1
9. i:=t7
10. if i<=20 goto 1
50. Explain the simple code generator and generate target code sequence for the following
statement d:=(a-b)+(a-c)+(a-c)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy