Hello. I'm working on a simple calculator in FreeBasic. It works, but it's limited in what kind of math problems you can enter. You could enter something like 12*3. After you press the enter key, it prints the result which in that case would be 36. If you wanted to add 5 you could type "+5" and press enter again. Is there a way to parse math expressions in FreeBasic so that the user could enter something like 12*3+4 or 4+3(9*2)? I figure there has to be a way to be able to have a user enter more complexed expressions than two numbers and an operator, but so far, I haven't been able to figure out how to do it.
Thanks.
Ryan
parsing math expressions
Two parsers have been proposed in the old QBN forum. I have saved them in the "Files" section of my mailing list (http://groups.yahoo.com/group/fbmathlib/files/Parsers/)
If you prefer, I can repost them here.
If you prefer, I can repost them here.
marzec wrote a nice math parser already at bad-logic forums, it seems quite functional (and expandable).
Marzec's and mine do the same thing in different ways. Both are expandable and easy enough to use. I did it in RPN because that is what I was comfortable with at the time.
What was posted on QBN for both of them were WIP. I had variable and constants implimented, Marzec didn't... but could have added them in no time.
In the end, use the one you like better. I don't think anyone had done any benchmarks on who's is faster. If they did, I have a gut feeling that Marzec's would out do mine. But I feel mine is easier to follow.
What was posted on QBN for both of them were WIP. I had variable and constants implimented, Marzec didn't... but could have added them in no time.
In the end, use the one you like better. I don't think anyone had done any benchmarks on who's is faster. If they did, I have a gut feeling that Marzec's would out do mine. But I feel mine is easier to follow.
Its the very first piece of code in that thread on QBN.
http://forum.qbasicnews.com/viewtopic.p ... light=math
http://forum.qbasicnews.com/viewtopic.p ... light=math