1

I read that it's mandotary to write %noyywrap or define a yywrap() function.

What if I default a yywrap() function in which I don't make any changes to yyin variable and return 0, what will happen in this case?

0 means that FLEX should must continue parsing other input files but does flex insert null inside yyin variable one it's done parsing it or in this case it goes for infinite loop?

Algo
  • 11
  • 4
  • 1
    Does this answer your question? [Meaning of yywrap() in flex](https://stackoverflow.com/questions/34479903/meaning-of-yywrap-in-flex) – Ted Lyngmo Jun 17 '23 at 08:32
  • @TedLyngmo not at all... I know that's the meaning of yywrap() and that's not my question... I have very specific question. does yyin get null value after finishing reading current file or we go in loop? – Algo Jun 17 '23 at 10:19
  • @Algo: you could easily test whether `yyin` is set to null by testing and/or printing in `yywrap`. – Jonathan Leffler Jun 17 '23 at 12:15

1 Answers1

3

If yywrap() returns 0, then the lexer will just loop (trying to) read more data. If you're using the default YY_INPUT that reads from yyin, and you haven't called clearerr on it, you'll get an infinite loop. If you call clearerr, then it will try to read more, but if yyin points at a file that hasn't changed, that will just be EOF again, and you'll still get an infinite loop.

If you've changed YY_INPUT to do something else that it will do whatever you've changed it to do.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226