Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Expression evaluator
#41
oh of course. cool.
Reply
#42
Hey guys,
I know this thread is almost dead, but I remembered something important regarding expression evaluators while working on another post by Agamemnus. I'll repeat here what I wrote to him.

DON'T THROW THIS PROGRAM AWAY. About 2 years ago a supervisor from the accounting dept where I worked, asked me to write a simple expression evaluator to be used in a data entry program.

The data that was entered into this program, very often had to be multiplied or divided by an exchange rate to convert it to US Dollars or Mexican Pesos. The person having to do the data entry would have to enter the data into a calculator and then enter the result into the data entry program, increasing the time and risk of error.

This supervisor's brilliant idea was to have me enhance the data entry program to recognize that an expression was entered, resolve the expression, and enter the result directly.

PRETTY COOL IDEA, NO?
*****
Reply
#43
yeah - I think expression evaluators are really cool & useful.
Reply
#44
Methinks aga's one could be better if he formatted the input string he was given to reduce the chance of programmer input error, rather than just saying "the user should do that".
Reply
#45
Well, reformatting and fixing this really is easy, one way is just to seperate everything into words, like (10+20) goes into..
array(0) = "("
array(1) = "10"
array(2) = "+"
array(3) = "20"
array(4) = ")"

its not too hard to make a program that changes a line into words like that but i like aga's way its just nice and simple, that could easily be modified, but yeah if it were to actually be in any product then you'd prolly need to fix that, heh.
/rant
Reply
#46
Why complicate it? infix to postifx + rpn is the best solution.
oship me and i will give you lots of guurrls and beeea
Reply
#47
Dammit, Blitz. This is the best solution.

rpn?
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#48
LOL. Try read that from my point of view.

"This is bettar!"
"What is rpn?"

You cant claim yours is better without knowing what he means, can you :S.

RPN is reversed polish notation. It is an extremely simplified format for displaying mathematical expressions

i.e.

infix:
5 * (3 + 4)

postfix (RPN):
3 4 + 5 *

There is no brackets (no need for recursion), and no order of operation . You just scan from left to right and its damn easy to parse it.

push 3
push 4
pop a '4
pop b '3
push a + b '7
push 5
pop a '5
pop b '7
push a * b '35

the top of your stack is now the answer. However, the only trouble is converting from infix to postfix (RPN) notation. Im still trying to figure out myself how i should be going about how to do this.

:???: I hope i didnt make much mistakes in there.
Reply
#49
Quote:[...]the top of your stack is now the answer. However, the only trouble is converting from infix to postfix (RPN) notation. Im still trying to figure out myself how i should be going about how to do this.

My expression evaluator works this way. If you take a glance at it (and add a PRINT at the top with the received data) you'll notice that it parses the string and extract members to make recursive calls using RPN. The prob comes with 2 * -3 'cause I made a mistake in the parser, but it can be easily solved.

I sum: My expression evaluator works in RPN translating an infix string at the same time.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#50
Well, I don't see the point of it. Using a string as input, if you have to use time translating to postfix, and then solve it, it takes more processing time to do so. Why not just get the numbers and run with them instead of changing formats and then solving?

See, Blitz. You know nothing.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)