示例#1
0
def p_arguments(t):
    '''arguments : expression
						| expression arguments'''
    if (len(t) == 2):
        t[0] = kino_compile.Tree_Node(kino_compile.ntArguments, None, t[1],
                                      t.lexer.lineno)
    else:
        t[0] = kino_compile.Tree_Node(kino_compile.ntArguments, [t[2]], t[1],
                                      t.lexer.lineno)
示例#2
0
def p_program_expr(t):
    '''program : line
					| line program'''
    if len(t) == 2:
        t[0] = kino_compile.Tree_Node(kino_compile.ntProgram, None, t[1],
                                      t.lexer.lineno)
    else:
        t[0] = kino_compile.Tree_Node(kino_compile.ntProgram, [t[2]], t[1],
                                      t.lexer.lineno)
示例#3
0
def p_parameters(t):
    '''parameters : declaration 
						| declaration parameters'''
    if (len(t) == 2):
        t[0] = kino_compile.Tree_Node(kino_compile.ntParameters, None, t[1],
                                      t.lexer.lineno)
    else:
        t[0] = kino_compile.Tree_Node(kino_compile.ntParameters, [t[2]], t[1],
                                      t.lexer.lineno)
示例#4
0
def p_primative_op(t):
    '''primative_op : PLUS
				 | MINUS
				 | MULT
				 | EQV
				 | NEQV'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntPrimative_op, None, t[1],
                                  t.lexer.lineno)
示例#5
0
def p_expression_number(t):
    '''expression : NUMBER'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntNumber, None, t[1],
                                  t.lexer.lineno)
示例#6
0
def p_primative_unary_op(t):
    '''unary_op : DEREF'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntUnaryPrimative_op, None, t[1],
                                  t.lexer.lineno)
示例#7
0
def p_primative_unary(t):
    '''expression : unary_op expression'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntUnaryPrimative, [t[2]], t[1],
                                  t.lexer.lineno)
示例#8
0
def p_primative(t):
    '''expression : expression primative_op expression'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntPrimative, [t[1], t[3]], t[2],
                                  t.lexer.lineno)
示例#9
0
def p_assignment(t):
    '''assignment : IDENTIFIER EQ expression '''
    t[0] = kino_compile.Tree_Node(kino_compile.ntAssignment, [t[3]], t[1],
                                  t.lexer.lineno)
示例#10
0
def p_loop(t):
    '''loop : WHILE LPAREN expression RPAREN LBRACE program RBRACE'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntLoop, [t[6]], t[3],
                                  t.lexer.lineno)
示例#11
0
def p_line_expr(t):
    '''line : declaration
			| assignment
			| control'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntLine, None, t[1],
                                  t.lexer.lineno)
示例#12
0
def p_function_call(t):
    '''expression : IDENTIFIER LPAREN arguments RPAREN'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntFunctionCall, [t[3]], t[1],
                                  t.lexer.lineno)
示例#13
0
def p_function_decl(t):
    '''function_decl : INT IDENTIFIER LPAREN parameters RPAREN LBRACE program RBRACE'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntFunctionDecl, [t[4], t[7]],
                                  t[2], t.lexer.lineno)
示例#14
0
def p_expression_identifier(t):
    '''expression : IDENTIFIER'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntIdentifier, None, t[1],
                                  t.lexer.lineno)
示例#15
0
def p_declaration(t):
    '''declaration : INT IDENTIFIER EQ expression
						| INT IDENTIFIER'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntDeclaration, [t[1], t[4]],
                                  t[2], t.lexer.lineno)
示例#16
0
def p_control(t):
    '''control : loop
					| conditional'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntControl, None, t[1],
                                  t.lexer.lineno)
示例#17
0
def p_conditional(t):
    '''conditional : IF LPAREN expression RPAREN LBRACE program RBRACE ELSE LBRACE program RBRACE'''
    t[0] = kino_compile.Tree_Node(kino_compile.ntConditional, [t[6], t[10]],
                                  t[3], t.lexer.lineno)