sancarn / stdVBA

VBA Standard Library - A Collection of libraries to form a common standard layer for modern VBA applications.
MIT License
294 stars 58 forks source link

Parsing arithmetic operators in StdLambda #32

Closed giulio-mae closed 3 years ago

giulio-mae commented 3 years ago

Hello, I probably found an issue in how StdLambda parses expressions involving and / operators. Consider the following: Set lambda = stdLambda.Create("$1 $2 / $3 * $4")

If I evaluate lambda(1,2,2,2), the result is 0.5 instead of 2.

Thank you

sancarn commented 3 years ago

Can confirm the bug, thanks :)

TarVK commented 3 years ago

I have a hunch of why this may be happening. I think operations are accidentally executed from right to left, instead of left to right. That would at least explain the result of 0.5. Of course not having proper priority would also explain it (executing * before /), but I am quite sure we did take care of having them on the same level.

Edit: We confirmed 2/2/2 results in 2, instead of 1/8. So it indeed appears to be executing right to left.

sancarn commented 3 years ago

Reviewed with Tar. Tar noticed that parseArithmeticPriority4 should be calling parseArithmeticPriority5. Ultimately this was a typo. Thanks for reporting the issue!

giulio-mae commented 1 year ago

Hi, I recently updated the library to the newest version and I think this bug has reappeared... Set lambda = stdLambda.Create("$1 / $2 / $3") lambda(2, 2, 2) is again evaluated as 2

sancarn commented 1 year ago

@giulio-mae Thanks, not sure how this snuck back in again... But fixed again now 👍