# LabVIEW

cancel
Showing results for
Did you mean:

## Operator Precedence

Hi, I am working on a standard calculator project. I need to know how to bring Operator Predence logic inside the program. Any one help! Thanks in advance

Best Regards,
Dhans 😉
Kudos are welcome 😉
Aspirant Labview Programmer (Labview 14) 😉
Message 1 of 20
(3,446 Views)

## Re: Operator Precedence

Inside of what program?

Message 2 of 20
(3,441 Views)

## Re: Operator Precedence

I think that the Principle of Data Flow defines operator precedence -- an Operator doesn't proceed until all of its Inputs are satisfied.  Thus while 2+3*4 requires a precedence "rule" to know if this is (2+3)*4 or 2+(3*4) (the latter is the usual "rule"), there is no ambiguity in LabVIEW:

Bob Schor

Message 3 of 20
(3,436 Views)

## Re: Operator Precedence

In the calculator program. I am storing Values as string in the array. So at the end of the calculation i need to extact vaues. Let me show you a simple example.

1+2*8-6 . This is the data that is shown in the display when i press on the calculator. Naturally, We calculate this exprssion as 1+(2*8)-6 = 11. But since i am storing operators as string, i doubt that there may be a chance for precednce fault when i implement calcuation logic while extracting those datas from array like (((1+2)*8)-6) .Thats why i am asking how to incorporate operator precedence logic.

Best Regards,
Dhans 😉
Kudos are welcome 😉
Aspirant Labview Programmer (Labview 14) 😉
Message 4 of 20
(3,423 Views)

## Re: Operator Precedence

Do you have to use that notation? With RPN the solution would be trivial.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 5 of 20
(3,404 Views)

## Re: Operator Precedence

"Eval Formula String"

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Message 6 of 20
(3,392 Views)

## Re: Operator Precedence

I'd be interested to see any calculator that interprets 1+2*8-6 as 1+(2*8)-6.  Calculators solve equations in the order they are input unless you have the ability to enter parentheses into the calculation.  IMHO, it's not a good calculator if it makes assumptions about what the operator wants, rather than doing what the operator says.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 7 of 20
(3,369 Views)

## Re: Operator Precedence

I'm surprised that you are surprised.

Any scientific calculator I've used in the last 30 years uses the normal math order of operations.

Now some cheap calculator that is used by any non-math people to help them balance their checkbook, that may resort to the order of operations being based on order of entry.

Message 8 of 20
(3,361 Views)

## Re: Operator Precedence

@aputman wrote:

I'd be interested to see any calculator that interprets 1+2*8-6 as 1+(2*8)-6.  Calculators solve equations in the order they are input unless you have the ability to enter parentheses into the calculation.  IMHO, it's not a good calculator if it makes assumptions about what the operator wants, rather than doing what the operator says.

aputman is correct here.

If I enter 1+2*8-6 im my calculator it responds like this:

I enter 1+2 as soon as I hit * the calculator shows the answer for 1+2 (3)

I hit the 8 and the calculator shows 24

Finish with - 6 and the answer is 18

========================
=== Engineer Ambiguously ===
========================
Message 9 of 20
(3,357 Views)

## Re: Operator Precedence

While aputman makes a good point, if you want to actually define and assign operator precedence to such a string, then you need to parse the string by precedence. Find the high priority operators such as * first and evaluate. Then repeat the parsing for the next level of precedence.   That kind of process can be extended to as many levels of precedence as you want. It can get pretty messy of you have things like -2^4*7+5*6. Plus you probably need to include parsing of parentheses for situations which are not conveniently encoded in simple strings.

Lynn

Message 10 of 20
(3,353 Views)