/
symbole.c
48 lines (42 loc) · 1.09 KB
/
symbole.c
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
#include "symbole.h"
#include <string.h>
//initialise la table des symboles
symtab init_symtab(){
symtab table = malloc (sizeof(struct str_symtab));
table->current_id = 0;
return table;
}
//alloue l'espace necessaire et renvoie un nouvel attribut vide
att new_attribute(){
att temp_att = malloc (sizeof(struct str_attribute));
return temp_att;
}
void put_attribute(symtab s, att a){
s->table[s->current_id] = a;
s->current_id ++;
}
//remplis les informations relatives a l'attribut
void set_attribute (att a, char* n, int t){
strcpy(a->name, n);
a->temp_value = t;
}
//recherche si un ident existe deja dans une table
int exist_ident(symtab s, char* c){
int i;
for(i=0; i<s->current_id; i++)
{
if(strcmp(s->table[i]->name, c) == 0)
return 1;
}
return 0;
}
//retourne l'identifiant correspondant de la table
att get_ident (symtab s, char * c){
int i;
for(i=0; i<s->current_id; i++)
{
if(strcmp(s->table[i]->name, c) == 0)
return s->table[i];
}
return new_attribute(); // n'arrive jamais normalement
}