示例#1
0
def p_statement_chamada_procedimento(t):
    '''chamada_subprograma  : id_sub
                            | WRITE LPAREN lista_identificadores_write RPAREN
                            | READ LPAREN lista_identificadores_read RPAREN
                            | id_sub LPAREN lista_expressoes_subprograma RPAREN '''
    if t[1] != "write" and t[1] != "read":
        print "\tCHPR " + tabela.getVar(t[1]).getRotulo()
示例#2
0
def p_statement_chamada_procedimento(t):
    '''chamada_subprograma  : id_sub
                            | WRITE LPAREN lista_identificadores_write RPAREN
                            | READ LPAREN lista_identificadores_read RPAREN
                            | id_sub LPAREN lista_expressoes_subprograma RPAREN '''
    if t[1] != "write" and t[1] != "read":
        print "\tCHPR " + tabela.getVar(t[1]).getRotulo()
示例#3
0
def p_statement_comando(t):
    '''comando : NUMBER DPONTOS comando_sem_rotulo
               | comando_sem_rotulo'''
    if len(t) > 2:
        label = tabela.getVar(t[1])
        print label.getEnd() + "\tNADA"
        print "\tENRT "+str(tabela.getNivel())+","+str(tabela.getLenTab())
示例#4
0
def p_statement_comando(t):
    '''comando : NUMBER DPONTOS comando_sem_rotulo
               | comando_sem_rotulo'''
    if len(t) > 2:
        label = tabela.getVar(t[1])
        print label.getEnd() + "\tNADA"
        print "\tENRT " + str(tabela.getNivel()) + "," + str(
            tabela.getLenTab())
示例#5
0
def p_expression_id(t):
    'expression : ID'
    if tabela.exists(t[1]) :
        ident = tabela.getVar(t[1])
        if ident.referencia:
            print "\tCRVI " + ident.getEnd()
        else:
            print "\tCRVL " + ident.getEnd()
        tipo.add(ident.getTipo())
    else:
        sys.stderr.write("ERRO: variavel nao definida:"+t[1]+"\n")
        raise SyntaxError
示例#6
0
def p_expression_id(t):
    'expression : ID'
    if tabela.exists(t[1]):
        ident = tabela.getVar(t[1])
        if ident.referencia:
            print "\tCRVI " + ident.getEnd()
        else:
            print "\tCRVL " + ident.getEnd()
        tipo.add(ident.getTipo())
    else:
        sys.stderr.write("ERRO: variavel nao definida:" + t[1] + "\n")
        raise SyntaxError
示例#7
0
def p_statement_lista_expressoes_subprograma(t):
    '''lista_expressoes_subprograma : ID
                                    | expression
                                    | ID VIRG lista_expressoes_subprograma
                                    | expression VIRG lista_expressoes_subprograma '''
    elem = tabela.useParam()
    if tabela.exists(t[1]):
        ident = tabela.getVar(t[1])
        if elem.referencia and not ident.referencia:
            print "\tCREN "+ident.getEnd()
        else:
            print "\tCRVL "+ident.getEnd()
    elif elem.referencia:
        print "ERRO: expressao encontrada na passagem por referencia ",elem
        raise SyntaxError
示例#8
0
def p_statement_lista_expressoes_subprograma(t):
    '''lista_expressoes_subprograma : ID
                                    | expression
                                    | ID VIRG lista_expressoes_subprograma
                                    | expression VIRG lista_expressoes_subprograma '''
    elem = tabela.useParam()
    if tabela.exists(t[1]):
        ident = tabela.getVar(t[1])
        if elem.referencia and not ident.referencia:
            print "\tCREN " + ident.getEnd()
        else:
            print "\tCRVL " + ident.getEnd()
    elif elem.referencia:
        print "ERRO: expressao encontrada na passagem por referencia ", elem
        raise SyntaxError
示例#9
0
def p_statement_atribuicao(t):
    'atribuicao : ID ATTRIB expression'
    if tabela.exists(t[1]):
        ident = tabela.getVar(t[1])
        if ident.eFuncao():
            ident = ident.retorno
            tabela.resetParam()
        if ident.referencia:
            print "\tARMI "+ident.getEnd()
        else:
            print "\tARMZ "+ident.getEnd()
        tipo.add(ident.getTipo())
        tipo.compara()
        tipo.reset()
    else:
        sys.stderr.write("ERRO: variavel nao definida: "+t[1]+"\n")
        raise SyntaxError
示例#10
0
def p_statement_atribuicao(t):
    'atribuicao : ID ATTRIB expression'
    if tabela.exists(t[1]):
        ident = tabela.getVar(t[1])
        if ident.eFuncao():
            ident = ident.retorno
            tabela.resetParam()
        if ident.referencia:
            print "\tARMI " + ident.getEnd()
        else:
            print "\tARMZ " + ident.getEnd()
        tipo.add(ident.getTipo())
        tipo.compara()
        tipo.reset()
    else:
        sys.stderr.write("ERRO: variavel nao definida: " + t[1] + "\n")
        raise SyntaxError
示例#11
0
def p_expression_function_exp(t):
    'expression : id_sub LPAREN lista_expressoes_subprograma RPAREN'
    if tabela.exists(t[1]):
        ident = tabela.getVar(t[1])
        print "\tCHPR " + ident.getRotulo()
示例#12
0
def p_statement_lista_identificadores_read(t):
    '''lista_identificadores_read : ID
                                  | ID VIRG lista_identificadores_read'''
    print "\tLEIT"
    ident = tabela.getVar(t[1])
    print "\tARMZ " + ident.getEnd()
示例#13
0
def p_statement_lista_identificadores_write(t):
    '''lista_identificadores_write : ID
                                   | ID VIRG lista_identificadores_write '''
    ident = tabela.getVar(t[1])
    print "\tCRVL " + ident.getEnd()
    print "\tIMPR"
示例#14
0
def p_statement_desvio(t):
    ' desvio : GOTO NUMBER'
    label = tabela.getVar(t[2])
    print "\tDSVR " + label.getEndGo(tabela.getNivel())
示例#15
0
def p_statement_desvio(t):
    ' desvio : GOTO NUMBER'
    label = tabela.getVar(t[2])
    print "\tDSVR " + label.getEndGo(tabela.getNivel())
示例#16
0
def p_expression_function_exp(t):
    'expression : id_sub LPAREN lista_expressoes_subprograma RPAREN'
    if tabela.exists(t[1]):
        ident = tabela.getVar(t[1])
        print "\tCHPR " + ident.getRotulo()
示例#17
0
def p_statement_lista_identificadores_read(t):
    '''lista_identificadores_read : ID
                                  | ID VIRG lista_identificadores_read'''
    print "\tLEIT"
    ident = tabela.getVar(t[1])
    print "\tARMZ " + ident.getEnd()
示例#18
0
def p_statement_lista_identificadores_write(t):
    '''lista_identificadores_write : ID
                                   | ID VIRG lista_identificadores_write '''
    ident = tabela.getVar(t[1])
    print "\tCRVL " + ident.getEnd()
    print "\tIMPR"