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

declaracao de funcao (inicio)

parent f6c59499
Branches
No related tags found
No related merge requests found
...@@ -2,22 +2,3 @@ ...@@ -2,22 +2,3 @@
AMEM 1 AMEM 1
DSVS R00 DSVS R00
R01: ENPR 1 R01: ENPR 1
AMEM 1
DSVS R02
R02: NADA
CRVI 1,-5
ARMZ 1,0
CRCT 1
ARMI 1,-5
DMEM 1
R00: NADA
CRCT 8
ARMZ 0,0
CREN 0,0
CRCT 8
CRCT 2
CRCT 3
SOMA
CHPR R01,0
DMEM 0
PARA
This diff is collapsed.
...@@ -155,6 +155,7 @@ lista_idents: lista_idents VIRGULA IDENT ...@@ -155,6 +155,7 @@ lista_idents: lista_idents VIRGULA IDENT
// REGRA 11 // REGRA 11
parte_declara_subrotinas: parte_declara_subrotinas parte_declara_subrotinas: parte_declara_subrotinas
declaracao_procedimento declaracao_procedimento
| declaracao_funcao
| |
; ;
...@@ -191,12 +192,47 @@ declaracao_procedimento: PROCEDURE IDENT { ...@@ -191,12 +192,47 @@ declaracao_procedimento: PROCEDURE IDENT {
PONTO_E_VIRGULA PONTO_E_VIRGULA
; ;
// REGRA 13
// Regra ajustada para declaração de procedimento
declaracao_funcao: FUNCTION IDENT {
// Insere o funcao na tabela de símbolos
info_t info;
char r_func[4];
sprintf(r_func, "R%02d", rot_id);
rot_id += 1;
strcpy(info.fun.rot,r_func);
info.fun.quant = 0;
info.fun.param = NULL;
info.fun.tipo = NSEI;
// Incrementa o nível léxico
nivel_lexico += 1;
desloc = 0; // Reinicia deslocamento para variáveis locais do novo nível
insere_ts(token, FUN, nivel_lexico, info, ts);
empilha(token,proc);
char buffer[50];
sprintf(buffer,"ENPR %d",nivel_lexico);
geraCodigo(r_func,buffer);
mostra_ts(ts);
}
parametros_ou_nada
PONTO_E_VIRGULA bloco
{
// Retorna ao nível léxico anterior e mantém o deslocamento atualizado
nivel_lexico -= 1;
}
PONTO_E_VIRGULA
;
parametros_ou_nada: ABRE_PARENTESES parametros_ou_nada: ABRE_PARENTESES
{num_param = 0;} {num_param = 0;}
paramentros_formais { paramentros_formais {
char proc_ident[50]; char proc_ident[50];
desempilha(proc_ident,proc); desempilha(proc_ident,proc);
adiciona_param(proc_ident,num_param,ts); adiciona_param(proc_ident,num_param,ts);
mostra_ts(ts);
} }
FECHA_PARENTESES FECHA_PARENTESES
| |
......
program proc1 (input, output);
var x: integer;
function f(var a: integer; b: integer): integer;
var z: integer;
begin
z := a;
a := 1;
end;
begin
x := f(x, 2+3);
end.
\ No newline at end of file
...@@ -8,5 +8,5 @@ program proc1 (input, output); ...@@ -8,5 +8,5 @@ program proc1 (input, output);
end; end;
begin begin
x := 8; x := 8;
p(x+9, 2+3); p(x, 2+3);
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