Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of yywrap() in flex

What does this instructions mean in flex (lex) :

#define yywrap() 1

and this [ \t]+$
i find it in the code below:

(%% [ \t]+ putchar('_'); [ \t]+% %%

input "hello world"

output "hello_world"

)

like image 480
deep_geek Avatar asked Dec 27 '15 11:12

deep_geek


1 Answers

According to The Lex & Yacc Page :

When the scanner receives an end-of-file indication from YY_INPUT, it then checks the yywrap() function. If yywrap() returns false (zero), then it is assumed that the function has gone ahead and set up yyin to point to another input file, and scanning continues. If it returns true (non-zero), then the scanner terminates, returning 0 to its caller. Note that in either case, the start condition remains unchanged; it does not revert to INITIAL.

The #define is used to simplify building the program (so that no -ll linkage option is needed).

Further reading:

  • What are lex and yacc?
  • Routines to reprocess input
  • 6. How do Lex and YACC work internally (Lex and YACC primer/HOWTO)
like image 136
Thomas Dickey Avatar answered Oct 04 '22 04:10

Thomas Dickey