Re: glr-parser hands me the wrong token
Adam Wozniak <[email protected]> Sat, 8 Apr 2023 15:43:18 -0700
| Newsgroups | gmane.comp.parsers.bison.bugs |
|---|---|
| Message-ID | <CA+JkkaDY2=LE_LYeb_=F1J6J4z75kQX-B-wGpsCnyrbKwW2xOQ@mail.gmail.com> |
On inspection, i think the problem is not Bison, but my lack of understanding of the rule of yytext. (i should be using yylval instead) i'll leave the code up though, as i think it's an good example of my misconception. (maybe the docs can be modified to warn of this pitfall?) On Sat, Apr 8, 2023 at 11:22=E2=80=AFAM Adam Wozniak <[email protected]= om> wrote: > this is all from the README.txt along with sample code that demonstrates > the problem i put up on > https://github.com/GorillaSapiens/bison_glr_bug > > =3D=3D=3D=3D > > # bison_glr_bug > > ######## the bug > > essentially, i believe the Bison glr-parser is handing me the wrong > yylloc and yytext under some circumstances. > > in my code... > > language.ypp: > 805 iconst : YYINTEGER > 806 { > 807 $$ =3D 0; > 808 printf("=3D=3D=3D> %s:%d source %d:%d '%s'\n", __FILE__, __LINE__, yy= lineno, > yylloc.first_column, yytext); > 809 assert(yytext[0] !=3D ','); > 810 } > 811 ; > > language.l: > 35 I_ZERO ([0]) > 36 I_NONZERO ([1-9][0-9]*) > 37 INTEGER {I_ZERO}|{I_NONZERO} > [...] > 92 {INTEGER} {=E2=8F=8E > 93 flexdebug(__LINE__, yytext, (int) YYINTEGER, > yylineno, yylloc.first_column);=E2=8F=8E > 94 return YYINTEGER;=E2=8F=8E > 95 }=E2=8F=8E > > As you can see, the yytext for an YYINTEGER should **NEVER** contain a ',= '. > But yet, i'm seeing this happen (see below). > > ######## how to reproduce > > $ git clone https://github.com/GorillaSapiens/bison_glr_bug.git > [...] > > $ make > [...] > > $ ./language program.txt > .l line 88, 'b', 258, source 1:1 > .l line 108, '=3D', 61, source 1:3 > .l line 88, 'a', 258, source 1:5 > .l line 108, '<', 60, source 1:6 > .l line 93, '1', 299, source 1:7 > .l line 108, ',', 44, source 1:8 > =3D=3D=3D> language.ypp:808 source 1:0 ',' > language: language.ypp:809: YYRESULTTAG yyuserAction(yyRuleNum, int, > yyGLRStackItem*, yyGLRStack*, long int, YYSTYPE*, YYLTYPE*): Assertion > `yytext[0] !=3D ','' failed. > Aborted (core dumped) > >