yacv
: Yet Another Compiler Visualizer
yacv
is a tool for visualizing various aspects of typical LL(1) and LR parsers. Check out demo on YouTube to see sample visualizations
Introduction
Getting comfortable with parsing can be tough. While the legendary “Dragon Book” is an excellent resource for everything related to compilers, it still contains very minimal visualizations for the parsing process itself. That being said, there exist visualization tools such as LR(0) parser visualizer and LL(1) parser visualizer by Zak Kincaid and Shaowei Zhu, JSMachines, Jison etc. However, all of these tools are web-based and most of them show steps in a table which isn’t very intuitive
yacv
attempts to overcome all these shortcomings by using manim
Primary features
yacv
takes in a context free grammar and a string and can be used to :
- Visualize the syntax tree
- Visualize the LR automaton
- Export the parsing table
- Visualize the parsing process step-by-step using manim
Working Example
Grammar:
S -> C C
C -> c C
C -> d
String: c c d d
Using the canonical LR(1) parsing method, yacv
can produce the following:
Syntax Tree
LR(1) Automaton
Canonical LR(1) Parsing Table
STATES | ACTION | GOTO | |||
---|---|---|---|---|---|
$ | c | d | S | C | |
0 | ERR | ['s3'] | ['s4'] | ['1'] | ['2'] |
1 | ACC | ERR | ERR | ERR | ERR |
2 | ERR | ['s6'] | ['s7'] | ERR | ['5'] |
3 | ERR | ['s3'] | ['s4'] | ERR | ['8'] |
4 | ERR | ['r3'] | ['r3'] | ERR | ERR |
5 | ['r1'] | ERR | ERR | ERR | ERR |
6 | ERR | ['s6'] | ['s7'] | ERR | ['9'] |
7 | ['r3'] | ERR | ERR | ERR | ERR |
8 | ERR | ['r2'] | ['r2'] | ERR | ERR |
9 | ['r2'] | ERR | ERR | ERR | ERR |