Every repository with this icon (
Every repository with this icon (
Reia Internals
Here’s a quick guide to how Reia’s compiler works
Scanning and Parsing
Reia uses a scanner based on leex, an Erlangly lex (http://github.com/rvirding/leex):
src/compiler/reia_scan.xrlReia’s parser is generated using yecc, an Erlangy yacc (erl -man yecc):
src/compiler/reia_parse.yrlThese two files generate Reia’s scanner and parser, and thus define the syntax of the language. If you’re interested in working on syntax hacks, these are the files to look in.
Things to look out for: shift/reduce or reduce/reduce conflicts from yecc. These are only warnings, but they indicate your grammar is somehow ambiguous. If you want to get a patch accepted to the grammar, be sure it’s free of these warnings.
There are a number of ways to parse Reia code to parse trees. The easiest is to do it straight from “ire” the Reia shell:
>> "2+2".to_parsetree()
=> [(:op,1,:'+',(:integer,1,2),(:integer,1,2))]
This outputs Reia parse trees in Reia syntax.
You can also parse Reia code from Erlang:
1> reia:parse(“2+2”). {ok,[{op,1,‘+’,{integer,1,2},{integer,1,2}}]}Compiler Passes
Reia’s compiler runs a number of passes over the parse tree which progressively transform the code into the Erlang abstract format.
The list of passes and basic compiler API are defined in:
src/compiler/reia_compiler.erlHere’s the present list of passes performed by the compiler:
- branches: Converts if statements to nested case statements and adds a catchall clause to all if/case statements that returns nil unless another catchall clause is defined
- ivars: Implemenets “instance variables”, i.e. adding hidden state to gen_server which compiles to pure functional state passing
- ssa: Static single assignment transform, implements destructive assignment
- methods: Handles hidden state passing between method calls within the same object
- r2e: Final Reia-to-Erlang pass, handles final conversion of Reia syntax trees into the Erlang abstract format
These passes are defined in the:
src/compiler/directory.







