To get ya started:
Every operator has precedence, and parenthesis "up" that precedence for that block. So lets say we only have
3 operators:
Code:
Op: Name: Precedence Value:
-----------------------------------------
/ Division 3
* Multiply 2
+ Addition 1
And lets say parenthesis add 10 to that precedence value:
Code:
Brace: Precedence Value:
( +10
) -10
[ ] { } -> same thing
Now we parse the string:
Code:
String: 2 + (2/3 * 5/6 + 4)
Braces: +10 -10
PValue: 1 13 12 13 11
What we have to do is incorporate a stack. We push (unless they're already there) their l-values and r-values and operate. The operation leaves the answer on the
stack. Ex: pushing 2 values and adding leaves one value on the top of the stack -> the answer.
There are many ways to do this. Here's one way where we start with the highest value operators:
Code:
push 2
push 3
divide
push 5
push 6
divide
multiply
push 4
addition
push 2
addition
This way uses post-fix "syntax" (make a search; I think that's how you call it). We push all the values from lowest priority to first, then operate all at once:
EDIT: Method two doesn't work, lol, but it can if you do it right, I'm going to sleep now....
Code:
push 2
push 4
push 2
push 3
push 5
push 6
divide
divide
multiply
addition
addition
And what's left on the stack is the answer! Hope I helped...