You are on page 1of 10

RVS TECHNICAL CAMPUS COIMBATORE

KANNAMPALAYAM, COIMBATORE - 641 402.


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
ACADEMIC YEAR 2016-2017

QUESTION BANK

Subject Code and Name : CS6660 COMPILER DESIGN

Staff-in-charge : D.BALAMURUGAN

Class / Sem : III CSE / VI

UNIT-I: INTRODUCTION TO COMPILERS


Translators-Compilation and Interpretation-Language processors -The Phases of Compiler-Errors
Encountered in Different Phases-The Grouping of Phases-Compiler Construction Tools -
Programming Language basics.

PART-A
1. What is language processing system? (Nov-Dec 2008)
2. What are compilers? Mention the broad steps in the process of compilation (Nov-Dec 2013)
3. Define cross compiler (May-June 2013-IT) / (May-June 2014)
4. Define pre-processor & what are the functions of pre-processor? (Nov-Dec 2007) / ND 2014
5. What do you meant by interpreter?
6. Write short notes on error handler
7. Mention some of the cousins of the compiler (Apr-May 2015 cbe)
8. What is front end and back end of compiler?
9. Give any 2 reasons why phases of compiler should be grouped? (May-June 2014)
10. List some compiler construction tools (Nov-Dec 2016)
11. What is symbol table? What are its attributes? (Nov-Dec 2007/2016, 2013-IT) / (May-June
2014) / Write short notes on symbol table manager
12. Differentiate compiler & interpreter (May-June2013-IT)/(Nov-Dec 2013-IT)
13. What is difference between compiler and assembler? (Apr-May 2015 cbe)
14. Identify compiler too1 that perform each of the following actions (May-June 2014-IT)
a) analyzes the program text and represents it as a hierarchical structure.
b)variables represent the logical signals (0 or 1 )in a switching circuit.,
PART-B
1. Explain the various phases of compiler with neat diagram / Explain process of compilation
(ND 2016) / (MJ 2013 /2014 IT) / ND 2013 IT / AM 2015 cbe / ND 2014 cbe
2. Briefly explain the compiler construction tools with benefits & drawbacks.( ND 2016) / ND
2014 (AM 2015) / ND 2013 IT / MJ 2013 IT / AM 2015 cbe // ND 2014 cbe
3. Describe how various phases should be combined as a pass in a compiler / Explain need for
grouping of phases (ND 2016) / ND 2014 / MJ 2014 IT / AM 2008
4. Explain various errors encountered in different phases of compiler (ND 2016)
5. What are the other tools related to compiler? / Explain cousins of compiler (MJ / ND 2014
IT , cbe)
6. Define the following terms : compiler, interpreter, translator and differentiate between
them(MJ 2014)
7. Explain simple one pass compiler (MJ 2013 IT )
8. Discuss how symbol table used in various phases of compiler (ND 2014 cbe)
9. Explain process of bootstrapping (AM 2015 cbe)
10. How abstract stack machine used as translator ( MJ 2009)
11. Write down the output of each phase for the expression
i) a: = b + c * 50.
ii) a=(b+c)*(b+c)*2 (AM 2014) / (MJ 2014 IT)
iii) position:=initial+rate*60 (MJ 2013 IT)
UNIT-II :LEXICAL ANALYSIS

Need and Role of Lexical Analyzer-Lexical Errors-Expressing Tokens by Regular Expressions-


Converting Regular Expression to DFA- Minimization of DFA-Language for Specifying Lexical
Analyzers-LEX- Design of Lexical Analyzer for a sample Language.

PART-A
1. What is role of lexical analyser? (Nov-Dec 2014)
2. What is LEX? (MJ 2013-IT)/Write about tool for generating lexical analyzer (AM 2015 cbe)
3. What are the issues to be considered in design of lexical analyzer? (May-June 2009 / 2007)
4. i) What are tokens? Give example (Nov-Dec 2013-IT)
ii) Define patterns, lexeme, tokens / differentiate patterns, lexeme, tokens (Nov-Dec 2016) /
(May June 2014) /(May-June 2014-IT) / ND 2014 cbe
5. i)Give the error recovery actions in lexical errors / lexical phase of compiler (Apr-may
2015) / (Nov-Dec 2008)
ii) Give two examples of lexical errors. (May-June 2014-IT)
6. What is the use of symbol table in lexical analyzing ? (ND 2014 cbe)
7. Mention types of input buffering (Nov-Dec 2013-IT)
8. Write note on buffer pair (Apr-May 2008)
9. Why is buffering used in lexical analysis? What are the commonly used buffering methods?
(May-June 2014)
10. Compare DFA & NFA (May-June 2014)
11. Define regular expression
12. Give the rules in regular expression/ Give the algebraic properties of regular expression
13. Define kleene closure or star closure and positive closure
14. What are the three parts of lexical program? (ND 2014 cbe)
15. Write regular definition to represent date in the following format Jan-5th 2014 (Apr-may
2015)
16. Write regular expression to
i) describe a language consists of string made of even number of as & bs (Nov-Dec
2014)
ii) to represent identifier (May-June 2013-IT) (Apr-May 2015 cbe)
iii) for the following over X = {a,b}. all strings containing exactly one a , all strings
containing an even number of a's. (May-June 2014-IT)
PART-B

1. Explain token specification and recognition (ND 2014) / AM 2008


2. Explain the Role of lexical analyzer in detail with necessary examples (ND2016) / MJ 2013
IT)
3. What is need for lexical analysing & What are the issues in lexical analyzing (AM 2014) /
AM 2015 cbe
4. Differentiate lexeme, token, pattern (6) (AM 2014)
5. Design lexical analyser generator (ND 2013 IT) / Discuss implementation of lexical
analyzer (MJ 2013 IT)
6. Discuss how FA is used to represent tokens and perform lexical analysis with example
(ND2016).
7. Write algorithm for minimizing the number of states of DFA (ND 2016) / MJ 2014 IT
8. Explain the optimization of DFA-based pattern matchers.
9. Write the tool for generating lexical analyser / Explain language for specifying lexical
analyzer (ND 2014)
10. Describe the error recovery schemes in lexical analysis phase of compiler(AM 2015) / MJ
2013 IT
11. Explain need for buffering / Input buffering schemes in lexical analysis (MJ 2014 IT) / AM
2015 cbe / ND 2014 cbe / AM 2008 / MJ 2007
12. Write the significance of symbol table during the lexical analysis MJ 2013 IT
13. what is Lex? Give the Lex specifications to count the number of characters and number of
lines in a given text and explain. (8) (MJ 2014 IT)
14. Convert the R.E to NFA and find DFA . (a/b)*aab (ND 2016) / ND 2013 IT
15. Obtain DFA from NFA of given regular expressions and Minimize DFA using new
construction. Write down the algorithm wherever necessary.
a. (a/b)* abb
b. (a/b)* a (a/b).
c. (a/b)* a (a/b) (Thompson method)
d. (a/b)* a(a/b) (a/b)
e. (a/b)* abb (a/b)*
f. (a/b)* abb (a/b) (minimized DFA) (AM 2015 cbe) / ND 2014 cbe
g. (a/b)*b+ use Thompson method (MJ 2014 IT)
h. (a/b)* abb# (minimized DFA directly from augmented re by drawing syntax tree
(ND 2014 cbe)
16. Prove that following 2 regular expressions are equal by showing that minimized DFAs are
same : a) i)(a/b)* ii) (a* / b*)* (AM 2015)
b) i) (a* / b*) ii) (( | a )b*)* (AM 2015 cbe )
17. Define a regular grammar. Construct a regular grammar which will generate all strings
of 0's and l's having both an odd number of 0's and odd number of 1's. (AM 2015 cbe )
UNIT-III- SYNTAX ANALYSIS
Need and Role of the Parser-Context Free Grammars -Top Down Parsing -General Strategies-
Recursive Descent Parser Predictive Parser-LL(1) Parser-Shift Reduce Parser-LR Parser-LR
(0)Item- Construction of SLR Parsing Table -Introduction to LALR Parser - Error Handling and
Recovery in Syntax Analyzer-YACC-Design of a syntax Analyzer for a Sample Language.

PART-A
1. What is meant by parser? mention its types (Nov-Dec 2013-IT)
2. What are the different levels of syntax error handler? /What are error recovery strategies in
parser?
3. Write differences between regular grammar & CFG (May-June 2013-IT)
4. Define ambiguity / What is ambiguous grammar? (Nov-Dec 2007)
5. Define sentential form.
6. What is role of parser? (Apr-may 2015)
7. Write differences between top down & bottom up parsing (May-June 2013-IT)
8. i)What are the difficulties with top down parsing?
ii) What are the factors to be considered for top down parsing? (May-June 2009)
9. What is predictive parser? (Nov-Dec 2007)
10. What is meant by recursive-descent parser?
11. What is CLR? (Nov-Dec 2008)
12. Define LL (1) grammar.
13. What are the actions available in shift reduce parser?
14. What are the disadvantages of operator precedence parsing? (MJ 2007) / (AM 2015 cbe)
15. Define augmented grammar.
16. Define handle pruning.(Nov-Dec 2016) / ND 2014 cbe
17. What is annotated parse tree? (May-June 2013-IT)
18. Write CF grammar to represent palindrome (Nov-Dec 2014)
19. i)Construct parse tree for ( id + id ) (Nov-Dec 2016)
ii) Draw the syntax tree for the statement (a+b) * (c+d) (Nov-Dec 2013-IT)
iii) Derive the string and construct a syntax tree for the input string ceaedbe using the
grammar S->SaA|A,A->AbB|B,B->cSd|e (May-June 2009)
20. Consider the following Grammar G. (Nov-Dec 2013-IT)
E -> E+T | T T -> T*F | F F -> (E) | id. Find the FIRST of all non terrninals,

PART-B

1. What is FIRST and FOLLOW? Explain in detail with an example. Write down the necessary
algorithm.
2. Find First and Follow:
a) E->E+T/T T->T*F/F
F-> (E)/id

b) S-> (L)/a L->L, S/a


3. Top down parsing:
a) S->a/^/ (T) T->T, S/S
Input: ( a, (a, a)) (((a, a), ^, (a)), (a))

b) S->a/^/(R) T->S, T/S R->T


Input: ( a, (a, a)) (((a, a), ^, (a)), (a))

4. Shift reduce parsing


a) S-> (L)/a L->L, S/a
Input :( a, (a, a)) (a,((a, a),(a, a)))

b) S->aZ A->bY
B->X
Input: XYZ
5. LL (1)
S->AaAb/BbBa A->
B->
Check whether the grammar is LL (1) but not SLR (1)
6. LR (1):
a) S->CC C->Cc
C->d
b) S->Aa/bAc/Bc/bBa
A->d B->d
Check whether the grammar is LR (1) but not LALR (1)

7. Generate SLR Parsing Table for the following grammar (AM 2015)
S -> Aa l bAc l Bc l bBa
A->d
B->d
And parse the sentence "bdc" and "dd".

8. Write down the algorithm to eliminate left-recursion and left-factoring and apply both to the
following grammar (AM 2015)
E-->E+T | E-T | T
T ->a | b | (E)

9. LALR:
a) S->CC C->Cc
C->d
b) S->Aa/bAc/dc/bda
A->d
Check whether the grammar is LALR (1) but not SLR (1)

c) E->E+T | T , T->T*F |F , F->(E) |id parse the sentence (a+b)*c (ND 2014)
UNIT- IV SYNTAX DIRECTED TRANSLATION & RUN TIME ENVIRONMENT

Syntax directed Definitions-Construction of Syntax Tree-Bottom-up Evaluation of S-Attribute


Definitions- Design of predictive translator - Type Systems-Specification of a simple type
checker- Equivalence of Type Expressions-TypeConversions.

RUN-TIME ENVIRONMENT: Source Language Issues-Storage Organization-Storage


Allocation- Parameter Passing-Symbol Tables-Dynamic Storage Allocation-Storage Allocation
inFORTAN.
PART-A
1. i)Give syntax-directed translation for case statement (Nov-Dec 2014)
ii) Give syntax-directed translation for the statement call p1(int a , int b) (Apr-May 2008)
iii) Give the translation scheme for assignment statements. (Apr-May 2015 cbe)
2. Define an attribute. Give the types of an attribute.
3. Why is SDT needed? (May-June 2013-IT)
4. What are the functions used to create the nodes of syntax trees?
5. Mention some forms of intermediate code. / What are the methods to represent intermediate
code? (Nov-Dec 2007 / 2013-IT) / (Apr-May 2015 cbe)
6. Define postfix notation.
7. Define quadruple. Give an example.
8. Define back patching. (Apr-May 2008) / (May-June 2009 / 2007)
9. List out 3 functions that are used to manipulate list of labels in back patching (Nov-Dec 2008)
10. What are the semantic rules are defined in the declarations operations?
11. Write the grammar for flow-of-control statements.
12. Write down syntax directed definition of a simple desk calculator(Nov-Dec 2016)
13. What is activation tree? (Nov-Dec 2007) / ND 2014 cbe
14. Draw the diagram of general activation record and give purpose of any 2 fields (MJ 2007)
15. What are the limitations of static allocation? ( Nov-Dec 2007) /(May-June 2009)
16. List dynamic storage allocation techniques (Nov-Dec 2016 / 2014)
14. What are the types of intermediate languages? (Nov-Dec 2014)
15. Write properties of intermediate language (May-June 2007)
16. What is the significance of intermediate code? (May-June 2014) / Why is it necessary to
generate intermediate code instead of generating target program itself? (May-June 2009)
17. Define constant folding (Nov-Dec 2008)
18. Compare SDD and SDT schemes (ND 2014 cbe)
19. Construct parse tree according to syntax directed definition for the following input
(4+7.5*3)/ 2 (Apr-may 2015)
20. Write various 3 address code form of intermediate code (May-June 2014) / Give the ways
representing 3 address code (Nov-Dec 2007)
21. i)Write 3-address code for x=*y;a=&x (Apr-may 2015)
ii)Translate the expression a-(b+c) into 3 address code (Nov-Dec 2008)
iv) 3 address code for x:=a[y] (ND 2014 cbe)
22. Place the above generated 3-address code in triplet, indirect triplet (Apr-may 2015)
23. Identify whether the following SDD are synthesized or inherited (May-June 2014-IT)
(a) E -> E +E {E.VAL= E.VAL+E.VAL}
(b) A -> XYZ {Y.VAL = 2*A.VAL}
PART-B
1. How would you generate the intermediate code for the Boolean expression?
2. What are the various ways of calling the procedure? Explain in detail. / Write note on
parameter passing
3. Explain how declarations are done in a procedure using syntax directed translation scheme.
4. How would you generate the intermediate code for the flow of control statements and control
flow expression in the statement. Explain in detail with e.g.
5. What is an Activation Record? Explain how its relevant to the intermediate code generation
phase with respect to procedure Declarations (AM 2015)
6. Describe the methods for generating syntax directed definition for control statements.
7. What is three address codes. Mention the types. How would you implement the three address
statement with e.g.
8. Mention in detail about any 4 issues in storage organization (AM 2015)
9. Explain run time environment with suitable example (ND 2014)
10. Explain specification of simple type checker (ND 2014) / Illustrate type checking with
necessary diagram (ND 2016)
11. I)Explain register allocation and assignment with suitable / Write the procedure to perform
Register Allocation and Assignment with Graph Coloring example (ND 2014) / AM 2015
12. Write short note on back patching (AM 2008)
13. Explain the following with respect to code generation phase (ND 2016)
i)Input to code generator ii ) target program iii)memory management
iv) instruction selection v) register allocation vi )evaluation order
14. Give a syntax-directed definition to differentiate expressions formed by applying the
arithmetic operators + and * to the variable x and constant ; expression :
x*(3*x+x*x) (AM 2015)
15. Apply Back-patching to generate intermediate code for the following input.
x:2+y;
if x < y then x : = x + y;
repeat
y:=y*2;
while x>l0 do x:=x/2
until x < y
Write the semantic rule and derive the Parse tree for the given code. ( AM 2015)

16. i)Generate intermediate code for the following code segment along with the required syntax
directed translation scheme (ND 2014)
While (i<10)
If(r%2==0)
Evensum=evensum+i:
Else
Oddsum =oddsum + i;
ii)Generate intermediate code for the following code segment along with the required syntax
directed translation scheme s=s+a[i][j] (ND 2014)
UNIT-V- CODE OPTIMIZATION AND CODE GENERATION
Principal Sources of Optimization-DAG- Optimization of Basic Blocks-Global Data Flow
Analysis- Efficient Data Flow Algorithms-Issues in Design of a Code Generator - A Simple Code
Generator Algorithm.

PART-A
1. What are the issues in the design of code generator? (May-June 2009)
2. Define basic block and flow graph. (Nov-Dec 2007 / 2008) / (Apr-May 2008)
3. How do you find leaders in basic block? (Apr-May 2008) /Write the steps for constructing
leaders in basic blocks. (May-June 2009)
4. What is meant by register descriptors and address descriptors?
5. What are the actions to perform the code generation algorithms?
6. Define DAG with example. Give the applications of DAG.(ND 2013-IT /2008) /( MJ-2007)
7. Define Peephole optimization. What are the characteristics of Peephole optimization? (Nov-
Dec 2016)
8. Name the techniques in loop optimization (May-June 2014)
9. What are the criteria used for code improving transformations (Nov-Dec 2008)
10. What are the primary structure preserving transformations on basic blocks? (MJ 2007)
11. Define Common sub-expression elimination with ex.
12. Define reduction in strength with ex.
13. What is inline expansion? ( Nov-Dec 2007)
14. Define code motion (Apr-May 2008) / (May-June 2007)
15. Identify the constructs for optimization in basic block (Nov-Dec 2016)
16. Write algorithm that orders the DAG node for generating optimal target code (AM 2015)
17. What role does target machine play on code generation phase of compiler? (Apr-may 2015)
18. How liveness of variable is calculated? (Apr-may 2015)
19. What is global data flow analysis? (Nov-Dec 2014) / (Apr-May 2008)
20. What are the difference between syntax tree and DAG? (May-June 2013-IT)
21. Differentiate basic block and flow graph ( Nov-Dec 2014)
22. How would you represent dummy blocks with no statement indicated in global data flow
analysis? (May-June 2014 )
PART-B
1. What are the issues in the design of code generator? Explain in detail / Explain - code
generation phase with simple code generation algorithm .(ND 2014)
2. Write a code generation algorithm. Explain about the descriptor and function getreg().Give
an example.
3. Explain about Optimization of basic blocks.
4. Explain peephole optimization and various code improving Transformations. (ND 2014)
5. Explain - Generating code from DAG with suitable example (ND 2014)
6. Explain DAG representation of basic blocks. What are the advantages of DAG
representation? Give example (AM 2015)
7. Explain principle sources of code optimization in details. (AM 2008)
8. Explain about transformation on a basic block.
9. Explain global Data flow analysis with necessary equations (ND 2016)
10. Explain any 4 issues in designing code generator (ND 2016)
11. Write the Code Generation Algorithm using Dynamic Programming and generate code for
the statement x= a / (b - c) - s*(e + f). [Assume aII instructions to be unit cost] (AM 2015)
12. Construct DAG & optimal target code for the expression ((a+b)/ (b-c)) - (a+b)*(b-c) + f
(AM 2015)
13. Explain loop optimization in detail & apply it for the given code (AM 2015)
14. What are the optimization techniques applied on procedures calls? Explain with example
(AM 2015)
15. Perform analysis of available expressions on the following code by converting into basic
blocks and compute global common sub expression elimination (Ref QN paper for the code)
(AM 2015)
16. Generate DAG representation of the following code and list out the applications of DAG
representation (ND 2014)
i = 1; while (i<=10) do
sum+ = a[il;

You might also like