示例#1
0
文件: parser.py 项目: EnriqueB/GProg
def p_var_value(p):
    '''var_value : ID saw_id EQUALS expression SEMI'''
    global q, directoryTable
    op1 = q.popOperandStack()
    var = q.popOperandStack()
    operator = '='
    #check type
    varType = getResultingType(var.Type, op1.Type, operator)
    if varType == None:
        print "ERROR: wrong type"
        sys.exit()
    else:
        q.generateQuad(operator, op1, None, var)
示例#2
0
文件: parser.py 项目: EnriqueB/GProg
def p_term_q(p):
    '''term_q :'''
    global q
    if (q.topOperatorEquals('*') or q.topOperatorEquals('/')):
        op2 = q.popOperandStack()
        op1 = q.popOperandStack()
        operator = q.popOperatorStack()
        varType = getResultingType(op1.Type, op2.Type, operator)
        if varType == None:
            print "ERROR: invalid type"
            sys.exit()
        else:
            res = directoryTable[functionList[-1]].add_temp(varType)
            q.generateQuad(operator, op1, op2, res)
            q.pushOperandStack(res)
示例#3
0
文件: parser.py 项目: EnriqueB/GProg
def p_seen_comp(p):
    '''seen_comp : '''
    global q, directoryTable, functionList
    op2 = q.popOperandStack()
    op1 = q.popOperandStack()
    operator = q.popOperatorStack()
    #check type
    varType = getResultingType(op1.Type, op2.Type, operator)
    if varType == None:
        print "ERROR: invalid type in comparison"
        sys.exit()
    else:
        res = directoryTable[functionList[-1]].add_temp(varType)
        q.generateQuad(operator, op1, op2, res)
        q.pushOperandStack(res)
示例#4
0
文件: parser.py 项目: EnriqueB/GProg
def p_var_declaration2(p):
    '''var_declaration2 : EQUALS expression
                        | empty'''
    global q, directoryTable
    if p[1]:
        #get var
        var = p[-2]
        var = directoryTable[functionList[-1]].get_var(var)
        op1 = q.popOperandStack()
        operator = p[1]
        #check type
        varType = getResultingType(var.Type, op1.Type, operator)
        if varType == None:
            print "ERROR: wrong type"
            sys.exit()
        else:
            q.generateQuad(operator, op1, None, var)
示例#5
0
文件: parser.py 项目: EnriqueB/GProg
def p_factor(p):
    '''factor : LPAREN found_paren expression RPAREN
                | cst_expression'''
    global q
    if p[1] == "(":
        while not q.topOperatorEquals("("):
            op2 = q.popOperandStack()
            op1 = q.popOperandStack()
            operator = q.popOperatorStack()
            varType = getResultingType(op1.Type, op2.Type, operator)
            if varType == None:
                print "ERROR: invalid type"
                sys.exit()
            else:
                res = directoryTable[functionList[-1]].add_temp(varType)
                q.generateQuad(operator, op1, op2, res)
                q.pushOperandStack(res)
        q.popOperatorStack()