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
1a93ea1f
Commit
1a93ea1f
authored
6 months ago
by
Henrique Margotte
Browse files
Options
Downloads
Patches
Plain Diff
chama procedimento funcionando
parent
616ffbe1
No related branches found
No related tags found
No related merge requests found
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
MEPA
+3
-0
3 additions, 0 deletions
MEPA
compilador.output
+948
-875
948 additions, 875 deletions
compilador.output
compilador.y
+28
-24
28 additions, 24 deletions
compilador.y
teste6.pas
+1
-1
1 addition, 1 deletion
teste6.pas
ts/ts.c
+1
-1
1 addition, 1 deletion
ts/ts.c
ts/ts.h
+1
-1
1 addition, 1 deletion
ts/ts.h
with
982 additions
and
902 deletions
MEPA
+
3
−
0
View file @
1a93ea1f
...
...
@@ -11,3 +11,6 @@ R02: NADA
R00: NADA
CRCT 8
ARMZ 0,0
CHPR R01,0
DMEM 0
PARA
This diff is collapsed.
Click to expand it.
compilador.output
+
948
−
875
View file @
1a93ea1f
This diff is collapsed.
Click to expand it.
compilador.y
+
28
−
24
View file @
1a93ea1f
...
...
@@ -161,7 +161,7 @@ declaracao_procedimento: PROCEDURE IDENT {
char r_proc[4];
sprintf(r_proc, "R%02d", rot_id);
rot_id += 1;
info.pr.rot
=
r_proc;
strcpy(
info.pr.rot
,
r_proc
)
;
info.pr.quant = 0;
info.pr.param = NULL;
...
...
@@ -196,27 +196,49 @@ comando: numero DOIS_PONTOS comando_sem_rotulo
| comando_sem_rotulo
;
comando_sem_rotulo: atribuicao
comando_sem_rotulo: atribuicao
_ou_procedimento
| comando_composto
| comando_condicional
| comando_repetitivo
| leitura
| escrita
;
atribuicao_ou_procedimento: IDENT {l_elem = busca(token, ts);}
atribuicao_ou_procedimento_token
;
atribuicao_ou_procedimento_token: atribuicao
| chamada_procedimento
;
chamada_procedimento: /*IDENT {
l_elem = busca(token,ts);
atribuicao: {
if (l_elem == NULL) {
yyerror("Variável de destino não declarada");
} else {
destino_nivel = l_elem->nivel;
destino_desloc = l_elem->info.vs.desloc;
}
} ATRIBUICAO expressao_simples {
// Gera código ARMZ para armazenar valor
char buffer[50];
sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc);
geraCodigo(NULL, buffer);
};
chamada_procedimento: {
if (l_elem == NULL || l_elem->categ != PR) {
yyerror("Procedimento não declarado");
} else {
// Gera código para chamar o procedimento
char buffer[50];
mostra_ts(ts);
sprintf(buffer, "CHPR %s,%d", l_elem->info.pr.rot, nivel_lexico);
geraCodigo(NULL, buffer);
}
//ABRE_PARENTESES FECHA_PARENTESES
}
*/
}
;
leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES
...
...
@@ -285,24 +307,6 @@ termo: termo ASTERISCO fator {
| fator
;
atribuicao: IDENT {
mostra_ts(ts);
// Busca variável no lado esquerdo
l_elem = busca(token, ts);
if (l_elem == NULL) {
yyerror("Variável de destino não declarada");
} else {
destino_nivel = l_elem->nivel;
destino_desloc = l_elem->info.vs.desloc;
}
} ATRIBUICAO expressao_simples {
// Gera código ARMZ para armazenar valor
char buffer[50];
sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc);
geraCodigo(NULL, buffer);
};
fator: IDENT {
// Carrega variável
l_elem = busca(token, ts);
...
...
This diff is collapsed.
Click to expand it.
teste6.pas
+
1
−
1
View file @
1a93ea1f
...
...
@@ -7,5 +7,5 @@ program proc1 (input, output);
end
begin
x
:=
8
;
p
p
;
end
.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ts/ts.c
+
1
−
1
View file @
1a93ea1f
...
...
@@ -20,7 +20,7 @@ void insere_ts(char *ident, int categ, int nivel, info_t info, ts_t *ts){
new
->
info
.
vs
.
tipo
=
info
.
vs
.
tipo
;
new
->
info
.
vs
.
desloc
=
info
.
vs
.
desloc
;
}
else
if
(
categ
==
PR
)
{
new
->
info
.
pr
.
rot
=
info
.
pr
.
rot
;
strcpy
(
new
->
info
.
pr
.
rot
,
info
.
pr
.
rot
)
;
new
->
info
.
pr
.
quant
=
info
.
pr
.
quant
;
new
->
info
.
pr
.
param
=
(
int
**
)
malloc
(
info
.
pr
.
quant
*
sizeof
(
int
*
));
for
(
int
i
=
0
;
i
<
info
.
pr
.
quant
;
i
++
)
{
...
...
This diff is collapsed.
Click to expand it.
ts/ts.h
+
1
−
1
View file @
1a93ea1f
...
...
@@ -7,7 +7,7 @@ typedef struct vs_t {
}
vs_t
;
typedef
struct
pr_t
{
char
*
rot
;
char
rot
[
4
]
;
int
quant
;
int
**
param
;
}
pr_t
;
...
...
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