Professional Documents
Culture Documents
QUESTION BANK
PRINCIPLES OF COMPILER DESIGN
UNIT I
PART-A
1. What is Error Handler?
The error handler invokes error diagnostic routines and also generates error
messages. It works in conjunction with all the phases to handle the errors at the
respective phases.
2. Define Tokens. APRIL/MAY 2011
The token can be defined as a meaningful group of characters over the character set
of the programming language like identifiers, keywords, constants and others.
3. Define Symbol Table.
A Symbol Table is a data structure containing a record for each identifier, with fields
for the attributes of the identifier.
4. Name some variety of intermediate forms.
Syntax tree
Quadruple
What are the main two parts of compilation? What are they performing?
APRIL/MAY 2010
The two main parts are
Analysis part breaks up the source program into constituent pieces and creates
An intermediate representation of the source program.
Synthesis part constructs the desired target program from the intermediate
Representation.
a.Parse generator
b. Scanner generators
c. Syntax-directed translation engines
d. Automatic code generator
i. Data flow engines.
9. What is a Loader? What does the loading process do?
A Loader is a program that performs the two functions
i. Loading
ii .Link editing
The process of loading consists of taking relocatable machine code, altering the
relocatable address and placing the altered instructions and data in memory at the proper
locations.
10. What is a preprocessor? Nov/Dev 2004
A preprocessor is one, which produces input to compilers. A source program may be
divided into modules stored in separate files. The task of collecting the source program is
sometimes entrusted to a distinct program called a preprocessor.
The preprocessor may also expand macros into source language statements.
Skeletal source program
Preprocessor
Source program
11. What is an assembler and interpreter? APRIL/MAY 2011
Assembler is a program, which converts the assembly language in to machine language.
Interpreter is a program which converts source language into machine language line by
line.
12. What is a lexeme? Define a regular set. APRIL/MAY 2011
A Lexeme is a sequence of characters in the source program that is matched by the
pattern for a token.
A language denoted by a regular expression is said to be a regular set
13. What is a sentinel? What is its usage? April/May 2004
A Sentinel is a special character that cannot be part of the source program.
Normally we use eof as the sentinel. This is used for speeding-up the lexical analyzer.
14. What is a regular expression? State the rules, which define regular expression?
MAY/JUNE 2007
Regular expression is a method to describe regular Language
3
Rules:
1) -is a regular expression that denotes {} that is the set containing the empty
string
2) If a is a symbol in ,then a is a regular expression that denotes {a}
3) Suppose r and s are regular expressions denoting the languages L(r ) and L(s) Then,
a) (r )/(s) is a regular expression denoting L(r) U L(s).
b) (r )(s) is a regular expression denoting L(r )L(s)
c) (r )* is a regular expression denoting L(r)*.
d) (r) is a regular expression denoting L(r ).
15. What are the Error-recovery actions in a lexical analyzer? April/May 2012,
APRIL/MAY 2005
Deleting an extraneous character
Inserting a missing character
Replacing an incorrect character by a correct character
Transposing two adjacent characters
16. Draw a transition diagram to represent relational operators. NOV/DEC 2007
Start
<
=
>
Other
2
3
return(relop, NE)
*
5 return(relop,EQ) 4
>
return(relop,LT)
=
6
7
Other
return(relop,GE)
*
Return(relop, GT)
17. What are the issues to be considered in the design of lexical analyzer? MAY/JUNE
2009
How to Precisely Match Strings to Tokens
How to Implement a Lexical Analyzer
18. Define concrete and abstract syntax with example. MAY/JUNE 2009
The grammar is mainly used for parsing only - the key is to resolve all ambiguities. This
grammar is called Concrete Syntax.
Abstract Syntax is used to characterize the essential structure of the program the key is to be as simple as possible; it may contain ambiguities.
Traditional Compilers do semantic analysis on Concrete Syntax
Modern Compilers do the semantic analysis on Abstract Syntax tree
19. Differentiate compiler and interpreter APRIL/MAY 2008
An interpreter is a translator used to convert high level program into machine code. These
translators translate the program line by line. A Compiler is also a translator which is used
to translate the whole source of a program at a time.
20. Write short notes on buffer pair. APRIL/MAY 2008
Lexical analyzer will detect the tokens from the source language with the help of input
buffering. The reason is, the lexical analyzer will scan the input character by character, it
will increase the cost file read operation.. So buffering is used. The buffer is a pair in
which each half is equal to system read command.
21. How is the token structure is specified? APRIL/MAY 2010.
Token structure is specified with the help of Pattern. The pattern can be described with the
help of Regular Expression
22. What is the role of lexical analyzer? NOV/DEC 2011
Its main task is to read input characters and produce as output a sequence of tokens that
parser uses for syntax analysis. Additionally task is removing blank, new line and tab
characters
23. Give the transition diagram for an identifier. NOV/DEC 2011
.
PART B [Text Book:Alfred Aho,Ravi Sethi,V.Jeffery Ullman]
1. What are the various phases of a compiler. Explain each phase in detail. (Page
No.10) April/May 2011, April/May 2012
2. Explain the various Compiler Construction Tools. (Page No.22) April/May 2011,
April/May 2012
5
the
transition
diagram
for
relational
operators
and
unsigned
It is difficult to select or determine which parse tree is suitable for an input string.
4.
Ex:
E E+E / E*E / id
If A is the Non terminal, labeling some interior node and x1, x2, x3 .xn
are the labels of the children.
form
may
contain
non
State of the calling procedure must be saved, so that it can resume after completion of
procedure.
o Return address is saved, in this location called routine must transfer after completion of
procedure
14. List out the actions involved in shift reduce parsing. MAY/JUNE 2007
o
o
o
o
Shift.
Reduce.
Accept.
Error.
15. What are the algebraic properties of regular expressions? APRIL/MAY 2005
8
Union
Kleene Closure
Positive Closure
APRIL/MAY 2008
TT*F|F
F ( E )| id
E TE'
E' +TE' |
T FT'
T' *FT' |
F ( E ) | id
Distinguish between the source text of a procedure and its activation at run time.
(Page No.389)
4.
(Page No.401)
6.
7.
Give an algorithm for finding the FIRST and FOLLOW positions for a given nonterminal.
MAY/JUNE 2009 APRIL/MAY 2008
April/May 2012
12.
APRIL/MAY 2005
11
NOV/DEC 2007
UNIT III
PART A
1.
Operator
Uminus
*
=
Argument -1
c
b
Argument -1
T1
Result
T1
T2
a
6.Generate three address code for " if A<B then 1 else 0", using numerical method.
(1) if A<B goto (4)
(2) T 1=0
(3) goto (5)
(4) T 1=1
(5)
7. List the three kinds of intermediate representation. NOV/DEC 2007
The three kinds of intermediate representations are
i. Syntax trees
ii. Postfix notation
iii. Three address code
8. What is a syntax tree? Draw the syntax tree for the assignment statement
a := b * -c + b * -c.
APRIL/MAY 2011,NOV/DEC 2011
A syntax tree depicts the natural hierarchical structure of a source program.
Syntax tree:
13
MAY/JUNE 2009
3. Describe the method of generating syntax directed definition for control statements.
( Page. No. 491)
NOV/DEC 2007
4. Brief Intermediate code generation for Basic block, Control Flow and Boolean
Expressions. (Page No:399 )
MAY/JUNE 2007
5. Explain the data structure used for implementing Symbol Table. (Page No:85 )
MAY/JUNE 2007 , NOV/DEC 2007, APRIL/MAY 2005
6. 7. Define three-address code. Describe the various methods of implementing threeaddress statements with an example. (Page No:366 ) MAY/JUNE 2007 ,
NOV/DEC 2007 ,APRIL/MAY 2005
7.
Give the translation scheme for converting the assignments into three address code.
(Page No:478 ) April/May 2011, Nov/Dec 2011
8.
16
9.
How can Back patching be used to generate code for Boolean expressions and flow
of control statements?
(Page No:501 ) April/May 2011, APRIL/MAY 2008
UNIT - IV
PART A
1. What are basic blocks?
An address descriptor keeps track of the location where the current value of the name can
be found at run time.
14. Define DAG. Nov/Dec 2007 , MAY/JUNE 2007
A DAG for a basic block is a directed acyclic graph with the following labels on nodes:
i) Leaves are labeled by unique identifiers, either variable names or constants.
ii) Interior nodes are labeled by an operator symbol.
iii) Nodes are also optionally given a sequence of identifiers for labels.
15. How would you calculate the cost of an instruction?
The cost of an instruction to be one plus the costs associated with the source and
destination address modes. This cost corresponds to the length of the instruction.
Address modes involving registers have cost zero, while those with a memory location
or literal in them have cost one.
16.
17.
19
2.
(Page No:528 )
April/May 2011, April/May 2012
3.
4.
(Page
MAY/JUNE 2007
Explain in the DAG representation of the basic block with example. (Page. No. 598)
April/May 2012 APRIL/MAY 2005 APRIL/MAY 2008
5.
How to generate a code for a basic block from its dag representation? Explain.
(Page No:546 )
6.
7.
8. Write short notes on next-use information with suitable example. (Page No.534)
APRIL/MAY 2008
UNIT - V
PART A
1. How the quality of object program is measured?
The quality of an object program is measured by its Size or its running time. For large
computation running time is particularly important. For small computations size may be
as important or even more.
2. Explain the principle sources of optimization.
Code optimization techniques are generally applied after syntax analysis, usually both
before and during code generation. The techniques consist of detecting patterns in the
program and replacing these patterns by equivalent and more efficient constructs.
3.
4.
10.
11.
12.
(Page No:592 )
(Page No:633 )
April/May 2011
7.
8.
23