Skip to content
Snippets Groups Projects
Commit 3af03988 authored by hm19's avatar hm19
Browse files

funcao espera parametros certos

parent 7f8dde59
No related branches found
No related tags found
No related merge requests found
...@@ -2,22 +2,52 @@ ...@@ -2,22 +2,52 @@
AMEM 1 AMEM 1
DSVS R00 DSVS R00
R01: ENPR 1 R01: ENPR 1
AMEM 1 AMEM 2
DSVS R02 DSVS R02
R02: NADA R02: NADA
CRVI 1,-5 CRVL 1,-5
ARMZ 1,0 CRCT 2
CMME
DSVF R03
CRVL 1,-5
ARMZ 1,-6
CRCT 0
ARMI 1,-4
DSVS R04
R03: NADA
AMEM 1
CRVL 1,-5
CRCT 1 CRCT 1
ARMI 1,-5 SUBT
DMEM 1 CREN 1,0
RTPR 1,2 CHPR R01,1
R00: NADA AMEM 1
CRCT 8 CRVL 1,-5
ARMZ 0,0
CREN 0,0
CRCT 2 CRCT 2
CRCT 3 SUBT
CREN 1,1
CHPR R01,1
SOMA SOMA
CHPR R01,0 ARMZ 1,-6
CRVL 1,0
CRVL 1,1
SOMA
CRCT 1
SOMA
ARMI 1,-4
R04: NADA
CRVL 1,-5
IMPR
CRVI 1,-4
IMPR
DMEM 2
R00: NADA
AMEM 1
CRCT 3
CREN 0,0
CHPR R01,-1
IMPR
CRVL 0,0
IMPR
DMEM 1 DMEM 1
PARA PARA
No preview for this file type
...@@ -567,11 +567,11 @@ static const yytype_int16 yyrline[] = ...@@ -567,11 +567,11 @@ static const yytype_int16 yyrline[] =
234, 238, 210, 246, 247, 245, 255, 258, 259, 263, 234, 238, 210, 246, 247, 245, 255, 258, 259, 263,
262, 272, 272, 280, 281, 284, 294, 297, 298, 299, 262, 272, 272, 280, 281, 284, 294, 297, 298, 299,
302, 303, 306, 307, 308, 309, 310, 311, 314, 314, 302, 303, 306, 307, 308, 309, 310, 311, 314, 314,
318, 319, 322, 322, 353, 353, 396, 399, 403, 402, 318, 319, 322, 322, 353, 353, 395, 398, 402, 401,
415, 415, 429, 432, 433, 436, 445, 448, 451, 456, 414, 414, 428, 431, 432, 435, 444, 447, 450, 455,
459, 462, 465, 468, 471, 474, 477, 483, 489, 492, 458, 461, 464, 467, 470, 473, 476, 482, 488, 491,
495, 498, 501, 501, 543, 554, 556, 563, 556, 589, 494, 497, 500, 500, 542, 553, 555, 562, 555, 588,
596, 598, 601, 601 595, 597, 600, 600
}; };
#endif #endif
...@@ -1811,39 +1811,38 @@ yyreduce: ...@@ -1811,39 +1811,38 @@ yyreduce:
{ {
if (l_elem == NULL){ if (l_elem == NULL){
yyerror("Procedimento não declarado"); yyerror("Procedimento não declarado");
} else if (l_elem->categ == PR || l_elem->categ == FUN) { } else{
// Gera código para chamar o procedimento // Gera código para chamar o procedimento
empilha(l_elem->ident, proc); empilha(l_elem->ident, proc);
} }
if (l_elem->categ == FUN) if (l_elem->categ == FUN)
geraCodigo(NULL, "AMEM 1"); geraCodigo(NULL, "AMEM 1");
if (l_elem->categ == PR || l_elem->categ == FUN)
num_param = 0; // Reinicia a contagem de parâmetros reais num_param = 0; // Reinicia a contagem de parâmetros reais
} }
#line 1823 "compilador.tab.c" #line 1824 "compilador.tab.c"
break; break;
case 65: case 65:
#line 367 "compilador.y" #line 368 "compilador.y"
{ {
if (l_elem->categ == PR || l_elem->categ ==FUN) {
char buffer[50]; char buffer[50];
mostra_ts(ts); mostra_ts(ts);
desempilha(buffer, proc); desempilha(buffer, proc);
l_elem = busca(buffer, ts); l_elem = busca(buffer, ts);
if (l_elem->categ == PR || l_elem->categ ==FUN) {
// Verifica se o número de parâmetros reais bate com os formais // Verifica se o número de parâmetros reais bate com os formais
if (num_param != l_elem->info.pr.quant) {
char error_msg[100]; char error_msg[100];
if(l_elem->categ == PR){ if (l_elem->categ == PR && num_param != l_elem->info.pr.quant) {
sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.", sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.",
l_elem->info.pr.quant, num_param); l_elem->info.pr.quant, num_param);
yyerror(error_msg); yyerror(error_msg);
} else if(l_elem->categ == FUN){ } else if(l_elem->categ == FUN && num_param != l_elem->info.fun.quant){
sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.", sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.",
l_elem->info.fun.quant, num_param); l_elem->info.fun.quant, num_param);
yyerror(error_msg); yyerror(error_msg);
} }
}
// Gera o código de chamada do procedimento // Gera o código de chamada do procedimento
...@@ -1851,11 +1850,11 @@ yyreduce: ...@@ -1851,11 +1850,11 @@ yyreduce:
geraCodigo(NULL, buffer); geraCodigo(NULL, buffer);
} }
} }
#line 1855 "compilador.tab.c" #line 1854 "compilador.tab.c"
break; break;
case 68: case 68:
#line 403 "compilador.y" #line 402 "compilador.y"
{ {
char buffer[50]; char buffer[50];
desempilha(buffer,proc); desempilha(buffer,proc);
...@@ -1863,20 +1862,20 @@ yyreduce: ...@@ -1863,20 +1862,20 @@ yyreduce:
val_ou_ref = l_elem->info.pr.param[num_param][1]; val_ou_ref = l_elem->info.pr.param[num_param][1];
empilha(buffer,proc); empilha(buffer,proc);
} }
#line 1867 "compilador.tab.c" #line 1866 "compilador.tab.c"
break; break;
case 69: case 69:
#line 411 "compilador.y" #line 410 "compilador.y"
{ {
num_param++; // Incrementa para cada parâmetro real num_param++; // Incrementa para cada parâmetro real
val_ou_ref = VLR; val_ou_ref = VLR;
} }
#line 1876 "compilador.tab.c" #line 1875 "compilador.tab.c"
break; break;
case 70: case 70:
#line 415 "compilador.y" #line 414 "compilador.y"
{ {
char buffer[50]; char buffer[50];
desempilha(buffer,proc); desempilha(buffer,proc);
...@@ -1884,20 +1883,20 @@ yyreduce: ...@@ -1884,20 +1883,20 @@ yyreduce:
val_ou_ref = l_elem->info.pr.param[num_param][1]; val_ou_ref = l_elem->info.pr.param[num_param][1];
empilha(buffer,proc); empilha(buffer,proc);
} }
#line 1888 "compilador.tab.c" #line 1887 "compilador.tab.c"
break; break;
case 71: case 71:
#line 423 "compilador.y" #line 422 "compilador.y"
{ {
num_param++; // Conta o primeiro parâmetro real num_param++; // Conta o primeiro parâmetro real
val_ou_ref = VLR; val_ou_ref = VLR;
} }
#line 1897 "compilador.tab.c" #line 1896 "compilador.tab.c"
break; break;
case 75: case 75:
#line 436 "compilador.y" #line 435 "compilador.y"
{ {
geraCodigo(NULL, "LEIT"); geraCodigo(NULL, "LEIT");
l_elem = busca(token,ts); l_elem = busca(token,ts);
...@@ -1905,123 +1904,123 @@ yyreduce: ...@@ -1905,123 +1904,123 @@ yyreduce:
sprintf(buffer,"ARMZ %d,%d",l_elem->nivel,l_elem->info.vs.desloc); sprintf(buffer,"ARMZ %d,%d",l_elem->nivel,l_elem->info.vs.desloc);
geraCodigo(NULL,buffer); geraCodigo(NULL,buffer);
} }
#line 1909 "compilador.tab.c" #line 1908 "compilador.tab.c"
break; break;
case 77: case 77:
#line 448 "compilador.y" #line 447 "compilador.y"
{ {
geraCodigo(NULL,"IMPR"); geraCodigo(NULL,"IMPR");
} }
#line 1917 "compilador.tab.c" #line 1916 "compilador.tab.c"
break; break;
case 78: case 78:
#line 451 "compilador.y" #line 450 "compilador.y"
{ {
geraCodigo(NULL,"IMPR"); geraCodigo(NULL,"IMPR");
} }
#line 1925 "compilador.tab.c" #line 1924 "compilador.tab.c"
break; break;
case 79: case 79:
#line 456 "compilador.y" #line 455 "compilador.y"
{ {
geraCodigo(NULL, "CMIG"); // Adiciona operação de cmig geraCodigo(NULL, "CMIG"); // Adiciona operação de cmig
} }
#line 1933 "compilador.tab.c" #line 1932 "compilador.tab.c"
break; break;
case 80: case 80:
#line 459 "compilador.y" #line 458 "compilador.y"
{ {
geraCodigo(NULL, "CMDG"); // Adiciona operação de cmdg geraCodigo(NULL, "CMDG"); // Adiciona operação de cmdg
} }
#line 1941 "compilador.tab.c" #line 1940 "compilador.tab.c"
break; break;
case 81: case 81:
#line 462 "compilador.y" #line 461 "compilador.y"
{ {
geraCodigo(NULL, "CMME"); // Adiciona operação de cmme geraCodigo(NULL, "CMME"); // Adiciona operação de cmme
} }
#line 1949 "compilador.tab.c" #line 1948 "compilador.tab.c"
break; break;
case 82: case 82:
#line 465 "compilador.y" #line 464 "compilador.y"
{ {
geraCodigo(NULL, "CMEG"); // Adiciona operação de cmeg geraCodigo(NULL, "CMEG"); // Adiciona operação de cmeg
} }
#line 1957 "compilador.tab.c" #line 1956 "compilador.tab.c"
break; break;
case 83: case 83:
#line 468 "compilador.y" #line 467 "compilador.y"
{ {
geraCodigo(NULL, "CMMA"); // Adiciona operação de cmma geraCodigo(NULL, "CMMA"); // Adiciona operação de cmma
} }
#line 1965 "compilador.tab.c" #line 1964 "compilador.tab.c"
break; break;
case 84: case 84:
#line 471 "compilador.y" #line 470 "compilador.y"
{ {
geraCodigo(NULL, "CMAG"); // Adiciona operação de cmag geraCodigo(NULL, "CMAG"); // Adiciona operação de cmag
} }
#line 1973 "compilador.tab.c" #line 1972 "compilador.tab.c"
break; break;
case 86: case 86:
#line 477 "compilador.y" #line 476 "compilador.y"
{ {
if (val_ou_ref == REF) if (val_ou_ref == REF)
yyerror("Erro: tentativa de EXPRESSAO em passagem por REFERENCIA\n"); yyerror("Erro: tentativa de EXPRESSAO em passagem por REFERENCIA\n");
else else
geraCodigo(NULL, "SOMA"); // Adiciona operação de soma geraCodigo(NULL, "SOMA"); // Adiciona operação de soma
} }
#line 1984 "compilador.tab.c" #line 1983 "compilador.tab.c"
break; break;
case 87: case 87:
#line 483 "compilador.y" #line 482 "compilador.y"
{ {
if (val_ou_ref == REF) if (val_ou_ref == REF)
yyerror("Erro: tentativa de EXPRESSAO em passagem por REFERENCIA\n"); yyerror("Erro: tentativa de EXPRESSAO em passagem por REFERENCIA\n");
else else
geraCodigo(NULL, "SUBT"); // Adiciona operação de subt geraCodigo(NULL, "SUBT"); // Adiciona operação de subt
} }
#line 1995 "compilador.tab.c" #line 1994 "compilador.tab.c"
break; break;
case 89: case 89:
#line 492 "compilador.y" #line 491 "compilador.y"
{ {
geraCodigo(NULL, "MULT"); // Adiciona operação de mult geraCodigo(NULL, "MULT"); // Adiciona operação de mult
} }
#line 2003 "compilador.tab.c" #line 2002 "compilador.tab.c"
break; break;
case 90: case 90:
#line 495 "compilador.y" #line 494 "compilador.y"
{ {
geraCodigo(NULL, "DIVI"); // Adiciona operação de divi geraCodigo(NULL, "DIVI"); // Adiciona operação de divi
} }
#line 2011 "compilador.tab.c" #line 2010 "compilador.tab.c"
break; break;
case 92: case 92:
#line 501 "compilador.y" #line 500 "compilador.y"
{ {
// Carrega variável // Carrega variável
l_elem = busca(token, ts); l_elem = busca(token, ts);
empilha(token, proc); empilha(token, proc);
} }
#line 2021 "compilador.tab.c" #line 2020 "compilador.tab.c"
break; break;
case 93: case 93:
#line 507 "compilador.y" #line 506 "compilador.y"
{ {
char buffer[50]; char buffer[50];
desempilha(buffer, proc); desempilha(buffer, proc);
...@@ -2058,11 +2057,11 @@ yyreduce: ...@@ -2058,11 +2057,11 @@ yyreduce:
} }
} }
} }
#line 2062 "compilador.tab.c" #line 2061 "compilador.tab.c"
break; break;
case 94: case 94:
#line 543 "compilador.y" #line 542 "compilador.y"
{ {
// Empilha constante // Empilha constante
char buffer[50]; char buffer[50];
...@@ -2073,11 +2072,11 @@ yyreduce: ...@@ -2073,11 +2072,11 @@ yyreduce:
} }
geraCodigo(NULL, buffer); geraCodigo(NULL, buffer);
} }
#line 2077 "compilador.tab.c" #line 2076 "compilador.tab.c"
break; break;
case 96: case 96:
#line 556 "compilador.y" #line 555 "compilador.y"
{ {
char r_ini[4]; char r_ini[4];
sprintf(r_ini, "R%02d", rot_id); sprintf(r_ini, "R%02d", rot_id);
...@@ -2085,11 +2084,11 @@ yyreduce: ...@@ -2085,11 +2084,11 @@ yyreduce:
rot_id += 1; rot_id += 1;
geraCodigo(r_ini,"NADA"); geraCodigo(r_ini,"NADA");
} }
#line 2089 "compilador.tab.c" #line 2088 "compilador.tab.c"
break; break;
case 97: case 97:
#line 563 "compilador.y" #line 562 "compilador.y"
{ {
char r_fim[4]; char r_fim[4];
sprintf(r_fim, "R%02d", rot_id); sprintf(r_fim, "R%02d", rot_id);
...@@ -2100,11 +2099,11 @@ yyreduce: ...@@ -2100,11 +2099,11 @@ yyreduce:
strcat(buffer,r_fim); strcat(buffer,r_fim);
geraCodigo(NULL,buffer); geraCodigo(NULL,buffer);
} }
#line 2104 "compilador.tab.c" #line 2103 "compilador.tab.c"
break; break;
case 98: case 98:
#line 573 "compilador.y" #line 572 "compilador.y"
{ {
char r_ini[4]; char r_ini[4];
char r_fim[4]; char r_fim[4];
...@@ -2119,21 +2118,21 @@ yyreduce: ...@@ -2119,21 +2118,21 @@ yyreduce:
geraCodigo(r_fim,"NADA"); geraCodigo(r_fim,"NADA");
} }
#line 2123 "compilador.tab.c" #line 2122 "compilador.tab.c"
break; break;
case 99: case 99:
#line 589 "compilador.y" #line 588 "compilador.y"
{ {
char r_fim[4]; char r_fim[4];
desempilha(r_fim,rot); desempilha(r_fim,rot);
geraCodigo(r_fim,"NADA"); geraCodigo(r_fim,"NADA");
} }
#line 2133 "compilador.tab.c" #line 2132 "compilador.tab.c"
break; break;
case 102: case 102:
#line 601 "compilador.y" #line 600 "compilador.y"
{ {
char r_else[4]; char r_else[4];
sprintf(r_else,"R%02d",rot_id); sprintf(r_else,"R%02d",rot_id);
...@@ -2149,11 +2148,11 @@ yyreduce: ...@@ -2149,11 +2148,11 @@ yyreduce:
empilha(r_fim, rot); empilha(r_fim, rot);
rot_id += 1; rot_id += 1;
} }
#line 2153 "compilador.tab.c" #line 2152 "compilador.tab.c"
break; break;
case 103: case 103:
#line 616 "compilador.y" #line 615 "compilador.y"
{ {
char r_fim[4]; char r_fim[4];
desempilha(r_fim,rot); desempilha(r_fim,rot);
...@@ -2168,11 +2167,11 @@ yyreduce: ...@@ -2168,11 +2167,11 @@ yyreduce:
geraCodigo(r_else,"NADA"); geraCodigo(r_else,"NADA");
} }
#line 2172 "compilador.tab.c" #line 2171 "compilador.tab.c"
break; break;
#line 2176 "compilador.tab.c" #line 2175 "compilador.tab.c"
default: break; default: break;
} }
...@@ -2404,7 +2403,7 @@ yyreturn: ...@@ -2404,7 +2403,7 @@ yyreturn:
#endif #endif
return yyresult; return yyresult;
} }
#line 633 "compilador.y" #line 632 "compilador.y"
int main (int argc, char** argv) { int main (int argc, char** argv) {
......
...@@ -353,37 +353,36 @@ chamada_procedimento: ...@@ -353,37 +353,36 @@ chamada_procedimento:
{ {
if (l_elem == NULL){ if (l_elem == NULL){
yyerror("Procedimento não declarado"); yyerror("Procedimento não declarado");
} else if (l_elem->categ == PR || l_elem->categ == FUN) { } else{
// Gera código para chamar o procedimento // Gera código para chamar o procedimento
empilha(l_elem->ident, proc); empilha(l_elem->ident, proc);
} }
if (l_elem->categ == FUN) if (l_elem->categ == FUN)
geraCodigo(NULL, "AMEM 1"); geraCodigo(NULL, "AMEM 1");
if (l_elem->categ == PR || l_elem->categ == FUN)
num_param = 0; // Reinicia a contagem de parâmetros reais num_param = 0; // Reinicia a contagem de parâmetros reais
} }
lista_parametros lista_parametros
{ {
if (l_elem->categ == PR || l_elem->categ ==FUN) {
char buffer[50]; char buffer[50];
mostra_ts(ts); mostra_ts(ts);
desempilha(buffer, proc); desempilha(buffer, proc);
l_elem = busca(buffer, ts); l_elem = busca(buffer, ts);
if (l_elem->categ == PR || l_elem->categ ==FUN) {
// Verifica se o número de parâmetros reais bate com os formais // Verifica se o número de parâmetros reais bate com os formais
if (num_param != l_elem->info.pr.quant) {
char error_msg[100]; char error_msg[100];
if(l_elem->categ == PR){ if (l_elem->categ == PR && num_param != l_elem->info.pr.quant) {
sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.", sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.",
l_elem->info.pr.quant, num_param); l_elem->info.pr.quant, num_param);
yyerror(error_msg); yyerror(error_msg);
} else if(l_elem->categ == FUN){ } else if(l_elem->categ == FUN && num_param != l_elem->info.fun.quant){
sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.", sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.",
l_elem->info.fun.quant, num_param); l_elem->info.fun.quant, num_param);
yyerror(error_msg); yyerror(error_msg);
} }
}
// Gera o código de chamada do procedimento // Gera o código de chamada do procedimento
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment