Skip to content

Commit

Permalink
docs: parser's automata visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Jan 21, 2024
1 parent 280ee9e commit 1550b2b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,31 @@ Instead of calling CLI manually you can setup your project to call the Rustemo
compiler from `build.rs` script. You can read more in the [configuration
section](configuration.md).
```

## Visualizing parser's automata

Besides providing a detailed information about the grammar and conflicts `rcomp`
can produce a diagram of the parser's handle finding automaton.

This can be used to investigate conflicts visually for smaller grammars.

E.g. for ambiguous grammar `calc.rustemo`:

```
{{#include ./images/calc.rustemo}}
```

a diagram can be produced with:

```
rcomp --dot calc.rustemo
```

and either transformed to an image with [GraphViz dot
tool](https://graphviz.org/docs/layouts/dot/) or opened directly using dot
viewers like, for example, [xdot](https://github.com/jrfonseca/xdot.py).

Here is how the diagram for the above grammar looks like. States marked with red
are states with conflicts.

![](./images/calc.dot.png)
Binary file added docs/src/images/calc.dot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/src/images/calc.rustemo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
E: E '+' E
| E '-' E
| num;

terminals
Plus: '+';
Minus: '-';
num: /\d+/;

0 comments on commit 1550b2b

Please sign in to comment.