ENGINEERING COLLEGE
PONDY-MAILAM ROAD, SEDARAPET, P.O., VANUR.
2 & 16 MARK
Sub Code & Sub Name : CS2352 -PRINCIPLES OF COMPILER DESIGN
Branch : CSE
Semester: VI
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.
2
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?
3
MAY/JUNE 2007
<
=
>
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
.
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
Main phases:
1) Lexical analysis
2)Syntax analysis
3) Semantic analysis
4) Intermediate code generation
5) Code optimization
6) Code generation
2. Explain the various Compiler Construction Tools. (Page No.22) April/May 2011,
April/May 2012
COMPILER CONSTRUCTION TOOLS
These are specialized tools that have been developed for helping implement various
phases of a compiler. The following are the compiler construction tools:
1) Parser Generators:
These produce syntax analyzers, normally from input that is based on a context-free
grammar.
-It consumes a large fraction of the running time of a compiler.
-Example-YACC (Yet Another Compiler-Compiler).
2) Scanner Generator:
-These generate lexical analyzers, normally from a specification based on regular expressions.
-The basic organization of lexical analyzers is based on finite automation.
3) Syntax-Directed Translation:
-These produce routines that walk the parse tree and as a result generate intermediate code.
-Each translation is defined in terms of translations at its neighbor nodes in the tree.
C : * : : * : 2 : eof : : : eof
For example, ban is a prefix of banana.
2. A suffix of string s is any string obtained by removing zero or more symbols from the
beginning of s. For example, nana is a suffix of banana.
3. A substring of s is obtained by deleting any prefix and any suffix from s.
For example, nan is a substring of banana.
3. The proper prefixes, suffixes, and substrings of a string s are those prefixes, suffixes,
and substrings, respectively of s that are not or not equal to s itself.
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
Union
12
Kleene Closure
Positive Closure
APRIL/MAY 2008
TT*F|F
F ( E )| id
E TE'
E' +TE' |
T FT'
T' *FT' |
F ( E ) | id
23. Mention the two rules for type checking. Nov/Dec 2011
type checker for a language is based on information about the syntactic constructs
in the language, the notion of types, and the rules for assigning types to language
constructs.
24. What is dangling reference APRIL/MAY 2012
A dangling reference occurs when there is a reference to storage that has been
deallocated. It is a logical error to use dangling references, since the value of deallocated
storage is undefined according to the semantics of most languages
PART B [Text Book:Alfred Aho,Ravi Sethi,V.Jeffery Ullman]
1. Explain Top- Down Parsing and Bottom up Parsing. C
MAY/JUNE 2007
2. Explain Error Recovery in Predictive Parsing. (Page No.192) MAY/JUNE 2007
NOV/DEC 2007 APRIL/MAY 2005
3.
Distinguish between the source text of a procedure and its activation at run time.
(Page No.389)
4.
(Page No.401)
6.
APRIL/MAY 2005,
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
15
NOV/DEC 2007
UNIT III
PART A
1.
Operator
Uminus
*
=
Argument -1
c
b
Argument -1
T1
Result
T1
T2
a
16
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:
17
18
19
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
20
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.
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?
4. What are the advantages and disadvantages of register allocation and assignments?
Advantages:
i. It simplifies the design of a compiler
Disadvantages:
i. It is applied too strictly.
ii. It uses registers in efficiently. Certain registers may go unused over substantial
portions of the code, while unnecessary load and stores are generated.
5. What is meant by multiregister operations?
We can modify our labeling algorithm to handle operations like multiplication, division,
or function calls which normally requires more than one register to perform. Hence this
operation is called multiregister operations.
6. What is meant by peephole optimization? MAY/JUNE 2007
Peephole optimization is a technique used in many compliers, in connection with the
optimization of either intermediate or object code. It is really an attempt to overcome the
difficulties encountered in syntax directed generation of code.
7. What are the primary structure preserving transformations on basic blocks?
Common sub-expression elimination
Dead-code elimination
Renaming of temporary variable
Interchange of 2 independent adjacent statements.
8. What are the issues in the design of code generators? Nov/Dec 2007
i) Input to the code generator
ii) Target programs
iii) Memory management
iv) Instruction selection
v) Register allocation
vi) Choice of evaluation order
vii) Approaches to code generation
9. What are the various forms of target programs?
i) Absolute machine language
ii) Relocatable machine language
iii) Assembly language
10. What are the rules to determine the leaders of basic blocks?
i) The first statement is a leader
22
ii) Any statement that is the target of a conditional or unconditional goto is a leader
iii) Any statement that immediately follows a goto or conditional goto statement is a
leader.
17.
produced by the front end together with information in the symbol table that is used to determine
the run time addresses of the data objects denoted by the names in the intermediate
representation.
PART B [Text Book:Alfred Aho,Ravi Sethi,V.Jeffery Ullman]
1. What are the issues in design of a code generator? Explain in detail (Page No:506 )
NOV/DEC 2007,
(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
24
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.
26
(Page No:592 )
(Page No:633 )
April/May 2011
7.
APRIL/MAY 2011
8.
28