I've tried taking this code and converting it to something for a project I'm working on for programming language processing, but I'm running into an issue with a simplified version:
op = oneOf( '+ - / *')
lparen, rparen = Literal('('), Literal(')')
expr = Forward()
expr << ( Word(nums) | ( expr + op + expr ) | ( lparen + expr + rparen) )
I've played around with a number of different modifications of this simple setup. Usually, trying something like:
print(expr.parseString('1+2'))
Will return ['1']
. While I get caught in deep recursion with something like:
print(expr.parseString('(1+2)'))
What am I missing with respect to simple recursion that I can't parse arbitrarily arithmetic expressions, such as 1+(2 * 3-(4*(5+6)-(7))...
?