but the grammar validation time is substantially large and as the arithmetic expression grows in size, time to parse the expression also grows exponentially. Any help would be appreciated. :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
operand = pp.oneOf([i for i in pp.alphanums]) # Common.indexed_field | Common.fnumber
I confirmed the dramatic increase in processing time.
The Wikipedia article says that using a packrat parser can trade time for space, and pyparsing does support packrat parsing. I haven't experimented with it much, so I just added "arith_expr.enablePackrat()" to the end.
Unfortunately, when I tried arith_expr.parseString("x+y+z") or even something simpler, after enabling packrat parsing, it raised an exception with about a 500 line traceback.
I'm sorry that doesn't help you, and doesn't give any insight into the reason pyparsing crashed with packrat enabled.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have wrote the following piece of code to parse arithmetic expressions containing logarithms and exponentials like;
but the grammar validation time is substantially large and as the arithmetic expression grows in size, time to parse the expression also grows exponentially. Any help would be appreciated. :)
I think the situation is described http://en.wikipedia.org/wiki/Parsing_expression_grammar#Implementing_parsers_from_parsing_expression_grammars.
I wasn't sure how you had defined Common, so I made mine simply match any letter or number, which is enough for the examples you gave.
I confirmed the dramatic increase in processing time.
The Wikipedia article says that using a packrat parser can trade time for space, and pyparsing does support packrat parsing. I haven't experimented with it much, so I just added "arith_expr.enablePackrat()" to the end.
Unfortunately, when I tried arith_expr.parseString("x+y+z") or even something simpler, after enabling packrat parsing, it raised an exception with about a 500 line traceback.
I'm sorry that doesn't help you, and doesn't give any insight into the reason pyparsing crashed with packrat enabled.