alex / rply

An attempt to port David Beazley's PLY to RPython, and give it a cooler API.
BSD 3-Clause "New" or "Revised" License
381 stars 60 forks source link

Implicit multiplication parsing issues #117

Closed Tom-the-Bomb closed 1 year ago

Tom-the-Bomb commented 1 year ago

I'm making a basic algebraic/mathematical equation parser, and I'm having a problem where unary operations make things a bit odd.

with unary operations implemented the way I have: 1 + 2 + 3 : 2 + 3 gets evaluated before 1 + 2 even though addition associativity is left.

Removing the unary operation rules and also there are also a couple of other changes fixes that but that messes up the precedence for implicit multiplication where: 1 + 2x : 1 + 2 becomes 3 before 2x becomes 2*x

I have no clue what's wrong

Code: https://mystb.in/RestoredSensitiveExemption (still being edited on my end)

(Combining the code in the rply documentation example produces the same problem)

nobodxbodon commented 1 year ago

As a reference, this commit adds support for expressions like 3a+4b:

https://gitee.com/MulanRevive/mulan-rework/commit/5d7f4aba97a3a822bf08e8198f013046eedf4915

Tom-the-Bomb commented 1 year ago

Thank you for that, but I've managed to work out a solution myself that passes my current test cases. :)