Chapter1
Chapter1
• Ch. 1: Introduction
• Ch. 2: Lexical Analysis
• Ch. 3: Syntax Analysis
• Ch. 4: Syntax-Directed Translation
• Ch. 5: Intermediate Code Generation
• Ch. 6: Run-Time Environments
• Ch. 7: Code Generation
• Ch.8: Code Optimization
Syllabus
• Textbook:
• “Compilers: Principles, Techniques, and Tools”
by Aho, Sethi, and Ullman, 2 nd edition
Objectives
• Be able to build a compiler for a (simplified)
(programming) language
• Know how to use compiler construction tools,
such as generators of scanners and parsers
• Be familiar with virtual machines, such as the
JVM and Java bytecode
• Be able to define LL(1), LR(1), and LALR(1)
grammars
• Be familiar with compiler analysis and
optimization techniques
• … learn how to work on a larger software project!
Compilers and Interpreters
• “Compilation”
– Translation of a program written in a source
language into a semantically equivalent
program written in a target language
Input
Source Target
Compiler
Program Program
Source
Program
Interpreter Output
Input
Error messages
The Analysis-Synthesis Model of
Compilation
Preprocessor
Modified Source Program
Try for example:
Compiler gcc -v myprog.c
Target Assembly Program
Assembler
Relocatable Object Code
Linker/Loader Libraries and
Relocatable Object Files
Absolute Machine Code
The Phases of a Compiler
Phase Output Sample
Programmer (source code producer) Source string A=B+C;
Scanner (performs lexical analysis) Token string ‘A’, ‘=’, ‘B’, ‘+’, ‘C’, ‘;’
And symbol table with names
Parser (performs syntax analysis Parse tree or abstract syntax tree ;
|
based on the grammar of the =
programming language) / \
A +
/ \
B C