-
Notifications
You must be signed in to change notification settings - Fork 0
/
symboltable.c
43 lines (39 loc) · 1.08 KB
/
symboltable.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
#include "symboltable.h"
void addToSymbolTable(char* val,int mem,char *ident,symbol_table_entry **head){
symbol_table_entry *new_entry;
symbol_table_entry *tmp;
new_entry=(symbol_table_entry*)malloc(sizeof(symbol_table_entry));
new_entry->val=val;
new_entry->ident=ident;
new_entry->mem=mem;
//new_entry->tmpident=tmpident;
new_entry->next=NULL;
if(*head==NULL){
*head=new_entry;
}else{
tmp=*head;
while(
tmp->next!=NULL){
tmp=tmp->next;
}
tmp->next=new_entry;
}
}
void printAllSymbolElements(symbol_table_entry *head){
while(head!=NULL){
printf("%s - %d\n",head->ident,head->mem);
head=head->next;
}
}
void printAllSymbolElementsToFile(symbol_table_entry *head, FILE *f){
while(head!=NULL){
fprintf(f,"%s -> %s->mem:%d\n",head->ident,head->val,head->mem);
head=head->next;
}
}
symbol_table_entry* findIdent(char* ident,symbol_table_entry *symbol_entry){
while(symbol_entry!=NULL && (strcmp(ident,symbol_entry->ident))){
symbol_entry=symbol_entry->next;
}
return symbol_entry;
}