Jump to content
  • Advertisement

Archived

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

_walrus

Help with Lex

This topic is 5372 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
Advertisement
yeah, yylex() will return whatever the matched rule returns.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!