Compiler Design Question Bank - Unit I
Compiler Design Question Bank - Unit I
DEPARTMENTOFCOMPUTERSCIENCEAND ENGINEERING
PART-A(1-MARKS)
1. What is a compiler?
a) System program that converts instructions to machine language
b) System program that converts machine language to high-level language
c) System program that writes instructions to perform
d) None of the mentioned
ANSWER:A
5. A programmer, writes a program to multiply two numbers instead of dividing them by mistake, how
can this error be detected?
a) Compiler or interpreter
b) Compiler only
c) Interpreter only
d) None of the mentioned
ANSWER:D
8. Which of the following is a part of a compiler that takes as input a stream of characters and produces
as output a stream of words along with their associated syntactic categories?
a) Optimizer
b) Scanner
c) Parser
d) None of the mentioned
ANSWER:B
12.Characters are grouped into tokens in which of the following phase of the compiler design?
a) Code generator
b) Lexical analyzer
c) Parser
d) Code optimization
ANSWER:B
13. A language L from a grammar G = { VN, Σ, P, S} is?
a) Set of symbols over VN
b) Set of symbols over Σ
c) Set of symbols over P
d) Set of symbols over S
ANSWER:A
17.Given an arbitrary non-deterministic finite automaton (NFA) with N states, the maximum number
of states in an equivalent minimized DFA is at least?
a) N2
b) 2N
c) 2N
d) N!
ANSWER:C
18.What can be said about a regular language L over {a} whose minimal finite state automaton has two
states?
a) L must be {an| n is odd}
b) L must be {an| n is even}
c) L must be {an| n is even}
d) Either L must be {an | n is odd}, or L must be {an | n is even}
ANSWER:D
19.How many minimum states are required to find whether a string has odd number of 0’s or not?
a) 1
b) 2
c) 3
d) 4
ANSWER:B
20.Consider the languages L1 = and L2 = {a}. Which one of the following represents L1 L2* U L1*?
a) €
b) a*
c) All of the mentioned
d) None of the mentioned
ANSWER:A
PART-B(2-MARKS)
1. Define Token.
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. What is a Complier?
A Complier is a program that reads a program written in one language-the source language-and translates
it in to an equivalent program in another language-the target language. As an important part of this
translation process, the compiler reports to its user the presence of errors in the source program.
4. What is an interpreter?
Interpreter is a program which converts source language to machine language line by line. No
intermediate object code is generated, hence are memory efficient. Ex: Python, COBOL.
A cross compiler is a compiler capable of creating executable code for a platform other than the one on
which the compiler is run. (ie).A compiler may run on one machine and produce target code for another
machine.
7. What are the four obsoletes of quality What are the main two parts of compilation? What
are they performing?
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.
8. State some compiler construction tools?
a. Parse generator
b. Scanner generators
c. Syntax-directed
d. Translation engines
e. Automatic code generator
f. Dataflow 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 does the Link Editing does?
Link editing: This allows us to make a single program from several files of relocatable machine code.
These files may have been the result of several compilations, and one or more may be library files of
routines provided by the system and available to any program that needs them.
11.What is a preprocessor?
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
sometimes entrusted to a distinct program called a preprocessor. The preprocessor may
also expand macros into source language statements.
12.Statesomefunctionsof Preprocessors
i) Macro processing
ii) File inclusion
iii) Relational Preprocessors
iv) Language extensions
16. List the phases that constitute the front end of a compiler.
The front end consists of those phases or parts of phases that depend primarily on the source language
and are 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 frontend as well includes error handling that
goes along with each of these phases.
19. What is the main difference between phase and pass of a compiler?
A phase is a subprocess of the compilation process whereas combination of one or more phases into a
module is called pass.
The error handler is invoked when a flaw in the source program is detected. It must warn the
programmer by issuing a diagnostic, and adjust the information being passed from phase to phases of that
each phase can proceed. So that as many errors as possible can be detected in one compilation.
22.Write short notes on symbol table manager?
The table management or bookkeeping portion of the compiler keeps track of the names used by program
and records essential information about each, such as its type (int, real etc.,) the data structure used to record
this information is called a symbol table manger.
24. What is a regular expression? State the rules, which define regular expression?
Regular expression is a method to describe regular Language Rules:
1) €-is a regular expression that denotes {€}that is the set containing the empty string
If a is a symbol in ∑,then aisa regular expression thatdenotes{a}
2)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 ).
e)
25.Write regular expression to describe a languages consist of strings made of even numbers a and b.
((a+b)(a+b))*
30.Define NFA.
A NFA accepts a string x, if and only if there is a path from the starting state to one of accepting states
such that edge labels along this path spell out x. ε- transitions are allowed in NFAs. In other words, we
can move from one state to another one without consuming any symbol.
31.What is a finite automata?
A recognizer for a language is a program that takes a string x, and answers “yes” if x is a sentence of
that language, and “no” otherwise.
32.ConstructRegularexpressionforthelanguageL={wε{0,1}/wconsistsofodd numberof0’s}
RE=0(001)*11
33.DifferentiateNFAandDFA.
NFA DFA
NFA or Non Deterministic Deterministic Finite
Finite Automaton is the one in Automaton is a FA in
which there exists many paths which there is only one
for a specific input from path for a specific input
current state to next state. from current state to next
state. There is a unique
transition on each input
symbol.
1.What are the various phases of a compiler? Explain each phase in detail by using the input
“a=(b+c)*(b+c)*2”.
2. Explain the various Compiler Construction Tools.
3.i) What are the cousins of a Compiler? Explain them in detail.
ii) Explain the need for grouping of phases of compiler.
4. For the following expression: Position: =initial+ rate*60.Write down the output after each phase.
5. i)Analyze the given expressions4:*+=cba with different phases of the compiler
ii) Classify the concepts of compiler and Interpreter.
6. i)Describe the errors encountered in different phases of compiler.
ii)Explain the functions of Preprocessor.
7.i) Explain Input Buffering with example.
ii) Discuss about the recognition of tokens with example
8. Explain the role of Lexical Analyzer in detail with necessary examples.
9. Discuss how finite automata is used to represent tokens and perform lexical analysis with examples.
10. Write an algorithm to convert NFA to DFA and minimize DFA. Give an example.
11. Minimize the following states of DFA
12. Prove that the following two regular expressions are equivalent by showing that the minimum state
DFA's are same :
( a/ b ) *
( a* / b * ) *