Python PLY zero or more occurrences of a parsing item

Posted by None on Stack Overflow See other posts from Stack Overflow or by None
Published on 2010-05-08T16:21:47Z Indexed on 2010/05/08 16:28 UTC
Read the original article Hit count: 161

Filed under:
|
|
|
|

I am using Python with PLY to parse LISP-like S-Expressions and when parsing a function call there can be zero or more arguments. How can I put this into the yacc code. This is my function so far:

def p_EXPR(p):
    '''EXPR : NUMBER
            | STRING
            | LPAREN funcname [EXPR] RPAREN'''
    if len(p) == 2:
        p[0] = p[1]
    else:
        p[0] = ("Call", p[2], p[3:-1])

I need to replace "[EXPR]" with something that allows zero or more EXPR's. How can I do this?

© Stack Overflow or respective owner

Related posts about python

Related posts about ply