I'm trying to figure out how to do a left-associative expression where recursive (not-enclosed in anything) expressions are possible. For example, I'd like to do:
expr + OP + expr
that parses 2 operations like 1 x 2 x 3
into (expr OP expr) OP expr
result.
If I try to prevent expr
parsing from infinite recursion, i can do something like:
expr -> Group(simple_expr + OP + expr)
| simple_expr
but then I'd get the expr OP (expr OR expr)
result.
How do I force left-side binding?
Edit: I know about the operatorPrecedence
but when the operator is "IS" + Optional("NOT")
or similar, it doesn't seem to match properly.
Here is an example parse action that will take the flat lists of tokens and nest them as if parsed left-recursively:
Prints:
(normal)
(LR-like)
Pyparsing produces left parse trees. Add a semantic action to edit the parse tree right after
expr
has been parsed.