Reputation: 2315
I am following the other examples on this site about how to parse a string with flex:
yy_scan_string(string);
yylex();
yyparse();
yy_delete_buffer( YY_CURRENT_BUFFER );
line 4 gives the problem it says
error: ‘YY_CURRENT_BUFFER’ undeclared (first use in this function)
I also don't get YY_BUFFER_STATE, by the way I am calling them from the bison file (.y), so they should be available. I am not sure why it is not finding the typedefs. I didn't come up with anything on the first dozen links on google Any help would be appreciated.
Upvotes: 3
Views: 3343
Reputation: 126448
YY_CURRENT_BUFFER
and YY_BUFFER_STATE
are defined by flex, not bison, so they're defined (and used) in the lex.yy.c
file generated by flex. So you can only access them from the .l
file, not from the .y
file.
If you want to access them in a bison grammar, the easiest way is to encapsulate the use of them in a small function you define in the 3rd section of the .l
file. Then you call that function from the .y
file or any other source file.
Upvotes: 5