Compiler Design QB - UNIT1
Compiler Design QB - UNIT1
PART A
Q.no. Question Page No. Level
1. Formulate The number of tokens in the following C statement :printf("i = %d, &i = %x", i, &i);
25 L3
a.3
b.26
c.10
d.21 Answer:c
2. In a compiler, keywords of a language are recognized during 21 L1
a.parsing of the program
b.the code generation
c.the lexical analysis of the program
d.dataflow analysis Answer: c
3. Analyse the lexical analysis for a modern computer language such as Java needs the power of which
one of the
following machine models in a necessary and sufficient sense? web L2
a.Finite state automata
b.Deterministic pushdown automata
c.Non-Deterministic pushdown automata
d.Turing Machine Answer: a
4. The lexical analyzer takes_________as input and produces a stream of_______as output. 21 L1
a) Source program,tokens
b)Token,source program
c)Either A and B
d)None of the above Answer:a
5. Resolution is externally defined symbols is performed by web L1
a)linker
b)loader
c)compiler
d)assembler Answer: a
6. Which of the following is used for grouping of characters into tokens? 21 L1
a) Parser
b) Code optimization
c) Code generator
d) Lexical analyzer Answer:d
7. Decide whether a given pattern constitutes a token or not depends on the 32 L2
a)Source language
b)Target language
c)Compiler
d) All of these Answer: c
8. Choose :A Compiler is 20 L3
a)A program that place program into memory and prepares them for execution
b)A program that automates the translation of assembly language into machine language
c)Aprogram that accepts program written in high level language and produces an object program
d)A program that appears to execute a source program as if it were machine language
Answer:c
9. Advantage of panic mode of error recovery is that 12 L2
a)It never gets into an infinite loop
b)It is simple to implement
c)Both A and B
d) None of these. Answer:c
10. In which way(s) a macroprocessor for assembly language can be implemented ? 14 L3
a) Independent two-pass processor
b) Independent one-pass processor
c)Expandmacrocalls and substitute arguments
d)All of the above Answer:d
11. Which of the following is used for grouping of characters into tokens (in a computer) 14 L1
a)A parser
b) Code optimizer
c) Code generator
d)Scanner Answer:d
12. A simple two-pass assembler does which of the following the first phase 13 L1
a) It allocates space for the literals.
b) It computes the total length of the program.
c) It builds the symbol table for the symbols and their values
d) All of above Answer: d
13. Convince :The translator is best described as 1 L3
a) Application software
b) A system software
c)A hardware component
d) All of the above Answer: b
37. What is the action of parsing the source program into proper syntactic classes? 5 L1
A. Lexical analysis
B. Syntax analysis
C. General syntax analysis
D. Interpretation analysis Answer: A
47. In a compiler, the data structure responsible for the management of information about variables and
their
attributes is 9 L1
a) Semantic stack
b) Parser table
c) Symbol table
d)Syntax tree Answer: C
48. The lexical analysis for java needs _____ in a necessary and sufficient sense. web L1
a)Turing machine
b)NPDA
c)DPDA
d)Finite state Automata Answer : D
49. Three Address code involves web L1
a) exactly 3 address
b)atleast 3 address
c)atmost 3 address
d)all the above Answer: C
50. Relocation bits used by relocating loader are specified by 3 L1
a)relocating loader itself
b)linker
c)assembler
d)macro processor Answer: B
PART B
Q.no. Question Page No. Level
1. What is translator? 1 L1
Translator is a kind of program which converts one form of source language into another
form of the target language.
Assembler and compiler are the two commonly used translators in operating systems.
2. What is an interpreter? 2 L1
An interpreter is a kind of translator which produces the results directly when the source
language and data is given to it as input.
It does not produce the object code rather each time the program needs execution
3. What is compiler? 20 L1
A compiler is a program that reads a program written in one language –the source language
and translates it into an equivalent program in another language-the target language.
The compiler reports to its user the presence of errors in the source program
S.N
O COMPILER INTERPERTER
A compiler reads the whole source An interpreter reads a statement from
1. code at the
once, creates tokens, checks input, converts it to an intermediate
semantics, code,
generates intermediate code, executes executes it, then takes the next
the statement in
whole program and may involve many sequence.
passes.
A compiler reads the whole program
2. even If an error occurs, an interpreter stops
if it encounters several errors. execution and reports it.
The interpreters do not produce object
3. The compilers produce object code code
Interpretation is less efficient than
4. Compiler is efficient than interpreter compiler
Different phases of compiler can be grouped together to form a front end and back end.
Front end consist of those phases that primarily dependent on the source language and
independent on the target language.
The front end consists of analysis part which includes lexical analysis, syntax analysis and
semantic analysis.
Back end consists of those phases that are totally dependent upon the target language and
independent on the source language.
It includes code generation and code optimization.
11. Classify the two parts of a compilation? Explain briefly. 4 L2
In synthesis part the intermediate form of the source language is taken and converted into an
equivalent target program.
During this process if certain code is to be optimized.
A symbol table is a data structure containing a record for each identifier, with fields for the
attributes of the identifier.
The data structure allows us to find the record for each identifier quickly and to store or
retrieve data from that record quickly.
Whenever an identifier is detected by a lexical analyzer, it is entered into the symbol table.
The attributes of an identifier cannot be determined by the lexical analyzer.
19. List the phases that constitute the front end of a compiler 12 L1
The front end consists of those phases or parts of phases that depends primarily on the source
language and is largely independent of the target machine. These include
Lexical and Syntactic analysis
The creation of symbol table
Semantic analysis
Generation of intermediate code
A certain amount of code optimization can be done by the front end as well. Also includes error
handling that goes along with each of these phases.
The back end of compiler includes those portions that depend on the target machine and
generally those portions do not depend on the source language, just the intermediate language.
These include
Code optimization
Code generation, along with error handling and symbol- table operations.
21. What does a semantic analysis do? 7 L1
Semantic analysis is one in which certain checks are performed to ensure that components of
a program fit together meaningfully.
Mainly performs type checking.
Linear analysis: The source string is read from left to right and grouped into tokens.
Hierarchical analysis: Characters or tokens are grouped hierarchically into nested collections
for checking them syntactically
Semantic analysis: It ensures the correctness of meaning of the program.
The assembler is a kind of translator which takes the assembly program as input and
produces the machine code as output.
The assembler converts the assembly program to low level machine language using two
passes.
A pass means one complete scan of the input program. The end of second pass is the
relocatable machine code.
24. Differentiate and describe loaders and link editors? 3 L2
Loader is a part of operating system and is responsible for loading executable files into
memory and executes them. It calculates the size of a program (instructions and data) and
creates memory space for it. It initializes various registers to initiate execution.
Linker is a computer program that links and merges various object files together in order to
make an executable file. All these files might have been compiled by separate assemblers.
25. Indicate the role of lexical analyzer? 32 L1
The lexical analyzer scans the source program and separates out the tokens from it.
26. Interpret the functions of lexical analyzer? 32 L2
It produces stream of tokens
It eliminates blank and comments
It generates symbol table which stores the information about identifiers , constants
encountered in the input.
It keep track of line numbers.
It reports the error encountered while generating the tokens.
32. Classify the possible error recovery actions in lexical analyzer? (Various possible error
recovery actions in lexical analyzer are, 34 L2
33. What is the input to lexical analyzer generator? What is its output? web L1
The lexical analyzer generator takes the source program as input and generates the stream
of tokens as output.
S.N
O Properties Meaning
1 r1 |r2=r2|r1 | is commutative
2 r1|(r2|r3)=(r1|r2)|r3 | is associative
Concatenation is
3 (r1r2)r3=r1(r2r3) associative
Concatenation is
4 R1(r2|r3)=r1r2|r1r3 distributive
(r2|r3)r1=r2r1|r3r1
5 Єr=Єr=r Є is identity
6 r*=(r|Є)* Relation between Є and *
7 r**=r* *Is idempotent
36. Write regular expression to describe the language consists of strings made of even numbers
a and b
Web L3
(11+00+(10+01)(11+00)\*(10+01))
37. Illustrate why buffering used in lexical analysis? What is the commonly used buffering
method?
35 L2
Because of the amount of time taken to process characters and the large number of characters
that must be processed during the compilation of a large source program, specialized buffering
techniques have been developed to reduce the amount of overhead required to process a single
input character.
Method:
One buffer scheme
Two buffer scheme
It represents the sequence of characters in the source program that are matched with pattern of
token.
39. Compare the features of DFA and NFA. 73 L2
PART C
Q.no. Question Page No. Level
1. Describe What is compiler? Explain the various phases of compiler in detail. 4 L1
2. Decide the output for the various phases of compiler with respect to following statements.
a=b+c*50.
a:=b+c*4. 26 L3
3. Discuss the various phases of a compiler in detail. Also write down the output for the following
expression after each phase. a:=b*c-d 10 L3
4. Predict and Explain in detail about the phases of compiler and translate the statement
pos:=init+rate*60
26 L3
5. Breakdown the grouping of phases (or) Describe how various phases could be combined as a
pass in a compiler. 12 L1
6. Summarize and explain the compiler construction tools. 14 L3
7. Write down the exclusive functions carried out by the analysis phases of any compiler. 5 L3
8. Briefly explain the cousins of compiler. 3 L1
9. Discuss the role of lexical analyzer in detail. 32 L1
10. Explain input buffering in detail (or) Write briefly on the issues in input buffering and how they
are
handled (or) Explain briefly about input buffering in reading the source program for finding the
tokens.
35 L1
11. Explain briefly the design of lexical analyzer. 65 L1
12. Draw the transition diagram for the following 71 L3
To represent relational operators.
To represent unsigned numbers.
13. Give the minimized DFA for the following expression. (a/b)*abb 44 L3
14. Prove the following two regular expressions are equivalent by showing the minimum state
DFA’s are same.
i) (a/b)* ii) (a*/b*) 46 L3
15. Illustrate Thomson’s construction by drawing a NFA for the regular expression (a/b)*a. Convert
this NFA to DFA using subset construction. Write the algorithm for subset construction.
46 L3
16.Construct the minimized DFA for the regular expression (0+1)*(0+1)10. web L3
17. Explain the design of lexical analyzer using LEX. 63 L1
18. Explain specification and recognition of tokens. 37 L1