edited symbol table node structure to remove strlength and value as they are not needed
This commit is contained in:
@ -1,45 +1,8 @@
|
||||
//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 "symbol_table.h"
|
||||
/*
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//Tail of Linked List points to a List of child scopes
|
||||
|
||||
typedef struct ListOfTable{
|
||||
struct SymbolTable* table;
|
||||
//struct ListOfTable* prev;
|
||||
struct ListOfTable* next;
|
||||
|
||||
}ListOfTable;
|
||||
|
||||
typedef union Value{
|
||||
int* value_of_int;
|
||||
void* value_of_pointer;
|
||||
bool* value_of_bool;
|
||||
char* value_of_char;
|
||||
}Value;
|
||||
|
||||
typedef struct TableNode{
|
||||
char* theType;
|
||||
char* theName;
|
||||
Value* value;
|
||||
struct TableNode* next;
|
||||
//this next value is an int for string types to tell you how far to traverse a buffer for the string
|
||||
int StrLength;
|
||||
}TableNode;
|
||||
|
||||
typedef struct SymbolTable{
|
||||
TableNode* entries;
|
||||
struct SymbolTable* Parent_Scope;
|
||||
struct ListOfTable* Children_Scope;
|
||||
int Line_Number;
|
||||
int Column_Number;
|
||||
}SymbolTable;
|
||||
|
||||
*/
|
||||
#include "symbol_table.h"
|
||||
|
||||
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
|
||||
SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable));
|
||||
@ -68,12 +31,10 @@ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
|
||||
}
|
||||
|
||||
|
||||
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, int StringLength){
|
||||
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id){
|
||||
TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
|
||||
newEntry->theType = typeOf;
|
||||
newEntry->theName = id;
|
||||
newEntry->value = value;
|
||||
newEntry->StrLength = StringLength;
|
||||
if(table->entries == NULL){
|
||||
table->entries = newEntry;
|
||||
return newEntry;
|
||||
@ -86,16 +47,13 @@ TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value,
|
||||
}
|
||||
|
||||
//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";
|
||||
Value* ofX = (Value*)malloc(sizeof(Value));
|
||||
ofX->value_of_char = 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,ofX,-1);
|
||||
printf("The value of the first entry is %s\n",First_Entry->value->value_of_char);
|
||||
TableNode* First_Entry = CreateEntry(Second,String,X);
|
||||
printf("The type of the first entry is %s\n",First_Entry->theType);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user