You are on page 1of 3

NAME: ADEIYE OLATUNJI VICTOR

MATRIC NO:15/69/0072
LEVEL: HND II PT

Question 1
Write a short note on Compiler Writing tools.

A compiler is a computer program which helps you transform source code written in a high-level
language into low-level machine language. It translates the code written in one programming language
to some other language without changing the meaning of the code. The compiler also makes the end
code efficient which is optimized for execution time and memory space.

The compiling process includes basic translation mechanisms and error detection. Compiler process
goes through lexical, syntax, and semantic analysis at the front end, and code generation and
optimization at a back-end.
Question 2
Explain briefly on the two parts of compilation.

Analysis and Synthesis are the two parts of compilation.

The analysis part breaks up the source program into constituent pieces and creates an intermediate
representation of the source program.

The synthesis part constructs the desired target program from the intermediate representation.
Question 3
Explain briefly on the phases of compilation process.

Phase 1: Lexical Analysis


Lexical Analysis is the first phase when compiler scans the source code. This process can be left to right,
character by character, and group these characters into tokens.

Here, the character stream from the source program is grouped in meaningful sequences by identifying
the tokens. It makes the entry of the corresponding tickets into the symbol table and passes that token
to next phase.

The primary function of this phase are:-

I. Identify the lexical units in a source code.


II. Classify lexical units into classes like constants, reserved words, and enter them in different
tables. It will Ignore comments in the source program.
III. Identify token which is not a part of the language.

Phase 2: Syntax Analysis


Syntax analysis is all about discovering structure in code. It determines whether or not a text follows the
expected format. The main aim of this phase is to make sure that the source code was written by the
programmer is correct or not.
Syntax analysis is based on the rules based on the specific programing language by constructing the
parse tree with the help of tokens. It also determines the structure of source language and grammar or
syntax of the language.

Here, is a list of tasks performed in this phase:

I. Obtain tokens from the lexical analyzer.


II. Checks if the expression is syntactically correct or not
Report all syntax errors.

Phase 3: Semantic Analysis


Semantic analysis checks the semantic consistency of the code. It uses the syntax tree of the previous
phase along with the symbol table to verify that the given source code is semantically consistent. It also
checks whether the code is conveying an appropriate meaning.

Semantic Analyzer will check for Type mismatches, incompatible operands, a function called with
improper arguments, an undeclared variable, etc.

Functions of Semantic analyses phase are:

I. Helps you to store type information gathered and save it in symbol table or syntax tree
II. Allows you to perform type checking
In the case of type mismatch, where there are no exact type correction rules which satisfy the desired
operation a semantic error is shown.

Phase 4: Intermediate Code Generation


Once the semantic analysis phase is over the compiler, generates intermediate code for the target
machine. It represents a program for some abstract machine.

Intermediate code is between the high-level and machine level language. This intermediate code needs
to be generated in such a manner that makes it easy to translate it into the target machine code.

Functions on Intermediate Code generation:

I. It should be generated from the semantic representation of the source program.


II. Holds the values computed during the process of translation.
III. Helps you to translate the intermediate code into target language.
Question 4
Differentiate: (a) Linker and Loader (b) Analysis phase and Synthesis phase.
Linker and loader:-
(a) The key difference between linker and loader is that the linker generates the executable file of a
program whereas, the loader loads the executable file obtained from the linker into main
memory for execution.
(b) The linker intakes the object module of a program generated by the assembler. However, the
loader intakes the executable module generated by the linker.
(c) The linker combines all object module of a program to generate executable modules it also links
the library function in the object module to built-in libraries of the high-level programming
language. On the other hands, loader allocates space to an executable module in main memory.
(d) The linker can be classified as linkage editor, and dynamic linker whereas loader can be classified
as absolute loader, relocatable loader and dynamic run-time loader.
Analysis and synthesis phase:-
Analysis phase creates an intermediate representation from the given source code. Synthesis phase
creates an equivalent target program from the intermediate representation.
Question 5
What phases constitutes the front end and back end of a compiler?

The phases of a compiler are collected into front end and back end. The front end includes all analysis
phases end the intermediate code generator. The back end includes the code optimization phase and
final code generation phase.

You might also like