You are on page 1of 3

Introduction to Compiling

Definition: A compiler is a program that translates a high-


level language program into a functionally equivalent low
level language program. Basically, it is a translator whose
source language (the language to be translated) is a high-
level language, and the target language (the language into
which the source language is to be translated) is a low-level
language. In other words, a compiler is used to implement a
high-level language on a computer.

analysis of the source program


two parts of compilation:
1. Analysis of source program
2. Synthesis of source program

Source Analysis Synthesis Target



program phase phase program

1. Lexical Analysis: It determines the lexical constituents in


the source string by reading the stream of characters
from left to right and grouping them into tokens. A
token is a sequence of characters having a collective
meaning.
2. Syntax Analysis: It determines the structure of the source
string by grouping them into nested collections with
collective meaning.

3. Semantic Analysis: It determines the meaning of source


string and ensures that components of a program fit together
meaningfully.

The synthesis step consists of two phases.

1. Code Optimization: It tries to improve the intermediate


code to achieve a faster running machine code.

2. Code Generation: It generates the target code. Memory


allocations are done for each of the variables used by the
program. Intermediate instructions are then translated into a
sequence of machine instructions.

the phases of a compiler


the grouping of phases, Compiler Construction tools, A
simple one-pass compiler.

You might also like