Re: [Pyparsing] parsing with operatorPrecedence takes too much time
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2008-04-04 15:16:45
|
Ralf - Part of what you are seeing is the result of a bug-fix in pyparsing 1.4.9 (I think), in which the operands of an operatorPrecedence were evaluated once for each level in the precedence chain, including the calling of parse actions. To correct this, each level now does a lookahead to see if that level applies, and only if successful then parses that level, otherwise descends to the next level of the list. So now every level is prefixed by a "FollowedBy" with that level's expression. Since the levels nest, this gets geometrically larger as more levels are added to the list. I ran your code with a modified version of operatorPrecedence that does not do this, and the time to parse your given string dropped from .09 to .06 seconds, and the expression string representation dropped to 202600 chars. I've poked a bit at your example, and I don't see any other low-hanging fruit to crank more speed out of this parser. What you might do is try converting by hand to an explicit infix notation parser, using the style in fourFn.py that comes with pyparsing. Other than that, I would say this may be as much a pyparsing performance issue as it is operatorPrecedence. -- Paul |