Made some changes to the files t#29
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
//Defining a symbol table
|
||||
//Using a Linked List Structure. Head of linked List points to parent scope (if one exists)
|
||||
//Tail of Linked List points to a Linked List of all the child scopes
|
||||
//T
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//Tail of Linked List points to a List of child scopes
|
||||
|
||||
@ -66,9 +71,46 @@ TableNode * look_up(SymbolTable * table, char * x){
|
||||
}
|
||||
return look_up(table->Parent_Scope, x);
|
||||
}
|
||||
void print_symbol_table(SymbolTable *table, FILE *file_ptr){
|
||||
if(table->Parent_Scope == NULL){
|
||||
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation");
|
||||
}
|
||||
TableNode * entrie = table->entries;
|
||||
fprintf(file_ptr, "-----------------:--------:--------:----------------------:-----------------------------\n");
|
||||
int parant_scope = 0;
|
||||
int current_scope = 0;
|
||||
if(table->Parent_Scope != NULL){
|
||||
parant_scope = table->Parent_Scope->Line_Number*1000 + table->Parent_Scope->Column_Number;
|
||||
current_scope = table->Line_Number*1000 + table->Column_Number;
|
||||
} else {
|
||||
current_scope = 1001;
|
||||
}
|
||||
|
||||
for(; entrie != NULL; entrie = entrie->next){
|
||||
if (parant_scope == 0){
|
||||
fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n",
|
||||
entrie->theName, current_scope,
|
||||
entrie->theType, "Extra annotation");
|
||||
} else {
|
||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n",
|
||||
entrie->theName, current_scope, parant_scope,
|
||||
entrie->theType, "Extra annotation");
|
||||
}
|
||||
}
|
||||
if (table->Children_Scope != NULL){
|
||||
ListOfTable* node = table->Children_Scope;
|
||||
for(; node != NULL; node = node->next){
|
||||
print_symbol_table(node->table, file_ptr);
|
||||
}
|
||||
}
|
||||
if (table->Parent_Scope == NULL) {
|
||||
fprintf(file_ptr, "-----------------:--------:--------:----------------------:-----------------------------\n");
|
||||
}
|
||||
}
|
||||
|
||||
//uncomment the below main function along with the headers above for a simple standalone test of table and entry creation
|
||||
|
||||
/*
|
||||
int main(){
|
||||
char* String = "STRING";
|
||||
char* X = "X";
|
||||
@ -79,3 +121,4 @@ int main(){
|
||||
printf("The type of the first entry is %s\n",First_Entry->theType);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user