Skip to content
Snippets Groups Projects
Commit db5ddc0e authored by hm19's avatar hm19
Browse files

retira procedimentos e funcoes da ts

parent cce4d24b
Branches
No related tags found
No related merge requests found
File added
File added
This diff is collapsed.
/* A Bison parser, made by GNU Bison 3.5.1. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Undocumented macros, especially those whose name start with YY_,
are private implementation details. Do not rely on them. */
#ifndef YY_YY_COMPILADOR_TAB_H_INCLUDED
# define YY_YY_COMPILADOR_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
PROGRAM = 258,
ABRE_PARENTESES = 259,
FECHA_PARENTESES = 260,
VIRGULA = 261,
PONTO_E_VIRGULA = 262,
DOIS_PONTOS = 263,
PONTO = 264,
T_BEGIN = 265,
T_END = 266,
VAR = 267,
IDENT = 268,
ATRIBUICAO = 269,
LABEL = 270,
TYPE = 271,
ARRAY = 272,
PROCEDURE = 273,
FUNCTION = 274,
GOTO = 275,
IF = 276,
THEN = 277,
ELSE = 278,
WHILE = 279,
DO = 280,
OR = 281,
DIV = 282,
AND = 283,
NOT = 284,
IGUAL = 285,
DIFERENTE = 286,
MENOR_IGUAL = 287,
MAIOR_IGUAL = 288,
MENOR = 289,
MAIOR = 290,
MAIS = 291,
MENOS = 292,
ASTERISCO = 293,
NUMERO = 294,
READ = 295,
WRITE = 296,
LOWER_THAN_ELSE = 297
};
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_COMPILADOR_TAB_H_INCLUDED */
......@@ -80,10 +80,12 @@ bloco :
comando_composto {
char buffer[50];
sprintf(buffer,"DMEM %d",desloc);
desloc = retira(desloc,ts);
desloc = retira_pr_fun(ts);
desloc = retira_vs_pf(ts);
geraCodigo(NULL,buffer);
if (nivel_lexico > 0)
nivel_lexico += 1;
mostra_ts(ts);
}
;
......@@ -197,7 +199,7 @@ declaracao_procedimento: PROCEDURE IDENT {
n = l_elem->info.pr.quant;
sprintf(buffer,"RTPR %d,%d",l_elem->nivel,n);
geraCodigo(NULL,buffer);
desloc = retira(n,ts);
desloc = retira_vs_pf(ts);
mostra_ts(ts);
}
PONTO_E_VIRGULA
......
lex.yy.c 0 → 100644
This diff is collapsed.
File added
......@@ -67,6 +67,74 @@ simb_t *topo(ts_t *ts){
return ts->topo;
}
int retira_vs_pf(ts_t *ts) {
if (ts == NULL || ts->topo == NULL) {
return 0; // Nenhum elemento a ser removido
}
int i; // Contador de elementos removidos
simb_t *temp = ts->topo;
while (ts->topo != NULL && (ts->topo->categ == VS || ts->topo->categ == PF)) {
temp = ts->topo;
ts->topo = ts->topo->prox;
//free the intern stuff
if (temp->categ == VS) {
free(temp->ident);
} else if (temp->categ == PF) {
free(temp->ident);
}
free(temp);
ts->tam--;
}
//retorna novo deslocamento
while (temp != NULL) {
if (temp->categ == VS || temp->categ == PF) {
return temp->info.vs.desloc + 1;
}
temp = temp->prox;
}
return 0;
}
int retira_pr_fun(ts_t *ts) {
if (ts == NULL || ts->topo == NULL) {
return 0; // Nenhum elemento a ser removido
}
int i; // Contador de elementos removidos
simb_t *temp = ts->topo;
while (ts->topo != NULL && (ts->topo->categ == PR || ts->topo->categ == FUN)) {
temp = ts->topo;
ts->topo = ts->topo->prox;
//free the intern stuff
if (temp->categ == PR) {
free(temp->ident);
for (int i = 0; i < temp->info.pr.quant; i++) {
free(temp->info.pr.param[i]);
}
free(temp->info.pr.param);
} else if (temp->categ == FUN) {
free(temp->ident);
for (int i = 0; i < temp->info.fun.quant; i++) {
free(temp->info.fun.param[i]);
}
free(temp->info.fun.param);
}
free(temp);
ts->tam--;
}
//retorna novo deslocamento
while (temp != NULL) {
if (temp->categ == VS || temp->categ == PF) {
return temp->info.vs.desloc + 1;
}
temp = temp->prox;
}
return 0;
}
int retira(int n, ts_t *ts) {
if (ts == NULL || ts->topo == NULL) {
return 0; // Nenhum elemento a ser removido
......
......@@ -71,6 +71,10 @@ simb_t *topo(ts_t *ts);
int retira(int n, ts_t *ts);
int retira_vs_pf(ts_t *ts);
int retira_pr_fun(ts_t *ts);
void atualiza_tipo(int n, int tipo, ts_t *ts);
void adiciona_param(char *ident, int n, ts_t *ts);
......
ts/ts.o 0 → 100644
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment