Archived

This topic is now archived and is closed to further replies.

Help with Lex

This topic is 5153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, is it possible to get flex/lex to stop after matching a token? I want to beable to stream in tokens one by one (as opposed to getting an array of all the tokens; its not practical with large files). I can probably modify the yylex function to stop after each match, but i want to avoid this (this will cause me to have to make the moddifications every time I generate the lex file). Thanks Example of what i want
%%
Token nextToken;

%%
{digit}+"."{digit} emitFloat();
{digit}+ emitInteger();
EOF emitEOF();
%%

void emitFloat()
{
  nextToken = Token(atof(yytext));
}
void emitInteger()
{
  ...
}
void emitEOF()
{
  nextToken = Token(EOF);
}

void main() 
{
 yylex();

 while(!nextToken.isEOF())
 {
   yylex();
   //do something with the nextToken
 }

}
 

Share this post


Link to post
Share on other sites