[Pyparsing] Operator Precedence and Associativity.
Brought to you by:
ptmcg
From: Ralph C. <ra...@in...> - 2006-09-12 12:24:22
|
Hi, PyParsing seems great; many thanks. But I'm having trouble concocting the right grammar for the typical binary operator part. I'm aware of the latest fourFn.py but its use of ZeroOrMore() results in + 1 + 2 + 3 ==> /|\ 1 2 3 whereas I'd like the left associativity explicit, i.e. + / \ 1 + 2 + 3 ==> + 3 / \ 1 2 I can achieve this with a right-associative operator, e.g. exponent, but how do I do this for left-associative ones whilst avoiding endless left-recursion? I wonder if PyParsing would benefit from being able to define operator tables, similar to K&R's, giving the tokens, precedence, and associativity, and being able to plumb that into the rest of the recursive descent parser at some point? Cheers, Ralph. |