Error recovery is missing
mingodad opened this issue · 9 comments
While converting some grammars I noticed that the error
for error recovering is not implemented.
Example grammar using error recovery that works with bison:
%nonassoc error
%left '(' ')'
%left '+' '-'
%left '*' '/'
%nonassoc integer
%%
stmts:
stmts stmt
| stmt
| %prec '('
;
stmt:
expr ';'
| error ';'
;
expr:
expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| expr error expr
| '(' expr ')'
| integer
;
%%
//[0-9]+ integer
Yes, I'm not intending to implement this feature.
Also if you try to use a huge grammar with parsertl generally it will likely struggle. Ideally I would use bison style table compression (making sure to dodge the GPL mind you), but getting this far was enough of a struggle I have to admit!
And what about byacc
https://github.com/ThomasDickey/byacc-snapshots:
Bison generating postgresql-16:
/usr/bin/time bison-nb postgresql16b2-naked.y
1.36user 0.03system 0:01.37elapsed 101%CPU (0avgtext+0avgdata 17204maxresident)k
0inputs+4072outputs (0major+10888minor)pagefaults 0swaps
/usr/bin/time byacc-nb postgresql16b2-naked.y
1.59user 0.02system 0:01.61elapsed 99%CPU (0avgtext+0avgdata 42124maxresident)k
0inputs+6800outputs (0major+10631minor)pagefaults 0swaps
Here is the postgresql-16 naked grammar:
postgresql16b2-naked.y.zip
It seems that even lemon
struggles with postgresl-16:
/usr/bin/time lemon-nb -s postgresql16b2-naked.lemon
Parser statistics:
terminal symbols................... 522
non-terminal symbols............... 706
total symbols...................... 1228
rules.............................. 3293
states............................. 3490
conflicts.......................... 0
action table entries............... 129153
lookahead table entries............ 129174
total table size (bytes)........... 546522
15.43user 0.25system 0:15.81elapsed 99%CPU (0avgtext+0avgdata 422128maxresident)k
0inputs+123656outputs (0major+105236minor)pagefaults 0swaps
And what about
byacc
https://github.com/ThomasDickey/byacc-snapshots
That actually looks really interesting.
I have a fork here https://github.com/mingodad/lalr-parser-test with some cosmetic changes.
There is also this https://github.com/phorward/unicc/tree/main/min_lalr1
After seeing Charles Baker's description of supporting "error", I might have a look at this at some point.
That would be a nice addition !
Also instead of reporting errors one by one, probably trying to recover and going forward and showing the accumulated errors would be nice.
Another interesting error recovering and messaging is done here https://github.com/sqmedeiros/lpeglabel#relabel-syntax .