Note: This is an outline of what I intend to say on the lecture.
It is not a definition of the course content,
and it does not replace the textbook.
Information about the course
Today:
Aho et al, Chapter 1, Introduction to Compiling,
KP kapitel 1, Kompilatorns beståndsdelar
1.1 Compilers
Aho fig 1.1: A compiler
input: source program
output: target program, error messages, warnings
the target program:
machine code for physical or abstract machine, assembler, C, silicon design...
Systematic techniques:
The first Fortran compiler took 18 staff-years in the 1950's.
In the 1980's, "a substantial compiler can be implemented even as
a student project in a one-semester compiler design course".
Main idea:
analysis (Swedish: "analys")
(one or more) intermediate representation(s) (Sw: "internform"): usually a tree, syntax tree
synthesis (Sw: "syntes")
Later: phases
Examples of compiler-like tools that perform analysis:
-
Structure editors (ex: Emacs' C mode)
-
Interpreters
(execute the tree, or generate byte-code or similar, compare: abstract machine)
"script languages", or "command languages", are often interpreted
-
Silicon compilers
-
HTML or XML processors
-
Programs that read configuration files
The context (Sw: "omgivning", "kontext") of a compiler:
Plus:
-
Sometimes a preprocessor (C: "#include" etc) before the actual compiler
-
Sometimes the compiler generates assembly code,
which is translated into machine code by by an assembler
-
Relocatable machine code = object code, absolute machine code
-
Static and dynamic linking
1.2 Analysis of the source program, 1.3 The Phases of a Compiler
- Lexical analysis ("scanning")
- Syntactical analysis ("parsing")
- Semantic analysis
- Intermediate code generation
- Code optimization
- Code generation
- (The symbol table)
- (Error handling: detection and reporting)
The phases of compiler (Aho fig 1.9):
Lexical analysis
A fragment of a program: position := initial + rate * 60
Tokens
Syntax analysis
Part of a grammar:
- expression -> identifier
- expression -> number
- expression -> expression1 "+" expression2
- expression -> expression1 "*" expression2
- expression -> ( expression1 )
- assignment statement -> identifier1 ":=" expression1
This means:
An expression can consist of an identifier.
An expression can also consist of a number.
Again: position := initial + rate * 60
Aho fig 1.4: "concrete syntax tree", or "parse tree"
Aho fig 1.2: "abstract syntax tree", or just "syntax tree"
All the phases
Aho fig 1.10
1.5 The Grouping of Phases
1.4 Cousins of the Compiler
1.6 Compiler-Construction Tools
- Parser generators (ex: Yacc, Bison)
- Scanner generators (ex: Lex, Flex)
Thomas Padron-McCarthy
(Thomas.Padron-McCarthy@tech.oru.se)
January 19, 2003