Pert 1 - Introduction To Compiler
Pert 1 - Introduction To Compiler
Week 1
• The operations themselves were very low level: move data from one
location to another, add the contents of two registers, compare two
values, and so on.
Compiler -. Assembly
-. Machine Language
-. Etc.
Compiler Classification
Load-and-go Optimizing
Compiler Compiler
The intermediate forms of the program are Tries to minimize or maximize some
generally kept in RAM, not saved to file attributes of an executable computer
system program.
Depending on how they have been constructed or what function they are
supposed to perform
General Description of Compiler
Source Target
Compiler
Program Program
Error messages
A Language Processing System
skeletal Source program
Preprocessor
source program
Compiler
A typical “Compilation”
target assembly program
Assembler
• Preprocessor
To incorporate skeletal program that becomes an input to the
compiler, and perform the functions of processing macros, file
inclusion, rational preprocessor, and language extensions.
• Assembler
perform processing on the output of the compiler that produces
binary codes that do not have the memory address (memory
addressing).
• Macro processing
Allow user to define macros that are shorthand for longer
constructs
• File inclusion
Preprocessor would be to include the header files into the
program.
• Rational preprocessor
Preprocessor can improve capability or add facilities of the
language that had long (older language).
• Language extensions
Combine commands that written in other languages into the
program in the form of a built-in macros.
Model of Compilation
Synthesis
Intermediate
representation Target program
The Phase of Compiler
Source program
syntax analyzer
semantic analyzer
symbol-table manager Error
handler
intermediate code
Record generator
identifiers &
attributes code optimizer
(symbol table)
Synthesis Phase
code generator
• Semantic analysis:
Certain check are performed to ensure the components of a
program fit together meaningfully.
Analysis Phase
Linear analysis / lexical analysis / scanning
Assignment statement
identifier := Expression
Example:
Type checking
Definite assignment (requiring all local variables to be initialized
before use)
Object binding (associating variable and function references with
their definitions)
Rejecting incorrect programs
Issuing warnings
Synthesis Phase
• Code Optimization
Attempt to improve the intermediate code, so that faster-running
machine code will result.
• Code Generation
The generation of target code, consisting normally of relocatable
machine code or assembly code.
The Phase of a Compiler
Symbol Table Management
• An essential function of a compiler is to record the identifiers used in
the source program and collect information about various attributes
of each identifier.
• A phase must somehow deal with the error, so that compilation can
proceed, allowing further errors in the source program to be
detected.
lexical analyzer
syntax analyzer
Symbol Table :=
1 position…….. id1 +
2 initial…….. id2 *
3 rate…….. id3 60
4
semantic analyzer
:=
id1 +
id2 *
id3 inttoreal
60
intermediate code generator
Translation Example
temp1 := inttoreal(60)
temp2 := id3 * temp1
temp3 := id2 + temp2
id1 := temp3
code optimizer
code generator
MOVF id3, R2
MULF #60.0, R2
MOVF id2 ,R1
ADDF R2, R1
MOVF R1, id1
Compiler Construction Tools
1. Parser generator
Tools that generate Syntax Analyzer (parser), from input-based
Context Free Grammar.
2. Scanner generator
Tools generate lexical analyzer (scanner), from regular
expression based specifications.
• Aho, A.V., Ravi, S., & Ullman, J.D. (2007). Compiler : Principle,
techniques and tools. 2nd. Addison-Wesley. New York. ISBN :
0321491696, Chapter 1.
• http://tinf2.vub.ac.be/~dvermeir/courses/compilers/compilers.pdf
• http://www.cp.eng.chula.ac.th/~piak/teaching/prolang/2013/ppt/1-intr
o.ppt