Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex does not remove yyunput even with suitable flags

Tags:

flex-lexer

lex

I'm Flexing a file with the

%option nounput

Option and using the command line

flex --nounput

And flex version 2.5.35.

However, the cpp output still contains the line

#define unput(c) yyunput( c, (yytext_ptr)  )

And this causes compilation problems with g++ since unput is not used.

Is there some way to fix this problem in a "clean" way? The two dirty ways are obvious:

  1. Use unput in some useless way.
  2. Remove the line automatically from the generated cpp file using some script.
like image 747
Gadi A Avatar asked Dec 01 '25 09:12

Gadi A


2 Answers

(I tried to flag this question as "problem no longer reproducible" but the flag timed-out/aged away. I'm answering it so that it does not remain an open unanswered question.)

As mentioned by @akond:

I don't experience this problem. The version I am using is the same (flex 2.5.35). %option nounput does the trick for me.

I also tried this on version 2.5.4 and can confirm there is no issue. The option --nounput is no longer recognised or documented; however, the %option nounput remains in the manual.

The cpp output still does contain the line #define unput(c) yyunput( c, yytext_ptr ) but this does not seem to generate any g++ errors for me. Are you using -pedantic-errors or some other similar option perhaps?

like image 62
Brian Tompsett - 汤莱恩 Avatar answered Dec 04 '25 03:12

Brian Tompsett - 汤莱恩


Good program but badly out of date documentation.

I found that version 2.6.4 accepts the nounput option and does the right thing.

like image 40
Tim Allman Avatar answered Dec 04 '25 03:12

Tim Allman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!