Extending a Pascal Compiler

The Compiler was written in OCaml. It followed a multi-pass approach: a Lexer turned the input program into a stream of tokens; a Parser turned the stream of tokens into a series of Abstract Syntax Trees (ASTs); a Type Checker ensured that all types were used consistently while simultaneously annotating the ASTs; then the resulting code was generated in a stack based intermediate language, and then machine code.

The main parts consisted of manipulating the context-free grammar (that was used to make sense of the stream of tokens) to include these new types of arrays; ensuring that the new arrays had their lengths passed as an auxiliary parameter to functions so that statements such as len(arr) still made sense even if arr was a formal parameter representing an array of arbitrary size; avoiding the repetition of side effects.

Both the final code and the submitted report can be found above.