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
68f30300
Commit
68f30300
authored
7 months ago
by
hm19
Browse files
Options
Downloads
Patches
Plain Diff
retorna procedimento, dmem e outros erros arrumados
parent
0429935b
No related branches found
No related tags found
No related merge requests found
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
MEPA
+7
-5
7 additions, 5 deletions
MEPA
compilador.output
+621
-556
621 additions, 556 deletions
compilador.output
compilador.y
+58
-39
58 additions, 39 deletions
compilador.y
ts/ts.c
+21
-6
21 additions, 6 deletions
ts/ts.c
ts/ts.h
+3
-1
3 additions, 1 deletion
ts/ts.h
with
710 additions
and
607 deletions
MEPA
+
7
−
5
View file @
68f30300
...
...
@@ -5,17 +5,19 @@ R01: ENPR 1
AMEM 1
DSVS R02
R02: NADA
CRVI 1,-5
ARMZ 1,0
CRCT 1
ARMI 1,-5
DMEM 1
RTPR 1,2
R00: NADA
AMEM 1
CREN 1,0
CRCT 8
ARMZ 0,0
CREN 0,0
CRCT 2
CRCT 3
SOMA
CHPR R01,0
ARMZ 0,0
DMEM 0
CHPR R01,2
DMEM 1
PARA
This diff is collapsed.
Click to expand it.
compilador.output
+
621
−
556
View file @
68f30300
This diff is collapsed.
Click to expand it.
compilador.y
+
58
−
39
View file @
68f30300
...
...
@@ -78,11 +78,12 @@ bloco :
}
comando_composto {
retira(desloc,ts);
char buffer[50];
sprintf(buffer,"DMEM %d",desloc);
desloc = retira(desloc,ts);
geraCodigo(NULL,buffer);
desloc = 0;
if (nivel_lexico > 0)
nivel_lexico += 1;
}
;
...
...
@@ -186,8 +187,18 @@ declaracao_procedimento: PROCEDURE IDENT {
parametros_ou_nada
PONTO_E_VIRGULA bloco
{
// Retorna ao nível léxico anterior e mantém o deslocamento atualizado
nivel_lexico -= 1;
char buffer[50];
desempilha(buffer,proc);
l_elem = busca(buffer,ts);
int n;
if(l_elem->categ == PR)
n = l_elem->info.pr.quant;
else if (l_elem->categ == FUN)
n = l_elem->info.pr.quant;
sprintf(buffer,"RTPR %d,%d",l_elem->nivel,n);
geraCodigo(NULL,buffer);
desloc = retira(n,ts);
mostra_ts(ts);
}
PONTO_E_VIRGULA
;
...
...
@@ -235,6 +246,7 @@ parametros_ou_nada: ABRE_PARENTESES
char proc_ident[50];
desempilha(proc_ident,proc);
adiciona_param(proc_ident,num_param,ts);
empilha(proc_ident,proc);
mostra_ts(ts);
}
FECHA_PARENTESES
...
...
@@ -329,9 +341,9 @@ atribuicao: {
chamada_procedimento:
{
if (l_elem == NULL
|| (l_elem->categ != PR && l_elem->categ != FUN))
{
if (l_elem == NULL
)
{
yyerror("Procedimento não declarado");
} else {
} else
if (l_elem->categ == PR || l_elem->categ == FUN)
{
// Gera código para chamar o procedimento
empilha(l_elem->ident, proc);
}
...
...
@@ -343,6 +355,7 @@ chamada_procedimento:
lista_parametros
{
if (l_elem->categ == PR || l_elem->categ ==FUN) {
char buffer[50];
mostra_ts(ts);
desempilha(buffer, proc);
...
...
@@ -351,13 +364,19 @@ chamada_procedimento:
// 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];
if(l_elem->categ == PR){
sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.",
l_elem->info.pr.quant, num_param);
yyerror(error_msg);
} else if(l_elem->categ == FUN){
sprintf(error_msg, "Erro: número de parâmetros incorreto. Esperado: %d, recebido: %d.",
l_elem->info.fun.quant, num_param);
yyerror(error_msg);
}
}
// Gera o código de chamada do procedimento
if (l_elem->categ == PR || l_elem->categ ==FUN) {
sprintf(buffer, "CHPR %s,%d", l_elem->info.pr.rot, nivel_lexico);
geraCodigo(NULL, buffer);
}
...
...
@@ -479,7 +498,7 @@ fator: IDENT {
char buffer[50];
desempilha(buffer, proc);
l_elem = busca(buffer, ts);
if (l_elem == NULL
|| l_elem->categ == PR
) {
if (l_elem == NULL) {
yyerror("Variável não declarada");
} else {
if (val_ou_ref == REF) {
...
...
This diff is collapsed.
Click to expand it.
ts/ts.c
+
21
−
6
View file @
68f30300
...
...
@@ -61,14 +61,20 @@ simb_t *busca(char *ident, ts_t *ts){
return
NULL
;
//nao tem
}
void
retira
(
int
n
,
ts_t
*
ts
)
{
if
(
ts
==
NULL
||
ts
->
topo
==
NULL
||
n
<=
0
)
{
return
;
// Nenhum elemento a ser removido
simb_t
*
topo
(
ts_t
*
ts
){
if
(
ts
==
NULL
)
return
NULL
;
return
ts
->
topo
;
}
int
retira
(
int
n
,
ts_t
*
ts
)
{
if
(
ts
==
NULL
||
ts
->
topo
==
NULL
)
{
return
0
;
// Nenhum elemento a ser removido
}
int
i
=
0
;
// Contador de elementos removidos
for
(;
i
<
n
&&
ts
->
topo
!=
NULL
;
i
++
)
{
int
i
;
// Contador de elementos removidos
simb_t
*
temp
=
ts
->
topo
;
for
(
i
=
0
;
i
<
n
&&
ts
->
topo
!=
NULL
;
i
++
)
{
temp
=
ts
->
topo
;
ts
->
topo
=
ts
->
topo
->
prox
;
free
(
temp
);
ts
->
tam
--
;
...
...
@@ -77,6 +83,15 @@ void retira(int n, ts_t *ts) {
if
(
i
<
n
)
{
printf
(
"Aviso: Tentativa de remover mais itens (%d) do que a pilha possui (%d). Removidos apenas %d itens.
\n
"
,
n
,
i
,
i
);
}
//retorna novo deslocamento
while
(
temp
!=
NULL
)
{
if
(
temp
->
categ
==
VS
)
{
return
temp
->
info
.
vs
.
desloc
+
1
;
}
temp
=
temp
->
prox
;
}
return
0
;
}
void
atualiza_tipo
(
int
n
,
int
tipo
,
ts_t
*
ts
){
...
...
This diff is collapsed.
Click to expand it.
ts/ts.h
+
3
−
1
View file @
68f30300
...
...
@@ -67,7 +67,9 @@ void insere_ts(char *ident, int categ, int nivel, info_t info, ts_t *ts);
simb_t
*
busca
(
char
*
ident
,
ts_t
*
ts
);
// Corrigido: retorna ponteiro para simb_t
void
retira
(
int
n
,
ts_t
*
ts
);
simb_t
*
topo
(
ts_t
*
ts
);
int
retira
(
int
n
,
ts_t
*
ts
);
void
atualiza_tipo
(
int
n
,
int
tipo
,
ts_t
*
ts
);
...
...
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