How do I get bison/flex to restart scanning after something like token substitution?

Posted by chucknelson on Stack Overflow See other posts from Stack Overflow or by chucknelson
Published on 2010-04-21T22:22:02Z Indexed on 2010/04/21 22:23 UTC
Read the original article Hit count: 267

Filed under:
|
|
|
|

Is there a way to force bison and/or flex to restart scanning after I replace some token with something else?

My particular example would be with replacement for a specific word/string. If I want a word of hello to be replaced by echo hello, how can I get flex or bison to replace hello and then start parsing again (to pick up 2 words instead of just one). So it would be like:

  • Get token WORD (which is a string type)
  • If hello, replace token value with echo hello
  • Restart parsing entire input (which is now echo hello)
  • Get token WORD (echo)
  • Get token WORD (hello)

I've seen very tempting functions like yyrestart(), but I don't really understand what that function in particular really accomplishes. Any help is greatly appreciated, thanks!

© Stack Overflow or respective owner

Related posts about yacc

Related posts about bison