-   Programming (
-   -   flex bison question (

sujandasmahapatra 11-14-2012 11:26 AM

flex bison question
I am using a library in my Qt application which is built and generated by lex and yacc compiler. When I am calling first time the function itís working fine, a good file. Next time running a bad file from within the same application for which it throws an error, from within the same application, now if I call next time for the good file also it throws the error. The problem is the error. If an error occurs then next time onwards it throws error for even for a good file. How can I clear the error stream so that it runs good for the good file. Any help is highly appreciated. Thanks Sujan

bool upgrade_model(char *model, string &newModel); //this function is exposed by the static library.

string newmodel;
 bool upgraded = upgrade_model("/home/red/good.model",&newmodel); // it runs fine
 upgraded = upgrade_model("/home/red/bad.model",&newmodel); //it throws error
 upgraded = upgrade_model("/home/red/good.model",&newmodel); //it throws error

How can I clear the error stream in the begining when a call is made to the function upgrade_model()

sundialsvcs 11-16-2012 07:59 AM

If an exception could be thrown by one of your handlers, e.g. upgrade_model(), you need to provide a way to trap that exception ... so that the handler returns false or what-not and doesn't blow completely out of the parser. Or, if you prefer to let it do that, you must be certain that the parser context (including the context of any handlers you've written) is completely re-initialized each time.

Of course, making sure that every parse starts from exactly the same state, with no residue from previous runs, is a program-design issue (on your part) that always exists. Your static-library needs to have some kind of "reinitialize" call ... right now, it's probably relying on its initial state-when-loaded.

Ultimately, this is a design flaw in your program, not in flex/bison, such that could exist in any application. Or it could be a design flaw in the library. Good luck with it.

sujandasmahapatra 11-17-2012 09:30 AM

Thanks a lot for your reply. You're correct it's reinitialization problem. I needed to make a call to 'BEGIN(INITIAL)' in my lex file before parsing. That solved the problem. Thanks a lot. Cheers

All times are GMT -5. The time now is 09:34 AM.