Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

yacc/bison locations

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 RenderTarget   Members   

398
Like
Likes
Like

Posted 07 January 2004 - 03:24 PM

So I''m trying to get bison (1.85) to report line numbers for syntax errors. I have flex assigning to yylloc, and the %locations directive in the grammar file, and all that business. I can get the @n values beautifully for non-syntax-errors. But in cases where bison can''t match a rule, it fires off the syntax error message before I can set a line number for it to use (it fires it off before performing the error action in any rule). I even tried it in the YYLLOC_DEFAULT, but that''s performed afterwards too. I guess I need to know what yyerror() needs to access when reporting a syntax error. Is there an internal variable which stores the correct yylloc for the erroneous token? I like pie.

#2 Grunhund   Members   

122
Like
Likes
Like

Posted 07 January 2004 - 04:58 PM

What I did in this situation (if I understand your problem correctly), is use the yylineno variable. In some implementations it is updated automagically. If not then in your flex/lex file just add the rule below to your grammer

''\n'' { yylineno++;}

or something similar and you can then access the line number bison choked on in yyerror.

Hope this helps,
Grunhund

#3 RenderTarget   Members   

398
Like
Likes
Like

Posted 07 January 2004 - 10:13 PM

Yeah, that''s pretty much what I needed, thanks! Though I eschewed the yylineno and declared my own iLineCur variable, which I increment myself in my ''\n'' action. It''s slightly more efficient, because with %option yylineno, every action is forced to scan for ''\n'' instead of the one I devote to just that. (In other words, if %option yylineno is active, yytext will be scanned an additional time, to count ''\n'' characters. Since I only have one rule which matches ''\n'', the counting is easier, and I save on the rescan.)

I like pie.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.