help-bison
[Top][All Lists]
Advanced

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

Re: confusing bison error


From: Akim Demaille
Subject: Re: confusing bison error
Date: Fri, 27 Nov 2020 08:47:05 +0100

Hi Jot,


> Le 27 nov. 2020 à 01:11, Jot Dot <jotdot@shaw.ca> a écrit :
> 
> FWIW: I'm new to flex/bison (lex/yacc) but I understand the basic concepts. 
> win_flex 2.6.4 
> bison (GNU Bison) 3.7.1

I'd prefer that you use the most recent release, although it shouldn't make any 
difference here.

> Having said that, everything compiles but it seems like the parser can't pick 
> up the single characters. 
> For example, the parser rule: 
> 
> single_const_decl: IDENTIFIER '=' expression ; 
> 
> The parser returns an error after it gets the IDENTIFIER and fetches an error 
> token instead of the '='. 
> I have figured out how to get the trace output and can confirm this: 
> 
> Trace says it goes into state 6: 
> 
> State 6 
> 
> 5 stmts: CONST_ . const_decl 
> 10 | CONST_ . const_decl ';' stmts 
> 46 const_decl: . single_const_decl 
> 47 | . const_decl ';' single_const_decl 
> 48 single_const_decl: . IDENTIFIER '=' expr 
> 
> IDENTIFIER shift, and go to state 14 <<<<< Trace says it goes to state 14 
> 
> const_decl go to state 15 
> single_const_decl go to state 16 
> 
> State 14 
> 
> 48 single_const_decl: IDENTIFIER . '=' expr 
> 
> '=' shift, and go to state 31 <<=== Does not happen. Returns an error token 
> instead. 

What do you mean?  It did display "go to state 31", but did not?  Could you 
please provide us with the full trace?  Also, have you tried to enable the Flex 
traces, just in case.


> FLEX: 
> 
> %option nodefault 
> %option c++ 
> %option yyclass="Scanner" 
> %option prefix="gen" 
> %option noyywrap 

Wow, you're brave :)

> %option yylineno 
> %option case-insensitive 
> %option nounistd 
> %option stack 
> 
> inum [0-9]+ 
> alpha [A-Za-z_]+ 
> ident {alpha}({alpha}|{inum})* 
> 
> /* *snip* */ 
> 
> %% 
> 
> /* *snip* */ 
> {ident} { return gen::Parser::make_IDENTIFIER(result.makeIdentifier(yytext), 
> loc); } 

Can you show how you handle '='?

> /* everything else */ 

I learned to distrust Flex's handling of comments when they are in column 0.

> [ \t\r\n]+ ; /* whitespace */ 

FWIW, I prefer to explicitly  "continue;" in these cases.

> . { return gen::Parser::make_YYerror(loc); } // { yyerror("Unknown character 
> '%c'", *yytext); } 
> 
> 
> NOTE: In case this matters, I would have assumed the whitespace rule and the 
> '.' would have taken care of all possible input conditions but I still get 
> this: 
> 1>Target FlexTarget: 
> 1> Process "scanner.l" flex file 
> 1> scanner.l:154: warning, -s option given but default rule can be matched 

I don't understand either.  You don't play with start conditions, do you?


Cheers!


reply via email to

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