-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabela.c
More file actions
116 lines (103 loc) · 3.35 KB
/
tabela.c
File metadata and controls
116 lines (103 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Arquivo original escrito por:
Autor: Ruben Carlo Benante
Email: benante@gmail.com
Data: 23/04/2009
Modificado: 25/05/2009
C88 versao 1 - tabela.h
Autores: Elton Oliveira, Marlon Chalegre
Rodrigo Castro, Romulo Jales
Emails: {elton.oliver, marlonchalegre
rodrigomsc, romulojales}@gmail.com
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tabela.h"
char buffer[100];
int idxId = 200;
int strxId = 1;
int idxCon = 30;
void iniciarTabelaSimb() {
tabelaSimb *sp = NULL;
for(sp = tabSimb; sp < &tabSimb[MAX_SIMB]; sp++) {
sp->uso = 0;
}
}
/* Procura na tabela de simbolos, nela iremos colocar nossas palavras reservadas e variaveis que estao sendo criadas */
/* se a palavra nao for encontrada ela e adicionada a tabela de simbolos*/
tabelaSimb* achaId(char *nome) {
tabelaSimb *sp = NULL;
for (sp = tabSimb; sp < &tabSimb[MAX_SIMB]; sp++) {
/* Existe? */
if (sp->uso && sp->idNome && !strcmp(sp->idNome, nome))
return sp;
/* ta livre? */
if (!sp->uso) {
sp->uso = 1;
sp->load = 0;
sp->tipoD = tipoIdIndef;
sp->idNome = strdup(nome); //coloca na tabela de simbolos
sp->idx = idxId;
idxId += 2;
sprintf(buffer, "(%d)", sp->idx);
sp->tval = strdup(buffer);
sprintf(buffer, "(%d)", sp->idx);
sp->mval = strdup(buffer);
return sp;
}
}
//a tabela de simbolos tem uma quantidade max, cuidado para n estourar
yyerror("Espaco insuficiente.\n");
return sp;
}
tabelaSimb* achaInt(int valor){
tabelaSimb *sp = NULL;
for(sp = tabSimb; sp < &tabSimb[MAX_SIMB]; sp++) {
/* Existe? */
if (sp->uso && sp->ival == valor &&
sp->tipoD == tipoConInt)
return sp;
/* ta livre? */
if (!sp->uso) {
sp->uso = 1;
sp->load = 0;
sp->tipoD = tipoConInt;
sp->ival = valor;
sp->idx = idxCon++;
sprintf(buffer, "%d", valor);
sp->tval = strdup(buffer);
sprintf(buffer, "%d", valor);
sp->mval = strdup(buffer);
return sp;
}
}
//a tabela de simbolos tem uma quantidade max, cuidado para n estourar
yyerror("Espaco insuficiente.\n");
return sp;
}
tabelaSimb* achaStr(char *valor){
tabelaSimb *sp = NULL;
for(sp = tabSimb; sp < &tabSimb[MAX_SIMB]; sp++) {
/* Existe? */
if (sp->uso && sp->sval && !strcmp(sp->sval, valor) &&
sp->tipoD == tipoConStr)
return sp;
/* ta livre? */
if (!sp->uso) {
sp->uso = 1;
sp->load = 0;
sp->tipoD = tipoConStr;
sp->sval = strdup(valor);
sp->idx = idxCon++;
sprintf(buffer, "str%d", strxId++);
sp->tval = strdup(buffer);
sprintf(buffer, "str%d", strxId-1);
sp->mval = strdup(buffer);
return sp;
}
}
//a tabela de simbolos tem uma quantidade max, cuidado para n estourar
yyerror("Espaco insuficiente.\n");
return sp;
}