1
Compilation 2007 Compilation 2007
Hand Hand-
- Written
Written One One-
- Pass Compilers
Pass Compilers
Michael I. Schwartzbach BRICS, University of Aarhus
2
One-Pass Compilers
Compiler Technology Compiler Technology
A Joos compiler uses big technology:
- scanner and parser generator
- visitor patterns
- aspects
- 14 passes through the AST
Even a Joos 0 compiler requires:
- 4,063 lines of hand-written code
- 21,910 lines of auto-generated code
This is orthogonal to the conceptual complexity:
- scanner, parser, weeder, scopes, environments, static type
checking, static analysis, code templates, optimization
3
One-Pass Compilers
Light Light-
- Weight Technology
Weight Technology
A one-pass (or narrow) compiler:
- reads the source file one character at a time
- constructs no internal representation of the full program
- outputs the generated code simultaneously
A hand-written compiler:
- contains no auto-generated code
Benefits of light-weight technology:
- simple, fast, and fun
Downside of light-weight technology:
- doesn't scale to complex languages like Java
4
One-Pass Compilers
Limitations of One Limitations of One-
- Pass Technology
Pass Technology
Limited scope rules:
- we can't see anything that occurs later in the file
Lack of static analysis:
- we never get a complete picture of the program
Lack of optimization:
- we can't look at the generated code twice