LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2012, 10:26 AM   #1
sujandasmahapatra
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
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
Code:
 bool upgrade_model(char *model, string &newModel); //this function is exposed by the static library.
Code:
 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()
 
Old 11-16-2012, 06:59 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,599
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
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.
 
Old 11-17-2012, 08:30 AM   #3
sujandasmahapatra
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Flex & Bison] How to check which state Flex is in? courteous Programming 0 06-03-2011 11:46 AM
Is there any support for bison-bridge and bison-locations in flex on windows systems? rami alkhateeb Linux - Software 0 12-29-2010 09:10 AM
installing bison and flex rameshsena Linux - Software 10 06-21-2010 11:33 AM
flex and bison saurav.nith Linux - General 1 04-06-2010 06:38 AM
bison / flex zaman Programming 1 08-16-2005 10:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration