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
a75825f5
Commit
a75825f5
authored
6 months ago
by
viniciusmioto
Browse files
Options
Downloads
Patches
Plain Diff
chamada de procedimento por valor + atribuicao indirate (ARMI)
parent
81b8ced9
No related branches found
No related tags found
No related merge requests found
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
MEPA
+4
-2
4 additions, 2 deletions
MEPA
compilador.output
+292
-265
292 additions, 265 deletions
compilador.output
compilador.y
+41
-7
41 additions, 7 deletions
compilador.y
teste9.pas
+1
-0
1 addition, 0 deletions
teste9.pas
with
338 additions
and
274 deletions
MEPA
+
4
−
2
View file @
a75825f5
...
@@ -5,13 +5,15 @@ R01: ENPR 1
...
@@ -5,13 +5,15 @@ R01: ENPR 1
AMEM 1
AMEM 1
DSVS R02
DSVS R02
R02: NADA
R02: NADA
CRV
L
1,-
4
CRV
I
1,-
5
ARMZ 1,0
ARMZ 1,0
CRCT 1
ARMI 1,-5
DMEM 1
DMEM 1
R00: NADA
R00: NADA
CRCT 8
CRCT 8
ARMZ 0,0
ARMZ 0,0
CR
VL
0,0
CR
EN
0,0
CRCT 2
CRCT 2
CHPR R01,0
CHPR R01,0
DMEM 0
DMEM 0
...
...
This diff is collapsed.
Click to expand it.
compilador.output
+
292
−
265
View file @
a75825f5
This diff is collapsed.
Click to expand it.
compilador.y
+
41
−
7
View file @
a75825f5
...
@@ -25,6 +25,7 @@ custom_stack_t *rot;
...
@@ -25,6 +25,7 @@ custom_stack_t *rot;
custom_stack_t *proc;
custom_stack_t *proc;
int val_ou_ref;
int val_ou_ref;
int atr_indireto;
%}
%}
...
@@ -211,7 +212,10 @@ secao_pfs: VAR
...
@@ -211,7 +212,10 @@ secao_pfs: VAR
val_ou_ref = REF;
val_ou_ref = REF;
}
}
lista_id_pf DOIS_PONTOS tipo
lista_id_pf DOIS_PONTOS tipo
{ num_param += num_vars;}
{
num_param += num_vars;
val_ou_ref = VLR;
}
| {
| {
num_vars = 0;
num_vars = 0;
val_ou_ref = VLR;
val_ou_ref = VLR;
...
@@ -266,13 +270,20 @@ atribuicao: {
...
@@ -266,13 +270,20 @@ atribuicao: {
if (l_elem == NULL) {
if (l_elem == NULL) {
yyerror("Variável de destino não declarada");
yyerror("Variável de destino não declarada");
} else {
} else {
if (l_elem->categ == PF && l_elem->info.pf.passagem == REF)
atr_indireto = REF;
else atr_indireto = VLR;
destino_nivel = l_elem->nivel;
destino_nivel = l_elem->nivel;
destino_desloc = l_elem->info.vs.desloc;
destino_desloc = l_elem->info.vs.desloc;
}
}
} ATRIBUICAO expressao_simples {
} ATRIBUICAO expressao_simples {
// Gera código ARMZ para armazenar valor
// Gera código ARMZ para armazenar valor
char buffer[50];
char buffer[50];
if (atr_indireto == REF) {
sprintf(buffer, "ARMI %d,%d", destino_nivel, destino_desloc);
} else {
sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc);
sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc);
}
geraCodigo(NULL, buffer);
geraCodigo(NULL, buffer);
};
};
...
@@ -291,7 +302,6 @@ chamada_procedimento:
...
@@ -291,7 +302,6 @@ chamada_procedimento:
lista_parametros
lista_parametros
{
{
char buffer[50];
char buffer[50];
mostra_ts(ts);
mostra_ts(ts);
desempilha(buffer, proc);
desempilha(buffer, proc);
...
@@ -317,11 +327,26 @@ lista_parametros: ABRE_PARENTESES
...
@@ -317,11 +327,26 @@ lista_parametros: ABRE_PARENTESES
|
|
;
;
lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples
lista_parametros_parenteses: lista_parametros_parenteses VIRGULA
{
char buffer[50];
desempilha(buffer,proc);
l_elem = busca(buffer,ts);
val_ou_ref = l_elem->info.pr.param[num_param][1];
empilha(buffer,proc);
}
expressao_simples
{
{
num_param++; // Incrementa para cada parâmetro real
num_param++; // Incrementa para cada parâmetro real
}
}
| expressao_simples
| {
char buffer[50];
desempilha(buffer,proc);
l_elem = busca(buffer,ts);
val_ou_ref = l_elem->info.pr.param[num_param][1];
empilha(buffer,proc);
}
expressao_simples
{
{
num_param++; // Conta o primeiro parâmetro real
num_param++; // Conta o primeiro parâmetro real
}
}
...
@@ -400,8 +425,17 @@ fator: IDENT {
...
@@ -400,8 +425,17 @@ fator: IDENT {
yyerror("Variável não declarada");
yyerror("Variável não declarada");
} else {
} else {
char buffer[50];
char buffer[50];
if (val_ou_ref == REF) {
sprintf(buffer, "CREN %d,%d", l_elem->nivel, l_elem->info.vs.desloc);
}
else if (l_elem->categ == PF && l_elem->info.pf.passagem == REF) {
sprintf(buffer, "CRVI %d,%d", l_elem->nivel, l_elem->info.vs.desloc);
}
else {
sprintf(buffer, "CRVL %d,%d", l_elem->nivel, l_elem->info.vs.desloc);
sprintf(buffer, "CRVL %d,%d", l_elem->nivel, l_elem->info.vs.desloc);
}
geraCodigo(NULL, buffer);
geraCodigo(NULL, buffer);
val_ou_ref = VLR;
}
}
}
}
| NUMERO {
| NUMERO {
...
...
This diff is collapsed.
Click to expand it.
teste9.pas
+
1
−
0
View file @
a75825f5
...
@@ -4,6 +4,7 @@ program proc1 (input, output);
...
@@ -4,6 +4,7 @@ program proc1 (input, output);
var
z
:
integer
;
var
z
:
integer
;
begin
begin
z
:=
a
;
z
:=
a
;
a
:=
1
;
end
;
end
;
begin
begin
x
:=
8
;
x
:=
8
;
...
...
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