Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 1.58 KB

README.md

File metadata and controls

32 lines (23 loc) · 1.58 KB

Compiler for tiny subset of Modula 2.

It was done to learn basics of compiler engineering.

LLVM IR was used as a target language.

What was done

  1. Peg packrat parser generator It consumes file like this and generates:

    • ast type definitions like these
    • parser file like this The result parser file has function parse which can parse source code and generate ast object. Parser generator supports basic quantifiers like: *+? Nonterminal in {} means that it is entry point (top level) nonterminal.
  2. Ast -> CFG pass

  3. CFG -> CFG in SSA form pass. Inspired by "Simple and Efficient Construction of Static Single Assignment Form (Braun)"

Known issues

  • Compiler doesn't have any garbage collection
  • Implemented only arrays, structs, integers.
  • Elimination of left recursion from grammar works only if left recursion appears in the first branch
  • Syntax error reports are incomprehensible :) This thing should be definitely rewritten

Other

Any modification of an array\structure copy entire agregate and then modify only needed subelement. This is done on purpose for potential CPS conversion in the future.