








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Some Issues in Compilerp Structure
15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul (^33)
Grouping of PhasesGrouping of Phases
Analysis Synthesis sourceprogram analyser lexical analysersyntax semanticanalyser generatorcode objectprogram
Front End := Back End velocity (^) + … velocity := initial_velocity + acceleration * time; …
initial_velocity l i
acceleration (^) time
Compiler PassesCompiler Passes
Compilers are complex programs. As a consequence they are broken into several distinct chunks called passes, that communicate with one another via temporary files. These passes are only a part of the compilation process. Structure of a typical four pass compiler is shown on next slide.
PassesPasses
First pass is the Preprocessor that typically performs
PassesPasses
The third pass is the optimizer that improves the quality of the generated intermediate code & TheThe fourthfourth passpass, thethe backback endend, translatestranslates thethe optimized code to real assembly language or some form of binary executable code. Number of Passes
Bootstrapping and PortingBootstrapping and Porting
Compiler ForLanguage A Running LanguageWritten in A C Existingil f C il f Language B
Compiler for Language A
Compiler for Language B
15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul (^1313)
T DiagramsT Diagrams
A compiler written in Language H (for host language) that
translates language S (for Source Language) into language T
(for Target Language) can be drawn as following T Diagram
S T H
T Diagrams (contd )T Diagrams (contd.)
To Directly Translate from Language A to C
A B B C A C H H H
15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul (^1515)
T Diagrams (contd )T Diagrams (contd.)
Compiler Form Machine “H” to Machine “K”
A B A B H H K K
K
T Diagrams (contd )T Diagrams (contd.)
It is common to write a compiler in the same language that it is to compile.
S T S
15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul (^1919)
Bootstrapping (Step 1)Bootstrapping (Step 1)
A H
A H A
A H A H H
A (^) H
Compiler written in its own Language A (^) “Quick and Dirty” Compiler written in itsM hine L ng ge
Running but inefficient Compiler Machine Language
Bootstrapping (Step 2)Bootstrapping (Step 2)
A H (^) A H A H H
A H A
A H H H
its own Language ACompiler written in Running but inefficient its own Language A Final Version of theCompiler Running but inefficient Compiler (from first stage)
Compiler
15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul (^2121)
BootstrappingBootstrapping
After bootstrapping we have a compiler in both source code and the existing code.
The advantage of this is that any improvement toThe advantage of this is that any improvement to the source code of the compiler can be immediately bbootstrapped to working compiler by applying the t t d t ki il b l i th same two-step process as before.
Compiler Construction ToolsCompiler Construction Tools
PP arser GeneratorsG t
g
CC ompiler Construction Toolsil C t ti T l
CC ompiler Construction Toolsil C t ti T l
15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul (^2727)
ConclusionConclusion
4 4. Compiler construction toolsCompiler construction tools