Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Compiler Phases
Compiler Phases
Compiler phases
09/21/16
Lexical analysis
Syntax analysis
Semantic analysis
Intermediate (machine-independent) code generation
Intermediate code optimization
Target (machine-dependent) code generation
Target code optimization
Preprocessor
Source program
Compiler
Target assembly program
assembler
Relocatable machine code
linker
Absolute machine code
09/21/16
What is a compiler?
Two components
Source
program
compiler
Target
program
Error message
09/21/16
09/21/16
Sourceprogram(characterstream)
Scanner
(lexicalanalysis)
Parser
(syntaxanalysis)
Parsetree
Backend
synthesis
Frontend
analysis
Tokens
SemanticAnalysis
andIntermediate
CodeGeneration
Abstractsyntaxtreeor
otherintermediateform
09/21/16
Machine
IndependentCode
Improvement
Modifiedintermediateform
TargetCode
Generation
Assemblyorobjectcode
MachineSpecific
CodeImprovement
Modifiedassemblyorobjectcode
COP4020 Spring 2014
program
var
read
i
then
:=
)
09/21/16
gcd
i
(
<>
i
i
end
(
,
i
j
:=
.
input
j
,
do
i
i
,
:
j
if
;
output
integer
)
i
j
writeln
)
;
;
>
else
(
;
begin
while
j
j
i
09/21/16
09/21/16
Context-Free Grammars
A Statement is a
For-statement
If-statement
Assignment
<statement>
<for-statement>
<assignment>
09/21/16
10
Parsing examples
id1
:=
id2
09/21/16
+
id3
60
11
Semantic Analysis
09/21/16
12
Semantic Analysis
Type checking
Every variable is declared before used
Identifiers are used in appropriate contexts
Check subroutine call arguments
Check labels
09/21/16
13
09/21/16
14
15
09/21/16
16
09/21/16
17
Summary
09/21/16
18