Tabela de simbolos... Construção das funções.
[toypasc.git] / symbol_table.c
blob172667b9d4b854ebd19d8666fbb0668f95c3783a
1 #include <string.h>
2 #include "symbol_table.h"
4 void
5 symbol_table_destroy(Symbol * table)
7 Symbol * first, second;
8 first = table;
10 while(first != NULL){
12 second = first;
13 first = first->next;
14 free(second);
18 free(first);
19 free(second);
23 char *
24 symbol_table_dump(Symbol table)
27 Symbol * temp;
28 temp = table;
30 while(temp =! NULL){
32 printf("%s\n", temp->name);
33 printf("%d\n", temp->type);
34 temp = temp->next;
38 free(temp);
42 Symbol *
43 symbol_insert(Symbol * table, char const * name, int type)
46 Symbol * symbol = (Symbol *) malloc (sizeof(Symbol));
47 symbol->next = table;
48 strcpy (symbol->name,name);
49 symbol->type = type;
50 return symbol;
54 Symbol *
55 symbol_lookup(Symbol * table, char const * name)
58 Symbol * temp;
59 temp = table;
61 while(strcmp (temp->name,name) && temp != NULL){
63 temp = temp->next;
67 return temp;
71 int
72 symbol_exists(Symbol * table, char const * name)
75 Symbol * temp;
76 temp = table;
78 while(temp != NULL){
80 if(strcmp (temp->name,name)){
82 return 1;
88 return 0;