Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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())
Ejemplo n.º 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())
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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"
Ejemplo n.º 14
0
def p_statement_desvio(t):
    ' desvio : GOTO NUMBER'
    label = tabela.getVar(t[2])
    print "\tDSVR " + label.getEndGo(tabela.getNivel())
Ejemplo n.º 15
0
def p_statement_desvio(t):
    ' desvio : GOTO NUMBER'
    label = tabela.getVar(t[2])
    print "\tDSVR " + label.getEndGo(tabela.getNivel())
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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"