Lemon-generated parser gives an assertion failure

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Lemon-generated parser gives an assertion failure

Kelvin Sherlock
The test case can be simplified to:

bug.lemon:
---

%include {
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "bug.h"
}
%code {
        int main(void) {

        void *pParser;

        pParser = ParseAlloc(malloc);
        if (!pParser) {
            printf("out of memory\n");
            exit(1);
        }

        ParseTrace(stderr, "Debug: ");

        Parse(pParser, X, 0);
        Parse(pParser, 0, 0);
        ParseFree(pParser, free);
        return 0;
        }
}


main ::= decls.
decls ::= .
decls ::= decls decl.

decl ::= X



which generates this code:

      default:
      /* (0) main ::= decls */ yytestcase(yyruleno==0);
      /* (1) decls ::= (OPTIMIZED OUT) */ assert(yyruleno!=1);
        break;

I believe the issue is line 4164 which should be … = LEMON_TRUE.  Currently, when i=0, all rules will erroneously be optimized out.

  4157    /* Mark rules that are actually used for reduce actions after all
  4158    ** optimizations have been applied
  4159    */
  4160    for(rp=lemp->rule; rp; rp=rp->next) rp->doesReduce = LEMON_FALSE;
  4161    for(i=0; i<lemp->nxstate; i++){
  4162      for(ap=lemp->sorted[i]->ap; ap; ap=ap->next){
  4163        if( ap->type==REDUCE || ap->type==SHIFTREDUCE ){
  4164          ap->x.rp->doesReduce = i;
  4165        }
  4166      }
  4167    }

Kelvin Sherlock

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Lemon-generated parser gives an assertion failure

Richard Hipp-3
On 4/25/17, Kelvin Sherlock <[hidden email]> wrote:

>
> I believe the issue is line 4164 which should be … = LEMON_TRUE.  Currently,
> when i=0, all rules will erroneously be optimized out.
>
>   4157    /* Mark rules that are actually used for reduce actions after all
>   4158    ** optimizations have been applied
>   4159    */
>   4160    for(rp=lemp->rule; rp; rp=rp->next) rp->doesReduce = LEMON_FALSE;
>   4161    for(i=0; i<lemp->nxstate; i++){
>   4162      for(ap=lemp->sorted[i]->ap; ap; ap=ap->next){
>   4163        if( ap->type==REDUCE || ap->type==SHIFTREDUCE ){
>   4164          ap->x.rp->doesReduce = i;
>   4165        }
>   4166      }
>   4167    }
>

Well done.  I fear that you have had to learn more about Lemon and
LALR(1) parsing than perhaps you really ever wanted to know.  Your
efforts are greatly appreciated.
--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users