Lrama is LALR (1) parser generator written by Ruby. The first goal of this project is providing error tolerant parser for CRuby with minimal changes on CRuby parse.y file.
Lrama's installation is simple. You can install it via RubyGems.
$ gem install lramaFrom source codes, you can install it as follows:
$ cd "$(lrama root)"
$ bundle install
$ bundle exec rake install
$ bundle exec lrama --version
lrama 0.7.0Lrama is a command line tool. You can generate a parser from a grammar file by running lrama command.
# "y.tab.c" and "y.tab.h" are generated
$ lrama -d sample/parse.ySpecify the output file with -o option. The following example generates "calc.c" and "calc.h".
# "calc", "calc.c", and "calc.h" are generated
$ lrama -d sample/calc.y -o calc.c && gcc -Wall calc.c -o calc && ./calc
Enter the formula:
1
=> 1
1+2*3
=> 7
(1+2)*3
=> 9Install railroad_diagrams 1.0.0 or later to generate SVG diagrams with links to
referenced rules and links back to referencing rules:
$ lrama --diagram=diagram.html -o calc.c sample/calc.yOpen diagram.html in a browser. Click a nonterminal symbol to visit its rule
or follow the referencing-rule links to navigate back.
Midrule action symbols are omitted from diagrams. User-defined empty rules remain visible.
Lrama is executed with BASERUBY when building ruby from source code. Therefore Lrama needs to support BASERUBY, currently 3.1, or later version.
This also requires Lrama to be able to run with only default gems because BASERUBY runs with --disable=gems option.
See LEGAL.md file.