SQLite Forum

lemon cannot shift-reduce errors
Login
Ok. Here's my tested and proposed change:

```
diff --git a/tool/lemon.c b/tool/lemon.c
index 75fc7aa2f..1bcb3778a 100644
--- a/tool/lemon.c
+++ b/tool/lemon.c
@@ -3571,7 +3571,7 @@ PRIVATE int compute_action(struct lemon *lemp, struct action *ap)
       /* Since a SHIFT is inherient after a prior REDUCE, convert any
       ** SHIFTREDUCE action with a nonterminal on the LHS into a simple
       ** REDUCE action: */
-      if( ap->sp->index>=lemp->nterminal ){
+      if( ap->sp->index>=lemp->nterminal && ( !lemp->errsym || ap->sp->index!=lemp->errsym->index )){
         act = lemp->minReduce + ap->x.rp->iRule;
       }else{
         act = lemp->minShiftReduce + ap->x.rp->iRule;
diff --git a/tool/lempar.c b/tool/lempar.c
index bbb0cc367..d5ebe6942 100644
--- a/tool/lempar.c
+++ b/tool/lempar.c
@@ -985,10 +985,6 @@ void Parse(
           yyact = yy_find_reduce_action(yypParser->yytos->stateno,
                                         YYERRORSYMBOL);
           if( yyact<=YY_MAX_SHIFTREDUCE ) break;
-          if( yyact>=YY_MIN_REDUCE && yyRuleInfoNRhs[yyact-YY_MIN_REDUCE] ){
-            yyact -= YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
-            break;
-          }
           yy_pop_parser_stack(yypParser);
         }
         if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
```

This fixes the test1.y example (ie: the parser accepts 'three'). It also does not mess up when presented with a true reduction in my larger grammar.