Skip to content

n-shevko/modula2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Compiler for tiny subset of Modula 2

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published