示例#1
0
def p_tuple1(p):
    '''tuple : LPAREN commalist_expr RPAREN
                        | LPAREN expr RPAREN
                        | LPAREN vdef RPAREN
                        | LPAREN assign RPAREN
                        | LPAREN commalist_def RPAREN
    '''
    p[0]=Node('tuple')
    if p[2].type == 'COMMALIST':
        p[0].elems = p[2].elems
    else:
        p[0].elems = [p[2]]
示例#2
0
def p_array(p):
    '''array : unary_expr list %prec LBRACKET
                | tuple list %prec LBRACKET
    '''
    p[0]= Node('ARRAY')
    p[0].var = p[1]
    p[0].elems = p[2].elems
示例#3
0
def p_commalist_def1(p):
    '''commalist_def : vdef COMMA vdef
                         | vdef COMMA assign
                         | vdef COMMA unary_expr
                         | assign COMMA vdef
                         | assign COMMA assign
                         | assign COMMA unary_expr
    '''
    p[0] = Node('COMMALIST')
    p[0].elems = [p[1],p[3]]
示例#4
0
def p_struct_start(p):
    """struct_start : STRUCT NAME LCURLY"""
    p[0] = Node("struct")
    p[0].name = p[2].value
    p[0].elems = []
示例#5
0
def p_list3(p):
    """list : LBRACKET RBRACKET"""
    p[0] = Node("List")
    p[0].elems = []
示例#6
0
def p_list1(p):
    """list : LBRACKET exprList RBRACKET"""
    p[0] = Node("List")
    p[0].elems = p[2]
示例#7
0
def p_dict(p):
    """dict : LCURLY range2List RCURLY"""
    p[0] = Node("Dict")
    p[0].elems = p[2]
示例#8
0
def p_exprTuple1(p):
    """exprTuple : LPAREN exprList RPAREN
    """
    p[0] = Node("Tuple")
    p[0].elems = p[2]
示例#9
0
def p_list3(p):
    '''list : LBRACKET  RBRACKET
    '''
    p[0] = Node('List')
    p[0].elems = []
示例#10
0
def p_list2(p):
    '''list : LBRACKET expr           RBRACKET
    '''
    p[0] = Node('List')
    p[0].elems = [p[2]]
示例#11
0
def p_list1(p):
    '''list : LBRACKET commalist_expr RBRACKET
    '''
    p[0] = Node('List')
    p[0].elems = p[2].elems
示例#12
0
def p_commalist_expr1(p):
    '''commalist_expr : expr COMMA expr
    '''
    p[0] = Node('COMMALIST')
    p[0].elems = [p[1],p[3]]
示例#13
0
def p_tuple2(p):
    '''tuple : LPAREN RPAREN'''
    p[0]=Node('tuple')
    p[0].elems = []