Professional Documents
Culture Documents
Introduction to Compiling
Compiler
Operating Systems
Hardware
Source Machine
program Compiler code
Error messages
12/07/21 Department of Computer ScienceER&DCI 4
Institute of Technology
Introduction
Source Target
program Compiler
Program
Error messages
12/07/21 Department of Computer ScienceER&DCI 5
Institute of Technology
What Do Compilers Do?
Source language:
High-level programming languages,
Query languages
Target language:
Machine language,
Typesetting commands,
VLSI layout, …
Source Target
class public Foo { load R0,R8
int maxargs(Stm s) call label4
…
…}
1
Pre-Processor
2
Compiler
3
Assembler
4 Relocatable
Machine Code
Library,
5 relocatable
Loader object files
Link/Editor
Executable
identifier := expression
identifier
Rate*60
Nodes of tree are constructed
12/07/21 Department of Computer
using a grammar for the base
ScienceER&DCI
Institute of Technology
15
For example we have some rules as a
part of the definition of expressions
Any identifier is an expression
Any number is an expression
If expression1 end expression2 are
expressions, then so are
expression1 + expression2,
expression1 * expression2 etc are also
expressions
addf fr2,fr1
Analysis Lexical
Syntax
Semantic
IR code gen
Optimizer
Synthesis Target code gen
Target Program
12/07/21 Department of Computer ScienceER&DCI 24
Institute of Technology
Source Program Pay := base + rate * 60
Id1 := Id2 + Id3 * 60
lexical
:=
+
id1 *
syntax id2
:= id3 60
+
semantic id1
id2 *
id3 inttoreal
IR code gen temp1 = inttoreal(60) 60
temp2 = id3* temp1
temp1 = id3* 60.0
optimizer temp3 = id2+ temp2
id1 = id2+temp1
id1 = temp3
movf id3, fr2; movf id2, fr1
target code gen mulf #60.0, fr2
addf fr2,fr1
Target Program movf fr1, id1
12/07/21 Department of Computer ScienceER&DCI 25
Institute of Technology