Life Cycle of Source Program Compiler Design
Life Cycle of Source Program Compiler Design
Abstract: This Research paper gives brief information on how the source program gets evaluated and from which
sections source code has to pass and parse in order to generate target code or predicted output. In addition to that, this
paper also explains the concept of Pre-processors, Translators, Linkers and Loaders and procedure to generate target
code. This paper concentrates on Concept of Compiler and Phases of Compiler.
Keywords: Macro; Token; Lexemes; Identifier; Operators; Operands; Sentinel; Prefix; Postfix; Quadruple; Triple;
Indirect triple; Subroutine
I. INTRODUCTION
Whenever we create a source code and start the process of evaluating it, computer only shows the output and errors (if
occurred). We don’t know the actual process behind it. In this research paper, the exact procedure behind the
compilation task and step by step evaluation of source code are explained. In addition to that touched topics are High
level languages, Low level languages, Pre-processors, Translators, Compilers, Phases of Compiler, Cousins of
Compiler, Assemblers, Interpreters, Symbol Table, Error Handling, Linkers and Loaders [1].
IV. PRE-PROCESSORS
Pre-processor is a computer program that manipulates its input data in order to generate output which is ultimately used
as input to some other program or compiler. Input of pre-processor is high level languages and output of pre-processor
is pure high level languages. Pure high level language refers to the language which is having Macros in the program
and File Inclusion. Macro means some set of instructions which can be used repeatedly in the program. Macro pre-
processing task is done by pre-processor. Pre-processor allows user to include header files which may be required by
program known as File Inclusion. Example: # defines PI 3.14 shows that whenever PI encountered in a program, it is
replaced by 3.14 values (Figure 1).
V. TRANSLATORS
Translator is a program that takes input as a source program and converts it into another form as output. Translator
takes input as a high level language and convert it into low level language [2]. There are mainly three types of
translators (Figure 2).
1) Compilers
2) Assemblers
3) Interpreters
Figure 2: Translators.
VI. COMPILERS
Compiler reads whole program at a time and generate errors (if occurred). Compiler generates intermediate code in
order to generate target code. Once the whole program is checked, errors are displayed. Example of compilers is
Borland Compiler, Turbo C Compiler. Generated target code is easy to understand after the process of compilation [3].
The process of compilation must be done efficiently. There are mainly two parts of compilation process (Figure 3).
ISSN(Online): 2320-9801
ISSN (Print): 2320-9798
Figure 3: Compilers.
Output:
Parse tree refers to the tree having meaningful data. Parse tree is more specified and more detailed.
Input is syntax tree and output is parse tree (syntax tree with meaning) [5,6].
Output for above given syntax tree is parse tree (Figure 7).
Figure 8: DAG
Most commonly used intermediate code is three address code which is having no more than three operands.
There are three representations used for three address code such as Quadruple, Triple and Indirect Triple.
Input: Parse Tree
Output: Three address code
t1=int to float(2);
t2=id4*t1;
t3=id3*t2;
t4=id2+t3;
t4=id1;
5. Mentioned below are various techniques for code optimization (Figure 9).
Compile Time Evaluation
Constant Folding
ISSN(Online): 2320-9801
ISSN (Print): 2320-9798
Constant Propagation
Common Sub Expression Elimination
Variable Propagation
Code Movement
Loop Invariant Computation
Strength Reduction
Dead Code Elimination
Code Motion
Induction Variables and Reduction in Strength
Loop Unrolling
Loop Fusion etc.
6. Code Generation
a) Code Generation is final phase of compiler.
b) Intermediate code is translated into machine language which is pass and parse from above phases and lastly
optimize.
c) Properties desired by code generation phase are mentioned below.
Correctness
High Quality
Quick Code Generation
Efficient use of resources of target machine
1. Pre-processors
2. Assemblers
3. Linkers and Loaders
IX. ASSEMBLERS
Assembler is a translator which takes assembly language as an input and generates machine language as an output.
Output of compiler is input of assembler which is assembly language. Assembly code is mnemonic version of machine
code. Binary codes for operations are replaced by names. Binary language or relocatable machine code is generated
from the assembler [10]. Assembler uses two passes. Pass means one complete scan of the input program (Figure 10).
X. INTERPRETERS
Interpreter performs the line by line execution of source code. It takes single instruction as an input, reads the
statement, analyzes it and executes it. It shows errors immediately if occur [11]. Interpreter is machine independent and
which does not produces object code or intermediate code as it directly generates the target code. Many languages can
be implemented using both compilers and interpreters such as BASIC, Python, C#, Pascal, Java, and Lisp etc. Example
of interpreter is UPS Debugger (Built in C interpreter). There are mainly two phases of Interpreter (Figure 11).
1) Analysis Phase: Analysis phase contains mainly three sub-phases named lexical analysis, syntax analysis and
semantic analysis. This phase of compilation process is machine independent. Analysis phase of interpreter
works same as analysis phase of compiler.
2) Synthesis Phase: This phase of compilation process is machine dependent. Synthesis phase contains sub-phase
named code generation (direct execution) as it does not generate intermediate code.
Allocation
Relocation
Link editing
Loading
Relocation of an object means allocation of load time addresses and placement of load time addresses into memory at
proper locations.
XIII. CONCLUSION
To conclude this research, source program has to pass and parse from above mentioned all sections to be converted into
predicted target program. After studying this research paper, one can understand the exact procedure behind the
compilation task and step by step evaluation of source code which contains pre-processors, translators, compilers,
phases of compiler, cousins of compiler, assemblers, interpreters, symbol table, error handling, linkers and loaders.
ISSN(Online): 2320-9801
ISSN (Print): 2320-9798
XIV. ACKNOWLEDGMENT
I am using this opportunity to express my gratitude to everyone who supported me in this research. I am thankful for
their aspiring guidance, invaluably constructive criticism and friendly advice during the research. I am sincerely
grateful to them for sharing their truthful and illuminating views on a number of issues related to the research work.
XV. REFERENCES
1. High-level programming language and Compiler
2. https://www.draw.io/s
3. B Vangie, High-level language. Webopedia.
4. A Puntambekar Anuradha, Compiler Design. Technical Publication Second Revised Edition 2016.
5. K Dixita, Compiler Design. Darshan Institute of Engineering and Technology.
6. DA Hardik, System Programing. Darshan Institute of Engineering and Technology
7. Compiler Design - Symbol Table. Tutorials Point.
8. P Matt, W Christopher, Compilers. Department of Computer Science University of Wales Swansea, UK 2007.
9. P Neha, WM Niharika, et al. Introduction to Compilers. International Journal of Science and Research 2015;
4: 2399-2405.
10. A Charu, A Chetna, et al. Research Paper on Phases Of Compiler. International Journal of Innovative
Research in Technology 2014; 1: 259-260.
11. VA Alfred, LS Monica, et al. Compilers: Principles, Techniques and Tools. Second Edition, Pearson, 2014.