flex
flex copied to clipboard
[Help] C++ changing the yyflex function
I want to change yylex
to alpha_yylex
, that also takes in a vector as an argument.
.
.
#define YY_DECL int yyFlexLexer::alpha_yylex(std::vector<alpha_token_t> tokens)
%}
.
.
. in main()
std::vector<alpha_token_t> tokens;
while(lexer->alpha_yylex(tokens) != 0) ;
I think i know why this fails, because obviously in the FlexLexer.h
there is NO alpha_yylex
, but i don't know how to achieve what i want...
In C it seems to be dead simple ,just use #define YY_DECL int alpha_yylex(***)
.
How can I make my own alpha_yylex() or modify the existing one?
If you haven't already, take a look at the tests/cxx_*.ll files to see how the options for C++ are set up. The options in tests/cxx_basic.ll are sufficient to get started.
To do what you want, you'll probably need to subclass yyFlexLexer to overload the yylex method or add an alternative. You can try injecting your subclass's header into the lexer and defining YY_DECL.
As an alternative to injecting your subclass into the lexer, you could implement your alpha_yylex to produce a std::istream& from the vector and feed that to yyFlexLexer::yylex( std::istream&, std::ostream&). (Pass std::cout for the ostream& if you don't have anything else defined.) The "%option c++" sets up YY_DECL to call a version of yylex that will work fine with this setup.