Kompilatorer och interpretatorer: Lecture 1

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

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:

The context (Sw: "omgivning", "kontext") of a compiler:

The context of a compiler

Plus:

1.2 Analysis of the source program, 1.3 The Phases of a Compiler

  1. Lexical analysis ("scanning")
  2. Syntactical analysis ("parsing")
  3. Semantic analysis
  4. Intermediate code generation
  5. Code optimization
  6. Code generation
  7. (The symbol table)
  8. (Error handling: detection and reporting)
The phases of compiler (Aho fig 1.9):

Aho Fig 1.9, Phases of a compiler

Lexical analysis

A fragment of a program: position := initial + rate * 60

Tokens

Syntax analysis

Part of a grammar:

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.4, Parse tree for...

Aho fig 1.2: "abstract syntax tree", or just "syntax tree"

Aho Fig 1.2, Syntax tree for...

All the phases

Aho fig 1.10

Aho Fig 1.10, Translation of a statement

1.5 The Grouping of Phases

1.4 Cousins of the Compiler

1.6 Compiler-Construction Tools


Thomas Padron-McCarthy (Thomas.Padron-McCarthy@tech.oru.se) January 19, 2003