Link to home
Start Free TrialLog in
Avatar of nullmind
nullmind

asked on

JavaCC expression parsing

I'm using JavaCC to parse expressions and generate a parse tree (not using JJTree,) and I've ran into a problem. JavaCC grabs the expresions from right-to-left, but I need to grab them left-to-right.

For example this expression:

5+2-3-1

This should be 3. However it wil end up being 5:

(3-1) = 2
(2-2) = 0
5 + 0 = 5

I want to reverse this process.. What can I do? I've constructed a very simple parse tree, do I need to iterate over the tree in a different order?
Avatar of ozo
ozo
Flag of United States of America image

How did you construct the grammar?
Avatar of nullmind
nullmind

ASKER

Exactly as the grammers for all the other expressions are in the repository.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial