|
1 | 1 | # Lrama |
2 | 2 |
|
3 | | -[](https://badge.fury.io/rb/lrama) |
4 | | -[](https://github.com/ruby/lrama/actions/workflows/test.yaml) |
| 3 | +Lrama is a Ruby implementation of a LALR(1) parser generator. It reads a Bison-style grammar file, builds parser tables, and emits a C parser. Its primary goal is to support CRuby parser development, including Bison-compatible grammar files, error-tolerant parsing work, parameterized grammar rules, inlining, syntax diagrams, and a toolchain that can run as part of Ruby's build. |
5 | 4 |
|
| 5 | +## Quick Start |
6 | 6 |
|
7 | | -## Overview |
8 | | - |
9 | | -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. |
10 | | - |
11 | | -## Installation |
12 | | - |
13 | | -Lrama's installation is simple. You can install it via RubyGems. |
| 7 | +Install the released gem: |
14 | 8 |
|
15 | 9 | ```shell |
16 | 10 | $ gem install lrama |
| 11 | +$ lrama --version |
17 | 12 | ``` |
18 | 13 |
|
19 | | -From source codes, you can install it as follows: |
| 14 | +From a checkout of this repository: |
20 | 15 |
|
21 | 16 | ```shell |
22 | | -$ cd "$(lrama root)" |
23 | 17 | $ bundle install |
24 | | -$ bundle exec rake install |
25 | | -$ bundle exec lrama --version |
26 | | -lrama 0.7.0 |
| 18 | +$ bundle exec ruby exe/lrama --version |
27 | 19 | ``` |
28 | | -## Usage |
29 | 20 |
|
30 | | -Lrama is a command line tool. You can generate a parser from a grammar file by running `lrama` command. |
| 21 | +Generate and run the calculator sample: |
31 | 22 |
|
32 | 23 | ```shell |
33 | | -# "y.tab.c" and "y.tab.h" are generated |
34 | | -$ lrama -d sample/parse.y |
| 24 | +$ bundle exec ruby exe/lrama -d sample/calc.y -o /tmp/calc.c |
| 25 | +$ gcc -Wall /tmp/calc.c -o /tmp/calc |
| 26 | +$ /tmp/calc |
35 | 27 | ``` |
36 | | -Specify the output file with `-o` option. The following example generates "calc.c" and "calc.h". |
| 28 | + |
| 29 | +Generate a state report and a syntax diagram while developing a grammar: |
37 | 30 |
|
38 | 31 | ```shell |
39 | | -# "calc", "calc.c", and "calc.h" are generated |
40 | | -$ lrama -d sample/calc.y -o calc.c && gcc -Wall calc.c -o calc && ./calc |
41 | | -Enter the formula: |
42 | | -1 |
43 | | -=> 1 |
44 | | -1+2*3 |
45 | | -=> 7 |
46 | | -(1+2)*3 |
47 | | -=> 9 |
| 32 | +$ bundle exec ruby exe/lrama -v --report-file=/tmp/calc.output sample/calc.y |
| 33 | +$ bundle exec ruby exe/lrama --diagram=/tmp/calc.html sample/calc.y |
48 | 34 | ``` |
49 | 35 |
|
50 | | -## Supported Ruby version |
| 36 | +## Manual |
| 37 | + |
| 38 | +Start with the introduction and examples if you are new to Lrama. Use the grammar, invocation, directive, and option references when you are maintaining an existing grammar. |
| 39 | + |
| 40 | +1. [Introduction](chapters/00-introduction.md) |
| 41 | +2. [Installation and Conditions](chapters/00-installation-and-conditions.md) |
| 42 | +3. [Concepts](chapters/01-concepts.md) |
| 43 | +4. [Examples](chapters/02-examples.md) |
| 44 | +5. [Grammar Files](chapters/03-grammar-files.md) |
| 45 | +6. [Parser C Interface](chapters/04-parser-interface.md) |
| 46 | +7. [Parser Algorithm](chapters/05-parser-algorithm.md) |
| 47 | +8. [Error Recovery and Error Tolerance](chapters/06-error-recovery.md) |
| 48 | +9. [Context Dependencies](chapters/07-context-dependencies.md) |
| 49 | +10. [Debugging Your Parser](chapters/08-debugging.md) |
| 50 | +11. [Invoking Lrama](chapters/09-invoking-lrama.md) |
| 51 | +12. [Generated Parser and Integration](chapters/10-generated-parser-and-integration.md) |
| 52 | +13. [History](chapters/11-history.md) |
| 53 | +14. [Version Compatibility](chapters/12-version-compatibility.md) |
| 54 | +15. [FAQ](chapters/13-faq.md) |
| 55 | + |
| 56 | +## Appendices |
| 57 | + |
| 58 | +- [Directive Reference](appendices/a-directive-reference.md) |
| 59 | +- [Command Line Option Reference](appendices/b-command-line-option-reference.md) |
| 60 | +- [Bison Compatibility](appendices/c-bison-compatibility.md) |
| 61 | +- [Standard Library](appendices/d-standard-library.md) |
| 62 | +- [Glossary](appendices/e-glossary.md) |
| 63 | +- [Troubleshooting](appendices/f-troubleshooting.md) |
| 64 | +- [License and Legal Notes](appendices/g-license-and-legal-notes.md) |
| 65 | + |
| 66 | +## Development Documents |
| 67 | + |
| 68 | +- [Profiling](development/profiling.md) |
| 69 | +- [Compressed state table](development/compressed_state_table/main.md) |
51 | 70 |
|
52 | | -Lrama is executed with BASERUBY when building ruby from source code. Therefore Lrama needs to support BASERUBY, currently 3.1, or later version. |
| 71 | +## Supported Ruby Version |
53 | 72 |
|
54 | | -This also requires Lrama to be able to run with only default gems because BASERUBY runs with `--disable=gems` option. |
| 73 | +Lrama is executed with BASERUBY when building Ruby from source. For that reason, Lrama must run on the BASERUBY version used by Ruby and must work with default gems only, because BASERUBY is executed with `--disable=gems`. |
55 | 74 |
|
56 | 75 | ## License |
57 | 76 |
|
58 | | -See [LEGAL.md](https://github.com/ruby/lrama/blob/master/LEGAL.md) file. |
| 77 | +See [LEGAL.md](../LEGAL.md) for the authoritative legal notice for this repository. |
0 commit comments