Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compilador
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hm19
compilador
Commits
b8977ae0
Commit
b8977ae0
authored
6 months ago
by
viniciusmioto
Browse files
Options
Downloads
Patches
Plain Diff
chamada de procedimentos com parametros e verificacao
parent
aebda399
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
MEPA
+0
-3
0 additions, 3 deletions
MEPA
compilador.y
+17
-0
17 additions, 0 deletions
compilador.y
teste7.pas
+2
-1
2 additions, 1 deletion
teste7.pas
with
19 additions
and
4 deletions
MEPA
+
0
−
3
View file @
b8977ae0
...
@@ -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
This diff is collapsed.
Click to expand it.
compilador.y
+
17
−
0
View file @
b8977ae0
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
teste7.pas
+
2
−
1
View file @
b8977ae0
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment