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
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
Tiago Henrique Conte
compilador
Commits
d44c0a3c
Commit
d44c0a3c
authored
2 years ago
by
Tiago Henrique Conte
Browse files
Options
Downloads
Patches
Plain Diff
Implementa forward
parent
8451a796
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
compilador.h
+2
-1
2 additions, 1 deletion
compilador.h
compilador.l
+6
-0
6 additions, 0 deletions
compilador.l
compilador.y
+41
-21
41 additions, 21 deletions
compilador.y
with
49 additions
and
22 deletions
compilador.h
+
2
−
1
View file @
d44c0a3c
...
...
@@ -65,7 +65,8 @@ typedef enum simbolos {
simb_integer
,
simb_boolean
,
simb_read
,
simb_write
simb_write
,
simb_forward
}
simbolos
;
typedef
enum
operacoes_t
{
...
...
This diff is collapsed.
Click to expand it.
compilador.l
+
6
−
0
View file @
d44c0a3c
...
...
@@ -281,6 +281,12 @@ write { simbolo = simb_write;
return WRITE;
}
forward { simbolo = simb_forward;
strncpy (token, yytext, TAM_TOKEN);
IMPRIME(" forward ");
return FORWARD;
}
{numero} { simbolo = simb_numero;
strncpy (token, yytext, TAM_TOKEN);
IMPRIME(" numero ");
...
...
This diff is collapsed.
Click to expand it.
compilador.y
+
41
−
21
View file @
d44c0a3c
...
...
@@ -38,7 +38,7 @@ char ident[50];
%token T_BEGIN T_END VAR NUMERO IDENT ATRIBUICAO
%token PROCEDURE FUNCTION GOTO LABEL ARRAY OF
%token IF THEN ELSE WHILE DO INTEGER BOOLEAN
%token READ WRITE
%token READ WRITE
FORWARD
/* Para funcionar o IF THEN ELSE
Precedências são crescentes, logo "lower_than_else" < "else" */
...
...
@@ -175,25 +175,34 @@ parte_declara_subrotinas:
declara_proc: PROCEDURE IDENT
{
// fprintf(stderr, "Ident: %s\n", token);
char *rotulo;
stack_push(rotulos, next_rot());
nivelLex++;
// Gera ENPR k com rotulo
rotulo = stack_item(rotulos, rotulos->top);
sprintf(comando, "ENPR %d", nivelLex);
geraCodigo(rotulo, comando);
// Adiciona procedimento à tabela de simbolos
if (buscaTS(token) == -1) {
stack_push(rotulos, next_rot());
rotulo = stack_item(rotulos, rotulos->top);
insereTS(token, cat_procedimento,
criaAtrProcedimento(rotulo));
}
}
param_formais
PONTO_E_VIRGULA bloco PONTO_E_VIRGULA
PONTO_E_VIRGULA declara_proc_extra
;
/* REGRA 12 - extra */
declara_proc_extra: FORWARD PONTO_E_VIRGULA { nivelLex--; }
| {
char *rotulo;
// Gera ENPR k com rotulo
rotulo = stack_item(rotulos, rotulos->top);
sprintf(comando, "ENPR %d", nivelLex);
geraCodigo(rotulo, comando);
} bloco PONTO_E_VIRGULA
{
char *rotulo;
...
...
@@ -220,17 +229,14 @@ declara_func: FUNCTION IDENT
char *rotulo;
stack_push(rotulos, next_rot());
nivelLex++;
// Gera ENPR k com rotulo
// Se não existe, adiciona função à tabela de simbolos
if (buscaTS(token) == -1) {
stack_push(rotulos, next_rot());
rotulo = stack_item(rotulos, rotulos->top);
sprintf(comando, "ENPR %d", nivelLex);
geraCodigo(rotulo, comando);
// Adiciona função à tabela de simbolos
insereTS(token, cat_funcao, criaAtrFuncao(rotulo));
}
}
param_formais DOIS_PONTOS tipo
...
...
@@ -246,7 +252,20 @@ declara_func: FUNCTION IDENT
break;
}
}
PONTO_E_VIRGULA bloco PONTO_E_VIRGULA
PONTO_E_VIRGULA declara_func_extra
;
/* REGRA 13 - extra */
declara_func_extra: FORWARD PONTO_E_VIRGULA { nivelLex--; }
| {
char *rotulo;
// Gera ENPR k com rotulo
rotulo = stack_item(rotulos, rotulos->top);
sprintf(comando, "ENPR %d", nivelLex);
geraCodigo(rotulo, comando);
} bloco PONTO_E_VIRGULA
{
char *rotulo;
...
...
@@ -567,6 +586,7 @@ comando_repetitivo: WHILE
/* REGRA 24 */
lista_expr: lista_expr VIRGULA { num_params++; } expr
| expr
|
;
/* REGRA 25 */
...
...
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