ModelQuestionAnswerCompilerDesign
ModelQuestionAnswerCompilerDesign
Faculty of Technology
Department of Computer Science
Final Exam
__________________________________________________
Compiler Design Course Code: C o S c 3 1 1 2
Total marks: 100% Time allowed: 3 Hours
Target group (4th Year CS students) Date: 03/10/2015 E.C
Sign: ____________________
General Instruction:
1) Switch off your mobile, Write your Name, ID No., and section on the space provided.
2) Read each Instruction and Question carefully
3) Use only Blue pen
4) Giving answers out of provided space will be ignored
5) Make sure your hand writing is neatly
6) Cheating or any way to try to cheat will make your result F
grade.
7) Make sure the exam have 5 Question type and 18 pages
For Instructor's use only
Part I Part II Part III Part IV Part IV (25%) Total (50%)
(5%) (5%) (25%) (10%)
Good Luck!
______________________________________________________
Page | 1
Part I: choose the correct choice from the following alternatives [Each 1 pt].
[1] One of the following is not a run time process of a compiler.
A. Memory allocation C. Absolute addressing
B. Creating activation record tree D. None
[2] Which one of the following is correct expression for the following DAG tree representations?
A. a*(b-c)+(b-c)*d C. a+a*(b-c)+(b-c)*d
B. a+a*(b-c)+(b+c)*d D. None of the above
[3] Which one of the following is not the task of type checker?
A. Name related checking C. Type checking
B. Uniqueness checking D. Syntax checking
[4] Which of the following suffices to convert an arbitrary CFG to an LL (1) grammar?
A. Removing left recursion alone C. Removing left recursion and factoring the grammar
[5] The operators consuming less execution time replace the operators that consume higher execution
time. This type of optimization technique known as_______.
A. Constant Folding C. Strength Reduction
[6] Consider the grammar with the following translation rules and E as the start symbol.
Grammar Rules Semantics Rules
E à E #T {E.value := E.value * T.value}
E àT {E.value := T.value}
T àT & F {T.value := T.value + F.value}
T àF {T.value := F.value}
F à num {F.value := num.lexvalue}
Compute E.value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 &4?
Page | 2
A. 200 C. 160
B. 180 D. 4
[7] In a compiler, keywords of a language recognized during ____.
A. parsing of the program C. the lexical analysis of the program
B. the code generation D. dataflow analysis
[8] The lexical analysis for a modern language such as Java needs the power of which one of the
following machine models in a necessary and sufficient sense.
A. Finite state automata C. Non-deterministic pushdown automata
B. Deterministic pushdown automata D. Turing machine
[9] Match all items in Group 1 with correct options from those given in Group 2.
Page | 3
Group 1 Group 2
P. Regular expression 1. Syntax analysis
Q. Pushdown automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis
S. Register allocation 4. Code optimization
A. P-4, Q-1, R-2, S-3 C. P-3, Q-4, R-1, S-2
B. P-3, Q-1, R-4, S-2 D. P-2, Q-1, R-4, S-3
[10] Which one of the following type checking is different from others?
A. Array bound out of index C. Accessing a variable out of scope
B. Null pointer dereference D. data value mismatch
[11] What is the result while computing the following postfix expression abc^ef**+ba/+ where
a=1,b=2,c=3,e=4,f=5?
A. 120 C. 50
B. 151 D. 163
[12] A common and more preferable data structure used to implement symbol table is______.
A. Linked List C. Hash table
B. Stack D. Binary search Tree
[13] Which one is not the function of the symbol table?
A. To store the names of all entities in a structured form at one place.
B. To implement and process type checking
C. To determine the scope of a name (scope resolution).
D. used to achieve compile time efficiency and speed up the execution of instructions
E. None
Page | 4
A. (A) C. (C)
B. (B) D. (D)
[15] Match the description of several parts of a classic optimizing compiler in List - I, with the names of
those parts in List - II:
List I List II
(a) a part of a compiler that is responsible for recognizing syntax. (i) Optimizer
(b) A part of a compiler that takes as input a stream of characters and produces as (ii) Semantic
output a stream of words along with their associated syntactic categories. Analysis
(c) A part of a compiler that understand the meanings of variable names and other
(iii) Parser
symbols and checks that they are used in ways consistent with their definition.
(d) An IR-to-IR transformer that tries to improve the IR program in some
(iv) Scanner
way(Intermediate Representation)
Code:
(a) (b) (c) (d)
(1) (iii) (iv) (ii) (i)
(2) (iv) (iii) (ii) (i)
(3) (ii) (iv) (i) (iii)
(4) (ii) (iv) (iii) (i)
A. (1) C. (3)
B. (2) D. (4)
[16] The output of a lexical analyzer _____.
A. A parse tree C. Machine code
B. Intermediate code D. A stream of tokens
[17] The optimization that avoids test at every iteration is.
A. Loop unrolling C. Constant folding
B. Loop jamming D. None of the mentioned
[18] One of the following is a Machine Independent phase of the compiler.
A. Syntax Analysis C. Lexical Analysis
B. Intermediate Code generation D. All of the mentioned
Page | 5
[19] A system program that combines the separately compiled modules of a program into a form suitable
for execution?
A. Assembler C. Linking Loader
B. Compiler D. Interpreter
[20] Output file of Lex is _____ if the input file is Myfile.
A. Myfile.e C. Myfile.lex
B. Myfile.yy.c D. Myfile.obj
[21] At what phase type checking will be done during.
A. Lexical Analysis C. Syntax Directed Translation
B. Syntax Analysis D. Code generation
[22] Consider the following statements:
(I) the output of a lexical analyzer is stream of characters.
(II) Total number of tokens in printf ("i=%d, &i=%x", i, &i); are 11.
(III) Symbol table can be implementation by using array and hash table but not tree.
Which of the following statement(s) is/are correct?
A. Only (I) C. All (I), (II), and (III)
B. Only (II) and (III) D. None of these
[23] Substitution of values for names whose values are constant, is done in
A. local optimization C. constant folding
B. loop optimization D. none of these
[24] A compiler for a high-level language that runs on one machine and produces code for a
different machine called ______.
A. optimizing compiler C. cross compiler
B. one pass compiler D. multipass compiler
[25] Which of the following functions performed by loader?
A. Allocate space in memory for the programs and resolve symbolic references between objects
B. Adjust all address dependent locations, such as address constants, to correspond to the allocated space.
C. Physically place the machine instructions and data into memory
D. All of these.
Page | 6
[26] In some programming languages, an identifier has permitted to be a letter followed by any number
of letters or digits. If L and D denotes the sets of letters and digits respectively, which of the following
expressions define an identifier?
A. ( L∪ D ) * C. (L. D )*
B. L (D ∪ L)* D. L. (L. D )*
[27] A system program that set-up an executable program in main memory ready for execution
is_.
A. Assembler C. Loader
B. Linker D. Text editor
[28] A variable or statement that is live at some point in a program and if its value cannot be used
(accessed) subsequently, then we can eliminate it. It refers to an optimization type of___.
A. Strength Reduction C. Loop Optimization
B. Dead Code Elimination D. Code Movement
[29] A shift reduce parser carries out the actions specified within braces immediately after reducing with
the corresponding rule of grammar:
Sà xxS {PRINT “1”} Sà y {print” 2”} Sà Sz {print” 3”}
What is the translation of xxxxyzz using the syntax directed translation scheme described by the above
rules?
A. 23311 C. 11231
B. 11233 D. 33211
[30] Consider the following grammar :
S → FR R → *S | є F → id
In the predictive parser table M, what are the production rules of the grammar at the entries M[S,
id] and M[R, $] respectively
A. {S → FR} and {R →є } C. {S → FR} and {R → *S}
B. {S → FR} and { } D. {F → id} and {R → є}
[31] Consider the following translation scheme.
S → ER E → F + E {print (‘+’); | F
R → *E {print {‘*’); R |є F → (S) | id {print (id.value) ;}
Page | 7
Here id is a taken that represents an integer and id.value represents the corresponding integer
A. 2 * 3 + 4 C. 2 3 * 4 +
B. 2 * + 3 4 D. 2 3 4 + *
[32] The following table depicts Places for potential improvements (code optimizations) by the user and
the compiler. Choose the correct matching (pairing) from the following alternatives?
List of Optimization Types List of optimization level
X
o Profile program a. Compiler level at CG
o Change algorithm
o Transform loops
Y
o Improve loops b. Compiler Level at ICG
o Procedure calls
o Address calculations.
Z
o Use registers c. User Level
o Select instructions
o Do peephole transformations
A. X&a , Y&b, Z& c C. X&c , Y&b, Z& a
B. X&b , Y&a, Z& c D. X&a , Y&c, Z& b
Page | 8