patrickfrey / mewa

Compiler-compiler for writing compiler frontends with Lua
https://github.com/patrickfrey/mewa
MIT License
23 stars 2 forks source link
compiler compiler-construction compiler-design compiler-frontend compilers compilers-design cpp cpp17 llvm-ir lua parser-generator programming-language programming-languages

Imagine

... to define the typesystem of your language like this:

Pseudocode Class Declaration
class Obj
{
    function run( param : int ) -> int;
}
Typedb Commands Illustration (Simplified)
intType = typedb:def_type( 0, "int" )

function call( func) return function( this, arg ) ... end end
function init( obj) return function( address) ... end end

object = typedb:def_type( 0, "Obj" )
mt = typedb:def_type( object, "run" )
run = typedb:def_type( mt, "()", call( "Obj_run"), {intType} )
typedb:def_reduction( intType, run, init( intType) )

Mewa

Mewa is a compiler-compiler for prototyping of compiler front-ends for statically-typed programming languages in Lua. You write an attributed grammar in a custom language, a sort of Bison/Yacc-style BNF. The parser creates an AST (Abstract Syntax Tree) with a fixed schema. Lua function calls attached as attributes are called on the AST tree traversal triggered by the compiler after the syntax analysis. A Lua module written in C++ (see typedb API) provides assistance to define the type system of your programming language in a declarative way.

Design Philosophy and Limitations

LLVM IR

The examples provided here use the intermediate representation (IR) of LLVM for code generation. For reading more see the collected links.

Status

I consider the software as ready for use in projects.

Portability

Build

Currently, there is only GNU Makefile support. CMake support is not planned for this project because the project is too small to justify it and it has not many dependencies. I would rather like to have Makefiles for platforms where GNU Makefile support is not available (e.g. Windows).

Target platforms

Issues around target platforms are discussed here.

Documentation

Mailing List

Chat

Website

Contact (E-Mail)