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?
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?
How did you construct the grammar?
ASKER
Exactly as the grammers for all the other expressions are in the repository.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.