Skip to content
Snippets Groups Projects
Commit 165feb6d authored by Henrique Margotte's avatar Henrique Margotte
Browse files

problemas chamada procedimento

parent dc1c13f6
Branches
No related tags found
No related merge requests found
INPP
AMEM 1
DSVS R00
R01: ENPR 1
AMEM 1
DSVS R02
R02: NADA
CRCT 3
ARMZ 1,1
DMEM 2
DSVS R00
R00: NADA
CRCT 8
CRCT 5
ARMZ 0,0
DMEM 0
CRVL 0,1
CRCT 5
CRCT 2
MULT
SOMA
ARMZ 0,1
DMEM 2
PARA
No preview for this file type
This diff is collapsed.
This diff is collapsed.
......@@ -118,7 +118,7 @@ tipo : IDENT
} else {
yyerror("Tipo não reconhecido. Somente 'integer' ou 'boolean' são permitidos.");
}
//mostra_ts(ts); // Mostra a tabela após a inserção
mostra_ts(ts); // Mostra a tabela após a inserção
}
;
......@@ -168,7 +168,7 @@ declaracao_procedimento: PROCEDURE IDENT {
char buffer[50];
sprintf(buffer,"ENPR %d",nivel_lexico);
geraCodigo(r_proc,buffer);
//mostra_ts(ts);
mostra_ts(ts);
}
PONTO_E_VIRGULA bloco
{ nivel_lexico -= 1; }
......@@ -193,10 +193,22 @@ comando_sem_rotulo: atribuicao
| comando_repetitivo
| leitura
| escrita
//| chamada_procedimento
| chamada_procedimento
;
//chamada_procedimento: ;
chamada_procedimento: /*IDENT {
l_elem = busca(token,ts);
if (l_elem == NULL || l_elem->categ != PR) {
yyerror("Procedimento não declarado");
} else {
// Gera código para chamar o procedimento
char buffer[50];
sprintf(buffer, "CHPR %s,%d", l_elem->info.pr.rot, nivel_lexico);
geraCodigo(NULL, buffer);
}
//ABRE_PARENTESES FECHA_PARENTESES
}*/
;
leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES
;
......@@ -265,6 +277,7 @@ termo: termo ASTERISCO fator {
;
atribuicao: IDENT {
mostra_ts(ts);
// Busca variável no lado esquerdo
l_elem = busca(token, ts);
if (l_elem == NULL) {
......
......@@ -3,5 +3,5 @@ var a: integer;
b: integer;
begin
a := 5;
b := a + 5 * 2;
b := b + 5 * 2;
end.
......@@ -7,4 +7,5 @@ program proc1 (input, output);
end
begin
x := 8;
p
end.
\ No newline at end of file
......@@ -75,7 +75,7 @@ void atualiza_tipo(int n, int tipo, ts_t *ts){
}
}
/*void mostra_ts(ts_t *ts) {
void mostra_ts(ts_t *ts) {
if (ts == NULL || ts->topo == NULL) {
printf("Tabela de Símbolos está vazia ou não inicializada.\n");
return;
......@@ -83,14 +83,21 @@ void atualiza_tipo(int n, int tipo, ts_t *ts){
printf("\nTabela de Símbolos:\n");
printf("----------------------------------------------------------------------------------\n");
printf("| %-10s | %-8s | %-8s | %-10s | %-10s |\n",
"Ident", "Categ", "Nivel", "Tipo", "Desloc");
printf("| %-10s | %-8s | %-8s | %-10s | %-10s | %-20s |\n",
"Ident", "Categ", "Nivel", "Tipo", "Desloc", "Detalhes");
printf("----------------------------------------------------------------------------------\n");
simb_t *p = ts->topo;
while (p != NULL) {
// Identificar o tipo como Inteiro, Boolean ou Indefinido
const char *tipoStr;
// Identificar a categoria
const char *categStr;
const char *tipoStr = "-";
char deslocStr[10] = "-";
char detalhes[50] = "-";
if (p->categ == VS) {
categStr = "VS";
// Determina o tipo como Inteiro, Boolean ou Indefinido
switch (p->info.vs.tipo) {
case INTEIRO:
tipoStr = "Inteiro";
......@@ -102,15 +109,20 @@ void atualiza_tipo(int n, int tipo, ts_t *ts){
tipoStr = "NSEI";
break;
}
sprintf(deslocStr, "%d", p->info.vs.desloc);
} else if (p->categ == PR) {
categStr = "PR";
tipoStr = "-";
sprintf(detalhes, "%s, Params: %d", p->info.pr.rot, p->info.pr.quant);
} else {
categStr = "Outro";
}
// Determinar a categoria
const char *categStr = (p->categ == VS) ? "VS" : "Outro";
// Imprimir a entrada
printf("| %-10s | %-8s | %-8d | %-10s | %-10d |\n",
p->ident, categStr, p->nivel, tipoStr, p->info.vs.desloc);
// Imprime a entrada
printf("| %-10s | %-8s | %-8d | %-10s | %-10s | %-20s |\n",
p->ident, categStr, p->nivel, tipoStr, deslocStr, detalhes);
p = p->prox;
}
printf("----------------------------------------------------------------------------------\n");
}*/
\ No newline at end of file
}
\ No newline at end of file
......@@ -49,6 +49,6 @@ void retira(int n, ts_t *ts);
void atualiza_tipo(int n, int tipo, ts_t *ts);
//void mostra_ts(ts_t *ts);
void mostra_ts(ts_t *ts);
#endif
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment