Hi buddies,
I want to evaluate a formula (with variable names and limited operators eg. (a+b)-c )entered in a textbox using JavaScript or PHP. Can anyone here assist me?
Thanks in Advance
-: Sithik :-
Evaluating a formula entered in a text box.
Moderator: General Moderators
-
sithik_frns
- Forum Newbie
- Posts: 1
- Joined: Mon Jul 14, 2008 12:30 am
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Evaluating a formula entered in a text box.
You'll have to ask a more specific question than that.sithik_frns wrote:Hi buddies,
I want to evaluate a formula (with variable names and limited operators eg. (a+b)-c )entered in a textbox using JavaScript or PHP. Can anyone here assist me?
Thanks in Advance
-: Sithik :-
Note that you have now posted in the regex forum. People often make the mistake of trying to write a mathematical expression parser with regex: this is really not the way to go. Regex is not the right tool.
So, I highly recommend you post your question in a more general part of this forum and ask a more specific question.
Best of luck.
Re: Evaluating a formula entered in a text box.
There are 10 types of people in this world, those who understand binary and those who don't
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Evaluating a formula entered in a text box.
Regex can definitely be useful but it's but it's only a tiny part of the solution.People often make the mistake of trying to write a mathematical expression parser with regex: this is really not the way to go. Regex is not the right tool.
sithik_frns, this is actually a pretty common thing so try searching for some existing code/library and articles. You'll want to search for "expression evaluation"
If you want to roll you own solution for fun or other reasons start with some kind of language definition - what is it going to be capable of? and a bunch of examples - this code should give this answer. Then write down the process your brain goes through in order to compute those expressions - that is what you'll have to describe to the computer.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Evaluating a formula entered in a text box.
True: as a part of the lexer, regex can be useful but, as you already mentioned, that is just a small part.Ollie Saunders wrote:Regex can definitely be useful but it's but it's only a tiny part of the solution.People often make the mistake of trying to write a mathematical expression parser with regex: this is really not the way to go. Regex is not the right tool.
...