示例#1
0
def p_comma_separated_expr(p):
    """
    arguments : arguments COMMA expression
              | expression
              |
    """
    if len(p) == 2:
        p[0] = ast.InstructionList([p[1]])
    elif len(p) == 1:
        p[0] = ast.InstructionList()
    else:
        p[1].children.append(p[3])
        p[0] = p[1]
示例#2
0
def p_statement_list(p):
    """
    statement_list : statement
                   | statement_list statement
                   |
    """
    if len(p) == 2:
        p[0] = ast.InstructionList([p[1]])
    elif len(p) == 1:
        p[0] = ast.InstructionList([ast.PassStatement()])
    else:
        p[1].children.append(p[2])
        p[0] = p[1]
示例#3
0
def p_statement_list(p):
    '''
    statement_list : statement
                   | statement_list statement
    '''
    if len(p) == 2:
        p[0] = ast.InstructionList([p[1]])
    else:
        p[1].children.append(p[2])
        p[0] = p[1]
示例#4
0
def p_function_declaration(p):
    """
    statement : FUNCTION identifier LPAREN arguments RPAREN LBRACK statement_list RBRACK
              | FUNCTION identifier LBRACK statement_list RBRACK
    """
    p[2].is_function = True

    if len(p) == 9:
        p[0] = ast.Assignment(p[2], ast.Function(p[4], p[7]))
    else:
        p[0] = ast.Assignment(p[2], ast.Function(ast.InstructionList(), p[4]))