Add function parsing to simple pyparsing arithmetics grammar

前端 未结 1 1501
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 19:51

I have this code:

    import pyparsing as pp

    point = pp.Literal(\".\")

    number = pp.Combine(pp.Word(pp.nums) + pp.Optional(point + pp.Word(pp.nums)))

          


        
相关标签:
1条回答
  • 2021-01-25 19:55

    In this grammar, a function call is at the same level as a variable reference or numeric literal, so I would add it as part of the definition of atom:

    function_call = Group(ident + lpar + Group(Optional(delimitedList(expr))) + rpar)
    
    atom = number | function_call | ident | pp.Group(lpar + expr + rpar)
    

    Also note the use of delimitedList in place of expr + ZeroOrMore(comma + expr).

    0 讨论(0)
提交回复
热议问题