I'm trying to parse a simple language. The trouble comes with parsing function calls. I'm trying to tell it that a function call is an expression followed by left parenthesis, argument list, and right parenthesis. I have something like this:
expr = Forward()
iden = Word(alphas+'_', alphanums+'_')
integer = Word(nums)
binop = operatorPrecedence(expr, ...) # irrevelant
call = expr + Literal('(') + delimitedList(expr) + Literal(')')
expr << call | integer | iden
The problem is obvious: expr is left-recursive. However, I can't figure what to do to solve this. I'm experienced with right-recursive-style grammars(a.k.a. PLY, Yacc, etc.) but am still trying to figure out left-recursive grammars.
expr, only with a sub-production ofexpr.) I don't knowpyparsingwell enough to know if (b) is an option.callwas anatom(not anexpr) followed by a parenthesizedarglist, and produced apower(not anexpr). Just figure out where in the precedence you want call expressions to go, split theoperatorPrecedencegroup into the half about that and the half below that, and explicitly put the call in between. (But, you know, actually look at the pyparsing examples or Python grammar rather than trusting my memory.:))