Merge branch 'Dev' into Sprint2-Partho_Symbol_Tabke-FE-t#NoTask
This commit is contained in:
@ -36,6 +36,7 @@ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column) {
|
|||||||
|
|
||||||
//create entry just for things below top level scope
|
//create entry just for things below top level scope
|
||||||
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id) {
|
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id) {
|
||||||
|
|
||||||
if(table ==NULL || table->Parent_Scope == NULL){
|
if(table ==NULL || table->Parent_Scope == NULL){
|
||||||
printf("Null reference to table given for create entry or given top level scope which is invalid\n");
|
printf("Null reference to table given for create entry or given top level scope which is invalid\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -90,6 +91,7 @@ if(table_lookup(table,id) != NULL){
|
|||||||
newEntry->next = oldEntry;
|
newEntry->next = oldEntry;
|
||||||
return newEntry;
|
return newEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TableNode* table_lookup(SymbolTable* table, char* x) {
|
TableNode* table_lookup(SymbolTable* table, char* x) {
|
||||||
@ -130,7 +132,10 @@ void print_symbol_table(SymbolTable* table, FILE* file_ptr) {
|
|||||||
} else {
|
} else {
|
||||||
current_scope = 1001;
|
current_scope = 1001;
|
||||||
}
|
}
|
||||||
|
if ( entrie == NULL ) {
|
||||||
|
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "",
|
||||||
|
current_scope, parant_scope, "", "Empty Scope");
|
||||||
|
}
|
||||||
for (; entrie != NULL; entrie = entrie->next) {
|
for (; entrie != NULL; entrie = entrie->next) {
|
||||||
if (parant_scope == 0) {
|
if (parant_scope == 0) {
|
||||||
fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n",
|
fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n",
|
||||||
@ -179,13 +184,13 @@ int getColumn(SymbolTable* st) { return st->Column_Number; }
|
|||||||
// standalone test of table and entry creation
|
// standalone test of table and entry creation
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int main(){
|
int main(){
|
||||||
char* String = "STRING";
|
char* String = "STRING";
|
||||||
char* X = "X";
|
char* X = "X";
|
||||||
SymbolTable* Second = CreateScope(NULL, 2,2);
|
SymbolTable* Second = CreateScope(NULL, 2,2);
|
||||||
printf("Line number is %d, Column number of scope is
|
printf("Line number is %d, Column number of scope is
|
||||||
%d\n",Second->Line_Number,Second->Column_Number); TableNode* First_Entry =
|
%d\n",Second->Line_Number,Second->Column_Number); TableNode* First_Entry =
|
||||||
CreateEntry(Second,String,X);
|
CreateEntry(Second,String,X);
|
||||||
|
|
||||||
printf("The type of the first entry is %s\n",First_Entry->theType);
|
printf("The type of the first entry is %s\n",First_Entry->theType);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7,7 +7,6 @@ typedef struct ListOfTable {
|
|||||||
struct SymbolTable* table;
|
struct SymbolTable* table;
|
||||||
// struct ListOfTable* prev;
|
// struct ListOfTable* prev;
|
||||||
struct ListOfTable* next;
|
struct ListOfTable* next;
|
||||||
|
|
||||||
} ListOfTable;
|
} ListOfTable;
|
||||||
|
|
||||||
typedef struct TableNode {
|
typedef struct TableNode {
|
||||||
|
Reference in New Issue
Block a user