Skip to content
Snippets Groups Projects
Commit b8977ae0 authored by viniciusmioto's avatar viniciusmioto
Browse files

chamada de procedimentos com parametros e verificacao

parent aebda399
Branches
No related tags found
No related merge requests found
...@@ -5,14 +5,11 @@ R01: ENPR 1 ...@@ -5,14 +5,11 @@ R01: ENPR 1
AMEM 1 AMEM 1
DSVS R02 DSVS R02
R02: NADA R02: NADA
CRVL 1,-5
ARMZ 1,0 ARMZ 1,0
DMEM 1 DMEM 1
R00: NADA R00: NADA
CRCT 8 CRCT 8
ARMZ 0,0 ARMZ 0,0
CRVL 0,0
CRCT 2
CHPR R01,0 CHPR R01,0
DMEM 0 DMEM 0
PARA PARA
...@@ -273,6 +273,7 @@ chamada_procedimento: ...@@ -273,6 +273,7 @@ chamada_procedimento:
// Gera código para chamar o procedimento // Gera código para chamar o procedimento
empilha(l_elem->ident, proc); empilha(l_elem->ident, proc);
} }
num_param = 0; // Reinicia a contagem de parâmetros reais
} }
lista_parametros lista_parametros
...@@ -283,6 +284,16 @@ chamada_procedimento: ...@@ -283,6 +284,16 @@ chamada_procedimento:
mostra_ts(ts); mostra_ts(ts);
desempilha(buffer, proc); desempilha(buffer, proc);
l_elem = busca(buffer, ts); l_elem = busca(buffer, ts);
// 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];
sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.",
l_elem->info.pr.quant, num_param);
yyerror(error_msg);
}
// Gera o código de chamada do procedimento
sprintf(buffer, "CHPR %s,%d", l_elem->info.pr.rot, nivel_lexico); sprintf(buffer, "CHPR %s,%d", l_elem->info.pr.rot, nivel_lexico);
geraCodigo(NULL, buffer); geraCodigo(NULL, buffer);
} }
...@@ -295,7 +306,13 @@ lista_parametros: ABRE_PARENTESES ...@@ -295,7 +306,13 @@ lista_parametros: ABRE_PARENTESES
; ;
lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples
{
num_param++; // Incrementa para cada parâmetro real
}
| expressao_simples | expressao_simples
{
num_param++; // Conta o primeiro parâmetro real
}
; ;
leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES
......
program proc1 (input, output); program proc1 (input, output);
var x: integer; var x: integer;
procedure p(a,b: integer; c:boolean); procedure p;
var z: integer; var z: integer;
begin begin
z := a; z := a;
end; end;
begin begin
x := 8; x := 8;
p;
end. end.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment