Reputation: 1
I am calling yyparse()
multiple times with the same input file. I have to start parsing from beggining of the file upto some point and then jump to some other location in the same file (parse some lines there), and then come back to original position and start parsing again from there. This I am doing many times. Each time before I call yyparse()
, I am opening the same input file freshly, and then pointing to position, from where i have to start parsing.
I am having problem in returning back to original position. I can jump to some other location, but returning from there to original position is problem. My parser is going to some other location while returning, parse few lines from there, and then come to original position. How can i avoid these extra line parsing? I am using yyrestart();
before new call to yyparse();
Upvotes: 0
Views: 1454
Reputation: 409136
Instead of restarting the parse each time you need to change position, you can do this all in the lexer.
When you need to parse another place in the file, push the current lexer state on to a stack, and set a new lexer stat to the position you want. When done, then just pop the state off the stack to make it current and continue parsing as if nothing happened.
A possible better solution is probably to do a straight parse of the source file, building an AST, and then you can easily do semantic handling and/or evaluate parts as you like. It will make the lexer and parser much simpler.
Upvotes: 2