1.10. Structure of a Compiler


The front end

A compiler generally starts with a front end that handles the language syntax and some of the language semantics.

string → lexer → sequence of
tokens
→ semantic parser → compiler
output

Intermediate code generation

Some compilers generate code during the parsing process. (So the semantic part of the semantic parser is the code generation.)

More commonly, the compiler generates intermediate code that is processed by a intermediate code analyzer and improver and a back end that generates the final code.

sem. parser → intermediate
code
→ analysis/improvement → intermediate
code
→ code generator → final output

Abstract syntax trees

Another common strategy is for the semantic parser to generate abstract syntax trees, which describe the structure of a section of a program. This gives the compiler writer more flexibility to handle difficult constructs.

sem. parser → ASTs → intermed. code gen. → intermediate
code
→ …

Interpreter

A compiler can produce abstract syntax trees and send them directly to an interpreter, which processes them. In this scheme, no code is generated. This is what your project will do.

sem. parser → ASTs → interpreter