views:

187

answers:

3

I'm about to start developing a sub-component of an application to evaluate math functions with operands of C++ objects. This will be accessed via a user interface to provide drag and drop, feedback of appropriate types followed by an execute button.

I'm quite interested in using flex and bison for this having looked at equation parsing and the like, both here and further afield. What I'm unsure of is if flex/bison is appropriate when you're trying to parse with custom C++ types? Obviously normal parsing is with text and this is quite a departure from that so wanted so too see what people thought, and see if I'm trying to put a square peg in a round hole.

What do you think?

Edit

There are some very good sources of information in the links people have provided below. One that looks promising but hasn't been mentioned yet is Boost.Spirit. I was taking a look though the examples earlier today and there are some informative calculator based examples in the boost/libs/spirit/examples directory should you have boost downloaded and be interested. Their homepage is here.

A: 

Certainly sounds like a square peg in a round hole to me (unless I grossly misunderstand the question):

Flex would create a state machine to tokenize a stream, in your case - the contents are already tokenized

Bison sounds a bit more relevant, since it can deal with operator precedence, but integrating with it would be too much of a pain for the relatively small benefit.

Ofir
Thanks for the answer. I think you understand the question alright, it's just not the right tool combo for the job (sadly!).
acju
+2  A: 

Please checkout muparser

RP
Very interesting link, thanks for that. I'm going to have a look through this today.
acju
+1  A: 

Flex and Bison are the right tool for parsing arithmetic expressions, equations and the like.

Here are few examples:

Danilo Piazzalunga
Thanks, I'd seen the top link but not the templated version. I'll put this on the list of possibles.
acju
You're welcome! :) Please vote up the helpful answers and, possibly, choose the most helpful (if any) as the accepted answer.
Danilo Piazzalunga