Building and Running PL/0

MAIN COMPILER CONTROL FLOW

parser calls scanner as needed, generates AST
typechecker runs, creating symbol tables and performing compile-time checks to insure validity of program
evaluator may run, creating activation records to hold program values
space allocator runs, allocating space for variables in their stack frames
code generator calls assembler to generate final output file

FILES (roughly in the order in which they are encountered in the project)

main files: plzero.h, plzero.c
This is the "top level" for the entire pl0 compiler (i.e.,"main" is here). It reads and parses the command line options, sets the appropriate flags, opens and close files, and calls the appropriate submodules of the compiler in the right order.
helper files: array.h, array.c
These files define a dynamic array class. Using this class, you can create arrays without fixed size, which expand as necessary. The array class can be used for any type by declaring Arrayof(TypeName,Type).
lexical analysis files
scanner.h, scanner.c
Contains code for the scanner object. The scanner breaks the input program into tokens, to make the parser's job easier. Only one scanner object is created. The scanner calls the buffer to get characters from the input file.
buffer.h, buffer.c
These files define the interface to the input file, converting it into a sequence of characters. Also handles line and character printing.
token.h, token.c
Code for defining and printing tokens.
abstract syntax tree files
ast.h, ast.c
These files define the AST (Abstract Syntax Tree). The AST is the central data structure generated by the parser and processed by the typechecker, and the code generator. It embeds within it the structure of the input program, and is annotated with line number information.
decl.h, decl.c
AST classes for different kinds of declarations (and some supporting helper classes)
stmt.h, stmt.c
AST classes for different kinds of statements.
expr.h, expr.c
AST classes for different kinds of expressions.
syntactic analysis files
parser.h, parser.decl.c, parser.stmt.c, parser.expr.c
The parser is an object which reads in tokens by calling the scanner when necessary, and builds an AST for later processing. Only one parser object is created. The parser.decl.c file parses declarations. Since declarations are the "top level" of a pl0 program, parsing starts here. The parser.stmt.c file parses statements. The parser.expr.c file parses arithmetic and relational expressions.
typechecking files
decl.tc.c, stmt.tc.c, expr.tc.c
Typechecking declarations, statements, and expressions.
symtab.h, symtab.c
Symbol tables.
type.h, type.c
Defines the representation of types (i.e. integer, boolean, procedure). These types are generated and compared during typechecking.
evaluation/interpretation files
decl.eval.c, stmt.eval.c, expr.eval.c
Evaluating declarations, statements, and expressions.
activation.c, activation.h
Activation records (the evaluation-time analog of symbol tables).
value.h, value.c
The classes representing values manipulated by the program (integers and booleans). The evaluation-time analog of types.
code generation files
decl.codegen.c, stmt.codegen.c, expr.codegen.c
Code generation for declarations, statements, and expressions.
symtab.codegen.c
Code generation functions related to stack layout.
asm.h, asm.c, asm.mips.h, asm.mips.c, asm.x86.h, asm.x86.c
These files define the "assembler", which is just an object that outputs appropriate assembly instructions to the output file. Only one assembler object is created. asm.[ch] defines an abstract superclass, which has two concrete implementations (mips and x86) each of which produces assembly code for a particular target machine.
regs.h, regs.c
These contain routines dealing with registers and register allocation.

CODING CONVENTIONS

_names indicate private variables
Class names start with a capital letter
Error conventions
Tplzero::syntaxError - for scanning & parsing errors
Tplzero::typeError - for typechecking errors
Tplzero::evalError - for evaluation/interpretation errors
Tplzero::error - for generic errors in user input
Tplzero::warning - for non-fatal errors
Tplzero::fatal - for internal compiler bugs

CLASS HIERARCHY

Token
IdentToken
IntegerToken
Ast
Decl
ModuleDecl
ProcDecl
VarDecl
ConstDecl
Stmt
AssignStmt
OutputStmt
IfStmt
WhileStmt
CallStmt
Expr
IntegerLiteral
LValue
VarRef
InputExpr
UnOp
BinOp
TypeAST
IntTypeAST
Block
FormalDecl
VarDeclItem
ConstDeclItem
SymTabScope
SymTabEntry
VarSTE
FormalSTE
ConstSTE
ProcSTE
Type
IntegerType
BooleanType
ProcedureType
ActivationRecord
ActivationRecordEntry
VarActivationRecordEntry
FormalActivationRecordEntry
ProcActivationRecordEntry
Value
IntegerValue
BooleanValue
UndefinedValue
Array