Beruflich Dokumente
Kultur Dokumente
References
Compilers: Principles, Tools and Techniques by Aho, Sethi and Ullman
A large number of systems software and application programs require structured input
Software quality assurance and software testing
XML, html based systems, Awk, Sed, Emacs, vi . Form processing, extracting information automatically from forms Compilers, assemblers and linkers High level language to language translators Natural language processing Where ever input has a structure one can think of language processing Why study compilers? Compilers use the whole spectrum of language processing technology
Many common applications require structured input during development phase (design of banner programme of Unix) xxxxxxxxx xxxxxxxxx xxxxxxxxx xxx xxx xxx xxx xxx xxx xxxxxxxxx xxxxxxxxx xxxxxxxxx 9x 9x 9x 3b 3x 3b 3x 3b 3x 3b 3x 3b 3x 3b 3x 9x 9x 9x
3 9x 6 3b 3x 3 9x
Theory of lexical analysis, parsing, type checking, runtime system, code generation, optimization (without going too deep into the proofs etc.)
Emphasis will be on algorithms and data structures rather than proofs of correctness of algorithms. Techniques for developing lexical analyzers, parsers, type checkers, run time systems, code generator, optimization. Use of tools and specifications for developing various parts of compilers
Bit of History
How are programming languages implemented? Two major strategies: Interpreters (old and much less studied) Compilers (very well understood with mathematical foundations) Some environments provide both interpreter and compiler. Lisp, scheme etc. provide Interpreter for development Compiler for deployment
Modern compilers preserve the basic structure of the Fortran I compiler !!!
Computer Organization
Applications
Compiler
Operating System Hardware Machine
Compiler
Goals of translation
Correctness High Level of abstraction
Good performance for the generated code Good compile time performance
Overall View
Compiler is part of program development environment The other typical components of this environment are editor, assembler, linker, loader, debugger, profiler etc. The compiler (and all other tools) must support each other for easy program development
14
Programmer
Source Program
Assembly code
Editor
Programmer Does manual Correction of The code
Compiler
Assembler
Machine Code
Linker
Resolved Machine Code
Loader
Errors, if any
Executable Image Execution on the target machine
The next step to understand the sentence is recognizing words (lexical analysis)
English language words can be found in dictionaries Programming languages have a dictionary (keywords etc.) and rules for constructing words (identifiers, numbers etc.)
Lexical Analysis
Someone the ice breaks final := initial + rate * 60
Syntax Analysis
Someone breaks the ice id1 := id2 + id3 * 60
id3
60
Semantic Anaysis
:= Someone plays the piano id1 + * id3
(meaningful)
id2
60
:=
id1
+
* id3 i2r 60
id2
i2r 60
temp1 := i2r ( 60 ) temp2 := id3 * temp1 temp3 := id2 + temp2 id1 := temp3
Code Optimization
temp1 := i2r ( 60 ) temp2 := id3 * temp1 temp3 := id2 + temp2 id1 := temp3
Code Generation
movf id3, r2 mulf #60.0, r2 movf id2, r1 addf r2, r1 movf r1, id1
Structure of a Compiler
Front End
Lexical Analysis Syntax Analysis Semantic Analysis Intermediate Code Generation
Back End
Code Optimization Code Generation
Compiler structure
Compiler
Lexical Analysis
Source Program
Target Program
(Language specific)
Front End
Back End
Symbol Table
Information required about the program variables during compilation
Class of variable: keyword, identifier etc. Type of variable: integer, float, array, function etc. Amount of storage required Address in the memory Scope information
Compiler
Lexical Analysis Syntax Semantic Analysis Analysis IL code
IL Optimiser
Code generator
Source Program
Token stream
optimised code
Target Program
(Language specific)
Front End
Machine specific
Back End
Cousins Of Compliers
1. Preprocessors : Provide Input to Compilers
a. Macro Processing #define in C: does text substitution before compiling #define X 3
#define Y A*B+C
#define Z getchar()
b. File Inclusion
#include in C - bring in another file before compiling
defs.h ////// ////// ////// main.c #include defs.h ------------------------////// ////// ////// -------------------------
is
Preprocessed
into:
ingres_system(Retr..Research,____,____);
2. Assemblers Assembly code: names are used for instructions, and names are used for memory addresses.
MOV a, R1 ADD #2, R1 MOV R1, b 0001 01 00 00000000 * 0011 01 10 00000010 0010 01 00 00000100 * relocation bit
Two-pass Assembly:
First Pass: all identifiers are assigned to memory addresses (0-offset) e.g. substitute 0 for a, and 4 for b Second Pass: produce relocatable machine code:
Next Lecture
Bootstrapping Cross compiler Single pass Multipass compiler Load go compiler Debugger optimiser