bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glr-parser hands me the wrong token


From: Adam Wozniak
Subject: Re: glr-parser hands me the wrong token
Date: Sat, 8 Apr 2023 15:43:18 -0700

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 AM Adam Wozniak <embracetheape@gmail.com>
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
>
> ====
>
> # 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                      $$ = 0;
> 808 printf("===> %s:%d source %d:%d '%s'\n", __FILE__, __LINE__, yylineno,
> yylloc.first_column, yytext);
> 809                      assert(yytext[0] != ',');
> 810                   }
> 811                ;
>
> language.l:
>  35 I_ZERO      ([0])
>  36 I_NONZERO   ([1-9][0-9]*)
>  37 INTEGER     {I_ZERO}|{I_NONZERO}
> [...]
>  92 {INTEGER}         {⏎
>  93                      flexdebug(__LINE__, yytext, (int) YYINTEGER,
> yylineno, yylloc.first_column);⏎
>  94                      return YYINTEGER;⏎
>  95                   }⏎
>
> 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, '=', 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
> ===> language.ypp:808 source 1:0 ','
> language: language.ypp:809: YYRESULTTAG yyuserAction(yyRuleNum, int,
> yyGLRStackItem*, yyGLRStack*, long int, YYSTYPE*, YYLTYPE*): Assertion
> `yytext[0] != ','' failed.
> Aborted (core dumped)
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]