|& Implementation||& Implementation|
Improve understanding of languages and machines.
Learn practicalities of translation.
Learn ``anatomy'' of programming languages.
Apply computer science theory to practical problems (using tools).
Do large programming project.
A compiler is a translator from ``high-level'' language to assembly code/object language.
Language L Language L'
Examples of translators:
|Pascal,C, etc.||$$||Compiler||$$||Machine Code|
|SQL||$$||DB Optimizer||$$||Query plan|
We study common features of translators, by building one.
We study languages from an implementor's viewpoint.
How do compilation feasibility and runtime efficiency affect language design?
(There are more ``theoretical'' approaches to studying programming languages, and there are interesting languages that don't compile easily...)
``Von Neumann'' Machine
Sequential control flow + labels + jumps
Small set of built-in data types and operators (e.g., byte, integer, floating point)
Flat linear address space.
Memory hierarchy (registers faster than memory faster than disk).
E.g., Fortran, Pascal, C, Cobol, Java, ...
Expressions (arithmetic, logical)
Control structures (loops, conditionals, etc.)
Type declarations and type checking
Composite types (arrays, records, etc.)
Procedures/Functions, with private scope
How can we make high-level language and Von Neumann machine meet?
Translate HLL into lower-level code (in traditional compiler, to machine code.)
Build a ``higher level'' virtual machine (in traditional interpreter, perhaps a stack machine.)
In practice, we do some of both, even in a compiler, since generated machine code makes use of a runtime library and operating system.
Compiler Structure: Want Simplicity and Flexibility
Syntax is easy.
Good theory: regular and context-free languages and automata.
Good tools, even for complex cases.
Semantics are hard.
Variety of choices:
|( we will focus here)|