I am building an equation parser, it takes the equation

"( 3456 + 321 * X ) / 45"

for example. As I couldn't find a direct solution to parse this equation, I split the equation and started implementing the operations 1 by 1 until I stuck with the execution order of the arithmetic operators (as the multiplication should be performed before
the addition)

So I am trying now to avoid this and try to parse the full equation.

Is there a way to convert the string "+" to + for example?

Participant

1043 Points

295 Posts

## String to Arithmetic operator conversion

Mar 18, 2009 09:30 AM|nomercy007|LINK

Hi all,

I am building an equation parser, it takes the equation

"( 3456 + 321 * X ) / 45"

for example. As I couldn't find a direct solution to parse this equation, I split the equation and started implementing the operations 1 by 1 until I stuck with the execution order of the arithmetic operators (as the multiplication should be performed before the addition)

So I am trying now to avoid this and try to parse the full equation.

Is there a way to convert the string "+" to + for example?

All-Star

124328 Points

10142 Posts

## Re: String to Arithmetic operator conversion

Mar 18, 2009 12:17 PM|SGWellens|LINK

Not they way you are thinking, + is an operator. You can create a variable, constant or enum that represents an operator.

You may want to look at the Shunting Yard Algorithm:

http://en.wikipedia.org/wiki/Shunting_yard_algorithm

My blog

Participant

1043 Points

295 Posts

## Re: String to Arithmetic operator conversion

Mar 22, 2009 03:07 AM|nomercy007|LINK

I know + is an operator. I meant "+" (plus sign between quotation marks in the code) is treated as string :

dim x as double = 3 "+" 2

will give a syntax error

I think I will go with the calculated datacolumn by using its expression property (although it supports limited operations)

thanks mentioning the Shunting Yard Algorithm, It was helpfull and I could build a better solution with.