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
|
||||
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id) {
|
||||
|
||||
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");
|
||||
return NULL;
|
||||
@ -90,6 +91,7 @@ if(table_lookup(table,id) != NULL){
|
||||
newEntry->next = oldEntry;
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TableNode* table_lookup(SymbolTable* table, char* x) {
|
||||
@ -130,7 +132,10 @@ void print_symbol_table(SymbolTable* table, FILE* file_ptr) {
|
||||
} else {
|
||||
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) {
|
||||
if (parant_scope == 0) {
|
||||
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
|
||||
|
||||
/*
|
||||
int main(){
|
||||
int main(){
|
||||
char* String = "STRING";
|
||||
char* X = "X";
|
||||
SymbolTable* Second = CreateScope(NULL, 2,2);
|
||||
printf("Line number is %d, Column number of scope is
|
||||
%d\n",Second->Line_Number,Second->Column_Number); TableNode* First_Entry =
|
||||
CreateEntry(Second,String,X);
|
||||
%d\n",Second->Line_Number,Second->Column_Number); TableNode* First_Entry =
|
||||
CreateEntry(Second,String,X);
|
||||
|
||||
printf("The type of the first entry is %s\n",First_Entry->theType);
|
||||
return 0;
|
||||
|
@ -7,7 +7,6 @@ typedef struct ListOfTable {
|
||||
struct SymbolTable* table;
|
||||
// struct ListOfTable* prev;
|
||||
struct ListOfTable* next;
|
||||
|
||||
} ListOfTable;
|
||||
|
||||
typedef struct TableNode {
|
||||
|
Reference in New Issue
Block a user