You are on page 1of 27

Compiler Design

2170701 Unit-1

UNIT -1
Introduction to Compiler
1. TRANSLATORS
A translator is one kind of program that takes one form of program (input) and
converts into another form (output). The input program is called source language
and the output program is called target language.
The source language can be high level language like C, C++, JAVA, FORTRAN,
and so on.
The target language can be a low level language (assembly language) or a
machine language (set of instructions executed directly by a CPU).

Figure 1.1. Translators


Types of Translators are:

(1). Compilers

(2). Interpreters

(3). Assemblers

COMPILER:-

Compiler is a translator program that translates a program written in source


program (High level language-HLL) and translates it into an equivalent
program in target program (Machine level language-MLL). As an important
part of a compiler is error showing to the programmer.
Source program target program
Compiler

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Error massage

Figure 1.2. A Compiler


Executing a program written n HLL programming language is basically of
two parts. The source program must first be compiled translated into a object
program.
An important role of the compiler is to report any errors in the source program
that it detects during the translation process.
If the target program is an executable machine-language program, it can then
be called by the user to process inputs and produce outputs.
It executes the whole program and then displays the errors.
Example: C, C++, COBOL, higher version of Pascal.

Figure 1.3: Running the target program


Interpreter:

It is one of the translators that translate high level language to low level
language.
An interpreter is another common kind of language processor. Instead of
producing a target program as a translation, an interpreter appears to directly
execute the operations specified in the source program on inputs supplied by
the user, as shown in Figure 1.4.

Figure 1.4: An interpreter


The machine-language target program produced by a compiler is usually
much faster than an interpreter (mapping inputs to outputs is easy in
compiler).
Compiler converts the source to target completely, but an interpreter executes
the source program statement by statement.
Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Usually interpreter gives better error diagnostics than a Compiler.
Example: Basic, Lower version of Pascal.
Assembler:
Programmers found it difficult to write or read programs in machine
language.
They begin to use a mnemonic (symbols) for each machine instruction,
which they would subsequently translate into machine language. Such a
mnemonic machine language is now called an assembly language.
Programs known as assembler were written to automate the translation of
assembly language in to machine language.
The input to an assembler program is called source program, the output is a
machine language translation (object program).

Figure 1.5: Assembler


There are two types of assemblers based on how many passes through the source
are needed to produce the executable program.

One-pass assemblers go through the source code once and assume that all
symbols will be defined before any instruction that references them.
Two-pass assemblers create a table with all symbols and their values in the
first pass, and then use the table in a second pass to generate code. The
assembler must at least be able to determine the length of each instruction on
the first pass so that the addresses of symbols can be calculated.
Example: Microprocessor 8085, 8086.

Hybrid Compiler
Hybrid Compiler is combination of compilation and interpretation.
Java language processors combine compilation and interpretation as shown in
Figure 1.6.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Java source program first be compiled into an intermediate form called bytecodes.
The byte codes are then interpreted by a virtual machine.
A benefit of this arrangement is that bytecodes compiled on one machine can be
interpreted on another machine.

Figure 1.6: A hybrid compiler

In order to achieve faster processing of inputs to outputs, some Java compilers,


called justin-time compilers, translate the bytecodes into machine language
immediately before they run.

Difference between compiler and interpreter:

Compiler Interpreter
Scans the entire program and translates it Translates program one statement
as a whole into machine code. at a time.

It is a translator that translates high level It is a translator that translates high


to low level language level to low level language.
Intermediate Object Code is Generated No Intermediate Object Code
is Generated
It takes large amount of time to analyze It takes less amount of time to
the source code but the overall execution analyze the source code but the
time is comparatively faster. overall execution time is slower.
It displays the errors after the whole It checks line by line for errors.
program is executed.
Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
A compiled language is more dificult to Debugging is easy because
debug. interpreter stops and reports errors
as it encounter them.
Examples of programming languages that Examples of programming
use compilers: C, C++, COBOL languages that use interpreters:
BASIC, Visual Basic,Python,
Ruby, PHP, Perl, MATLAB, Lisp
It requires large space in the computer. Interpreter is easy to write and do
not require large memory space in
the computer.

Save machine code for future use. Doesnt store translated statements.

2. OVERVIEW OF LANGUAGE PROCESSING SYSTEM


In addition to a compiler, several other programs may be required to create an
executable target program, as shown in Figure 2.1.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Figure 2.1: A language-processing system
Note: Preprocessors, Assemblers, Linkers and Loader are collectively called cousins of
compiler

Preprocessor:
A preprocessor is a program that processes its input data (source program) to produce
output that is used as input to another program. The output is said to be a modified source
program. A preprocessor produce input to compilers. They may perform the following
functions.
1. Macro processing: A preprocessor may allow a user to define macros that are
short hands for longer constructs. macro definitions (#define, #undef)
2. File inclusion: A preprocessor may include header files into the program text.
When the preprocessor finds #include directive it replaces it by the entire
content of the specified file. #include <file>

3. Rational preprocessor: these preprocessors augment older languages with more


modern flow-of-control and data structuring facilities. For example, such a
preprocessor might provide the user with built-in macros for constructs like
while-statements or if-statements, where none exist in the programming language
itself.
4. Language Extensions: These preprocessor attempts to add capabilities to the
language by certain amounts to build-in macro. For example, the language Equal
is a database query language embedded in C.
Compiler:
The modified source program is then fed to a compiler. The compiler may produce an
assembly-language program as its output. because assembly language is easier to produce
as output and is easier to debug.
Assembler:
The assembly language is then processed by a program called an assembler that produces
relocatable machine code as its output.
One-pass assemblers go through the source code once and assume that all symbols will
be defined before any instruction that references them.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Two-pass assemblers create a table with all symbols and their values in the first pass, and
then use the table in a second pass to generate code.
LINKER:
Large programs are often compiled in pieces, so the relocatable machine code may have
to be linked together with other relocatable object files and library files into the code that
actually runs on the machine.
Three tasks of the linker are :
1. Searches the program to find library routines used by program, e.g. printf(), math
routines.
2. Determines the memory locations that code from each module will occupy and
relocates its instructions by adjusting absolute references
3. Resolves references among files.
LOADER:
The loader then puts together the entire executable object files into memory for
execution. It also performs relocation of an object code. A loader is the part of an
operating system that is responsible for loading programs in memory, one of the essential
stages in the process of starting a program.
Linker & Loader produce absolute machine code.

3. THE PHASES OF COMPILER / STRUCTURE OF COMPILER:


There are 2 parts to compilation:
a. Analysis (Machine Independent/Language Dependent)
b. Synthesis (Machine Dependent/Language independent)
Analysis part breaks down the source program into constituent pieces and creates
an intermediate representation of the source program.
The analysis part also collects information about the source program and stores it
in a data structure called a symbol table, which is passed along with the
intermediate representation to the synthesis part.
The analysis part carried out in four phases, they are lexical analysis, syntax
analysis, Semantic Analysis and intermediate code generator.
The analysis part is often called the front end of the compiler.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Synthesis part constructs the desired target program from the intermediate
representation.
The synthesis part carried out in two phases, they are in Code Optimization and
Code Generation. The synthesis part is called the back end of the compiler.

Figure 3.1: Phases of a compiler

A Compiler operates in phases, each of which transforms the source program from one
representation into another. The following are the phases of the compiler:
Main phases:
1) Lexical analysis
2) Syntax analysis
3) Semantic analysis
4) Intermediate code generation
5) Code optimization
6) Code generation
LEXICAL ANALYSIS:

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
The first phase of a compiler is called lexical analysis or scanning or linear
analysis.
The lexical analyzer reads the stream of characters making up the source program
and groups the characters into meaningful sequences called lexemes.
For each lexeme, the lexical analyzer produces output as a token.
For example, suppose a source program contains the assignment statement
position = initial + rate * 60 3.1
The characters in this assignment statement could be grouped into the following
lexemes and mapped into the following tokens.
(1) position is a lexeme that would be mapped into a token < id1 >. Where id1 is
an abstract symbol standing for identifier.
(2) The assignment symbol = is a lexeme that is mapped into the token < = >.
(3) initial is a lexeme that is mapped into the token < id2 >.
(4) + is a lexeme that is mapped into the token < + >.
(5) rate is a lexeme that is mapped into the token < id3 >.
(6) * is a lexeme that is mapped into the token < * >.
(7) 60 is a lexeme that is mapped into the token < 60 >.
Blanks separating the lexemes would be discarded by the lexical analyzer. The
sequence of tokens produced as follows after lexical analysis.
Id1 = id2 + id3 * 60 3.2
Syntax Analysis
It is called parsing or hierarchical analysis. It involves grouping the tokens of the
source program into grammatical phrases that are used by the compiler to
synthesize output.
They are represented using a syntax tree as shown below:

Figure 3.2: Syntax tree for position = initial + rate * 60

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
A syntax tree is the tree generated as a result of syntax analysis in which the
interior nodes are the operators and the exterior nodes are the operands.
This analysis shows an error when the syntax is incorrect.

Semantic Analysis :
It is the third phase of the compiler.
The semantic analyzer uses the syntax tree and the information in the symbol
table to check the source program for semantic consistency with the language
definition.
It checks the source programs for semantic errors and saves it in either the syntax
tree or the symbol table, for subsequent use during intermediate-code generation.
An important part of semantic analysis is type checking, where the compiler
checks that each operator has matching operands.
For example, many programming language definitions require an array index to
be an integer; the compiler must report an error if a floating-point number is used
to index an array.

Figure 3.3: Semantic tree for position = initial + rate * 60

Suppose that position, initial and rates have been declared to be floating-point
numbers, and that the lexeme 60 by itself forms an integer.
The type checker in the semantic analyzer discovers that the operator * is applied
to a floating-point number rate and an integer 60.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
In this case, the integer may be converted into a floating-point number. In Fig.
3.3, notice that the output of the semantic analyzer has an extra node for the
operator inttofloat, which explicitly converts its integer argument into a floating-
point number.

Intermediate Code Generation


After syntax and semantic analysis of the source program, many compilers
generate an explicit low-level or machine-like intermediate representation.
The intermediate representation has two important properties:
a. It should be easy to produce
b. It should be easy to translate into the target machine.
Three-address code is one of the intermediate representations, which consists of a
sequence of assembly-like instructions with three operands per instruction. Each
operand can act like a register.
The output of the intermediate code generator consists of the three-address code
sequence for position = initial + rate * 60
t1 = inttofloat(60)
t2 = id3 * t1
t3 = id2 + t2
id1 = t3 3.3

Code Optimization
The machine-independent code-optimization phase attempts to improve the
intermediate code so that better target code will result. Usually better means
faster.
Optimization has to improve the efficiency of code so that the target program
running time and consumption of memory can be reduced.
The optimizer can deduce that the conversion of 60 from integer to floating point
can be done once and for all at compile time, so the inttofloat operation can be
eliminated by replacing the integer 60 by the floating-point number 60.0.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Moreover, t3 is used only once to transmit its value to id1 so the optimizer can
transform (eq.3.3) into the shorter sequence
t1 = id3 * 60.0
id1 = id2 + t1 3.4

Code Generation
The code generator takes as input an intermediate representation of the source
program and maps it into the target language.
If the target language is machine code, then the registers or memory locations are
selected for each of the variables used by the program.
The intermediate instructions are translated into sequences of machine
instructions.
For example, using registers R1 and R2, the intermediate code in (3.4) might get
translated into the machine code
LDF R2, id3
MULF R2, R2 , #60.0
LDF Rl, id2
ADDF Rl, R2
STF idl, Rl 3.5
The first operand of each instruction specifies a destination. The F in each
instruction tells us that it deals with floating-point numbers.
The above code loads the contents of address id3 into register R2, and then
multiplies it with floating-point constant 60.0. The # signifies that 60.0 is to be
treated as an immediate constant.
The third instruction moves id2 into register R1 and the fourth adds to it the value
previously computed in register R2.
Finally, the value in register R1 is stored into the address of id1, so the code
correctly implements the assignment statement (eq. 3.1).

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1

Figure.3.4: Translation of statement a=b+c*2.

Symbol-Table Management
The symbol table, which stores information about the entire source program, is
used by all phases of the compiler.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
An essential function of a compiler is to record the variable names used in the
source program and collect information about various attributes of each name.
These attributes may provide information about the storage allocated for a name,
its type, its scope.
In the case of procedure names, such things as the number and types of its
arguments, the method of passing each argument (for example, by value or by
reference), and the type returned are maintained in symbol table.
The symbol table is a data structure containing a record for each variable name,
with fields for the attributes of the name. The data structure should be designed
to allow the compiler to find the record for each name quickly and to store or
retrieve data from that record quickly.
A symbol table can be implemented in one of the following ways:
Linear (sorted or unsorted) list
Binary Search Tree
Hash table
Among the above all, symbol tables are mostly implemented as hash tables,
where the source code symbol itself is treated as a key for the hash function and
the return value is the information about the symbol.
A symbol table may serve the following purposes depending upon the language
in hand:
To store the names of all entities in a structured form at one place.
To verify if a variable has been declared.
To implement type checking, by verifying assignments and
expressions.
To determine the scope of a name (scope resolution).

ERRORS ENCOUNTERED IN DIFFERENT PHASES


An important role of the compiler is to report any errors in the source program
that it detects during the entire translation process.
Each phases of compiler can encounter errors, after detecting errors, must be
corrected to precede compilation process.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
The syntax and semantic phases handles large number of errors in compilation
process.
Error handler handles all types of errors like lexical errors, syntax errors, semantic
errors and logical errors.
Lexical errors:
Lexical analyzer detects errors from input characters.
Name of some keywords identifiers typed incorrectly.
Example: switch is written as swich.
Syntax errors:
Syntax errors are detected by syntax analyzer.
Errors like semicolon missing or unbalanced parenthesis.
Example: ((a+b* (c-d)). In this statement ) missing after b.
Semantic errors:
Data type mismatch errors handled by semantic analyzer.
Incompatible data type value assignment.
Example: Assigning a string value to integer.
Logical errors:
Code note reachable and infinite loops.
Misuse of operators. Codes written after end of main() block.

4. GROUPING OF THE PHASES


Compiler can be grouped into front and back ends:
Front end: analysis (machine independent)
These normally include lexical and syntactic analysis, the creation of the symbol
table, semantic analysis and the generation of intermediate code. It also includes error
handling that goes along with each of these phases.

Back end: synthesis (machine dependent)


It includes code optimization phase and code generation along with the necessary
error handling and symbol table operations.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1

Figure 4.1: The Grouping of Phases of compiler

There are a few advantages.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
1. Helps focus on the problem. Compilation is quite a complex task. Hence
separating it into stages makes it easier and helps to focus on the problem. It also
makes it easier to engineer and have different teams focus on each part.
2. Makes it modular. The frontend is specific to the source language and the backend
is specific to the target machine. An issue of the target architecture does not show
up in the frontend and an issue of the source language does not show up in the
backend. If someone comes up with a better frontend then he/she can replace the
frontend without any changes to the backend. Same with backend.
3. Makes it portable across languages and architecture. The intermediate code is
independent of the source language and the machine code. Hence the compiler
can easily be ported to different source language (by writing a different frontend)
and target architecture(by writing a different backend).
Compiler passes
A collection of phases is done only once (single pass) or multiple times (multi
pass)
Single pass:
Usually requires everything to be defined before being used in source
program.
Multi pass:
Compiler may have to keep entire program representation in memory.
Several phases can be grouped into one single pass and the activities of
these phases are interleaved during the pass. For example, lexical analysis,
syntax analysis, semantic analysis and intermediate code generation might
be grouped into one pass.
Difference:
1. A one-pass compilers is faster than multi-pass compilers. Multi - pass
compiler is slower than a single pass compiler because each pass reads &
writes an intermediate file.
2. A one-pass compiler has limited scope of passes but multi-pass compiler has
wide scope of passes.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
3. Multi-pass compilers are sometimes called wide compilers where as one-pass
compiler are sometimes called narrow compiler.
4. Single pass compiler can be made to use more space than multi-pass compiler
whereas Multi - pass compiler can be made to use less space than a single -
pass compiler.
5. Single pass compiler is not portable where as multipass compiler supports
portability.
6. Many programming languages cannot be represented with single pass
compilers, for example Pascal can be implemented with a single pass compiler
where as languages like Java require a multi-pass compiler.

5. Explain linker and loader in details.


Linker:
In high level languages, some built in header files or libraries are stored.
These libraries are predefined and these contain basic functions which are
essential for executing the program.
These functions are linked to the libraries by a program called Linker.
If linker does not find a library of a function then it informs to compiler and then
compiler generates an error.
The compiler automatically invokes the linker as the last step in compiling a
program.
Not built in libraries, it also links the user defined functions to the user defined
libraries. Usually a longer program is divided into smaller subprograms called
modules.
And these modules must be combined to execute the program.
The process of combining the modules is done by the linker.
Loader:
Loader is a program that loads machine codes of a program into the system
memory.
In Computing, a loader is the part of an Operating System that is responsible for
loading programs.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
It is one of the essential stages in the process of starting a program. Because it
places programs into memory and prepares them for execution.
Loading a program involves reading the contents of executable file into memory.
Once loading is complete, the operating system starts the program by passing
control to the loaded program code.
All operating systems that support program loading have loaders. In many
operating systems the loader is permanently resident in memory.

6. Software tools used in Analysis part:


1) Structure editor:
Takes as input a sequence of commands to build a source program.
The structure editor not only performs the text-creation and modification
functions of an ordinary text editor, but it also analyzes the program text, putting
an appropriate hierarchical structure on the source program.
For example , it can supply keywords automatically - while . do and begin..
end.
2) Pretty printers:
A pretty printer analyzes a program and prints it in such a way that the structure
of the program becomes clearly visible.
For example, comments may appear in a special font.
3) Static checkers:
A static checker reads a program, analyzes it, and attempts to discover potential
bugs without running the program.
For example, a static checker may detect that parts of the source program can
never be executed.
4) Interpreters:
Translates from high level language (BASIC, FORTRAN, etc.) into machine
language.
An interpreter might build a syntax tree and then carry out the operations at the
nodes as it walks the tree.
Interpreters are frequently used to execute command language since each operator
Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
Executed in a command language is usually an invocation of a complex routine
such as an editor or complier.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1

Assignment-1
Introduction to Compiler
1. What is compiler? List major functions done by compiler.
2. Differentiate compiler, interpreter and Assembler.
3. Explain the analysis synthesis model of compilation. List the factors that affect the
design of compiler. Or (explain structure of compiler.) Or (Draw different phases
of Compiler with example. Also explain all Phase in brief. )
4. Find errors and identify the phase of compiler detecting them for following C
program segment. Justify your answers.
int fi( int);
char a[10], * cptr;
int k = 1 ;
int j = 2;
float f;
cptr = a;
if (k);
fi(k);
fi( j )
++k;
*(cptr + 1 ) = 0 ;
++ a;
n + *k ;
5. Explain cousins of compiler or context of compiler.
6. What is a symbol table? Discuss any two data structures suitable for it & compare
their merits / demerits. Also compare one pass & two pass compilers.
7. Explain linker and loader in details.
8. Differentiate single pass and multi-pass compiler.
9. Explain front end and back end in details.

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1

Objective Type questions (1/2 Marks)


1. List the various phases of a compiler.
2. Mention some of the cousins of a compiler.
3. List the subparts or phases of analysis part.
4. Define Following Term:
Compiler, Interpreter, Assembler, Cross Compiler, Hybrid Compiler, Linker,
Loader, Symbol table, Preprocesser
5. List the phases that constitute the front end of a compiler.
6. Mention the back-end phases of a compiler.
7. List the various compiler construction tools.
8. What does a semantic analysis do?
10. Is macro processing a phase in compilation? Justify your answer.
11. Write three address code for the expression r := 9*2+7.
12. __________ is a program that reads a program written in one language and
translates it into an equivalent program in another language.

13. What does the front end of a compiler do?


14. The lexical analyzer takes_________as input and produces a stream of_______as
output.
a) Source program, tokens
b) Token,source program
c) Either A and B
d) None of the above
15. The linker
a) is similar to interpreter
b) uses source code as its input
c) is required to create a load module
d) none of the above
16. Intermediate code generation phase gets input from
a) Lexical analyzer
b) Syntax analyzer
c) Semantic analyzer
Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
d) Error handling
17. Translator for low level programming language were termed as
(A) Assembler
(B) Compiler
(C) Linker
(D) Loader
18. The translator which perform macro expansion is called a
(A) Macro processor
(B) Macro pre-processor
(C) Micro pre-processor
(D) Assembler

19. An assembler is

(A) programming language dependent.

(B) syntax dependant.

(C) machine dependant.

(D) data dependant.

20. An analysis, which determines the syntactic structure of the source statement, is
called

(A) Semantic analysis


(B) process analysis
(C) Syntax analysis
(D) function analysis

21. Which of the following are language processors?

(A) Assembler (B) Compiler (C) Interpreter (D) All of the above

22. A system program that combines separately compiled modules of a program into a
form suitable for execution is __________
(A) Assembler
Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
(B) Linking loader
(C) Linker
(D) None of the Above

23. A compiler that runs on a particular platform and is capable of generating executable
code for another platform is called a _______
A. Assembler
B. Linking loader
C. Loader
D. Cross-Compiler

24. Which of the following is/ are parts of compilation

A. Analysis
B. Synthesis
C. Analysis & Synthesis
D. None of above
25. Comments may appear in a special font is an example of
A. Structure Editor
B. Pretty printers
C. Static checker
D. Interpreter
26. Certain variables might be used before being defined is an example of
A. Structure Editor
B. Pretty printers
C. Static checker
D. Interpreter
27. Which of the following may detect that parts of the program can never be
executed?
A. Structure Editor
B. Pretty printers
C. Static checker
Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
D. Interpreter
28. Analysis of source program consist of
A. Linear analysis
B. Hierarchical analysis
C. Semantic analysis
D. All of above
29. Output of compiler is
A. Source program
B. Relocatable machine code
C. Target assembly program
D. Absolute machine code
30. Output of Assembler is
a. Source program
b. Relocatable machine code
c. Target assembly program
d. Absolute machine code
31. Output of preprocessor is
a. Source program
b. Relocatable machine code
c. Target assembly program
d. Absolute machine code
32. In which phase identifiers entered into the symbol table?
a. Lexical Analysis
b. Syntax Analysis
c. Semantic Analysis
d. Intermediate Code Generation
33. Which of the following are compiler construction tools?
a. Parser generators
b. Scanner generators
c. Data flow engines
d. All of above

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar
Compiler Design
2170701 Unit-1
34. Which of the following is a phase of compilation
a. Lexical Analysis
b. Code generation
c. Static analysis
d. Both a & b
35. An ideal compiler should
a. Detect error
b. Detect & repair error
c. Detect, repair & correct error
d. None of these
36. Which of the following is/are phases of analysis
a. Lexical Analysis
b. Code generation
c. Code optimization
d. None of above
37. Which of the following phase of compilation process is an optional phase.
a. Lexical analysis
b. Syntax analysis
c. Code optimization
d. Code generation

Prepared By:
Prof. Ankita Chauhan
CE Department
MBICT-New Vvnagar

You might also like