diff --git a/docs/src/cli.md b/docs/src/cli.md index a3bc3f0d..a0fdcc93 100644 --- a/docs/src/cli.md +++ b/docs/src/cli.md @@ -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) diff --git a/docs/src/images/calc.dot.png b/docs/src/images/calc.dot.png new file mode 100644 index 00000000..97699c37 Binary files /dev/null and b/docs/src/images/calc.dot.png differ diff --git a/docs/src/images/calc.rustemo b/docs/src/images/calc.rustemo new file mode 100644 index 00000000..a5090c18 --- /dev/null +++ b/docs/src/images/calc.rustemo @@ -0,0 +1,8 @@ +E: E '+' E + | E '-' E + | num; + +terminals +Plus: '+'; +Minus: '-'; +num: /\d+/;