Last active
October 24, 2016 01:26
-
-
Save DmitrySoshnikov/0bf15c7db28e104f73f8177908e3658f to your computer and use it in GitHub Desktop.
Comparison of parsing tables for grammars with and without operators precedence and assoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.dmitrys:syntax$ syntax-cli --grammar ~/calculator.grammar.js --mode LALR1 --table | |
Parsing mode: LALR(1). | |
Grammar: | |
0. $accept -> E | |
---------------- | |
1. E -> E + E | |
2. | E * E | |
3. | NUMBER | |
4. | ( E ) | |
LALR(1) parsing table: | |
┌───┬────┬────┬────────┬────┬────┬─────┬───┐ | |
│ │ + │ * │ NUMBER │ ( │ ) │ $ │ E │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 0 │ │ │ s2 │ s3 │ │ │ 1 │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 1 │ s4 │ s5 │ │ │ │ acc │ │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 2 │ r3 │ r3 │ │ │ r3 │ r3 │ │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 3 │ │ │ s2 │ s3 │ │ │ 8 │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 4 │ │ │ s2 │ s3 │ │ │ 6 │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 5 │ │ │ s2 │ s3 │ │ │ 7 │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 6 │ r1 │ s5 │ │ │ r1 │ r1 │ │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 7 │ r2 │ r2 │ │ │ r2 │ r2 │ │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 8 │ s4 │ s5 │ │ │ s9 │ │ │ | |
├───┼────┼────┼────────┼────┼────┼─────┼───┤ | |
│ 9 │ r4 │ r4 │ │ │ r4 │ r4 │ │ | |
└───┴────┴────┴────────┴────┴────┴─────┴───┘ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.dmitrys:syntax$ syntax-cli -g ~/calc-no-assoc.g.js -m LALR1 -t | |
Parsing mode: LALR(1). | |
Grammar: | |
0. $accept -> E | |
---------------- | |
1. E -> E + T | |
2. | T | |
3. T -> T * F | |
4. | F | |
5. F -> NUMBER | |
6. | ( E ) | |
LALR(1) parsing table: | |
┌────┬────┬────┬────────┬────┬─────┬─────┬────┬───┬───┐ | |
│ │ + │ * │ NUMBER │ ( │ ) │ $ │ E │ T │ F │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 0 │ │ │ s4 │ s5 │ │ │ 1 │ 2 │ 3 │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 1 │ s6 │ │ │ │ │ acc │ │ │ │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 2 │ r2 │ s8 │ │ │ r2 │ r2 │ │ │ │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 3 │ r4 │ r4 │ │ │ r4 │ r4 │ │ │ │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 4 │ r5 │ r5 │ │ │ r5 │ r5 │ │ │ │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 5 │ │ │ s4 │ s5 │ │ │ 10 │ 2 │ 3 │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 6 │ │ │ s4 │ s5 │ │ │ │ 7 │ 3 │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 7 │ r1 │ s8 │ │ │ r1 │ r1 │ │ │ │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 8 │ │ │ s4 │ s5 │ │ │ │ │ 9 │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 9 │ r3 │ r3 │ │ │ r3 │ r3 │ │ │ │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 10 │ s6 │ │ │ │ s11 │ │ │ │ │ | |
├────┼────┼────┼────────┼────┼─────┼─────┼────┼───┼───┤ | |
│ 11 │ r6 │ r6 │ │ │ r6 │ r6 │ │ │ │ | |
└────┴────┴────┴────────┴────┴─────┴─────┴────┴───┴───┘ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment