123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #ifndef SYMBOL_TABLE_H_INCLUDED
- #define SYMBOL_TABLE_H_INCLUDED
-
- #define SYMBOL_TABLE_SIZE 100
-
- enum Type {
- TYPE_CONST,
- TYPE_INT
- };
-
- typedef struct SymbolItem {
- enum Type type;
- char *name;
- int address;
- int init;
- } SymbolItem;
-
- /**
- * Stores temp variables at the end of the table
- */
- typedef struct SymbolTable {
- struct SymbolItem table[SYMBOL_TABLE_SIZE];
- int index;
- int temp_index;
- } SymbolTable;
-
- /**
- * Initializes the table's index to 0
- *
- * @param table
- */
- void init_table(SymbolTable *table);
-
- /**
- * Checks if the given symbol is in the table
- *
- * @param table
- * @param name
- * @return
- */
- int has_symbol(SymbolTable* table, char *name);
-
- /**
- * Adds the given symbol to the table.
- *
- * @param table
- * @param type
- * @param name
- * @return 0 on success, -1 if the symbol already exists, -2 if the table is full
- */
- int add_symbol(SymbolTable* table, enum Type type, char *name);
-
- /**
- * Adds the given symbol to temporary variables space
- * Temporary variables must start with _
- *
- * @param table
- * @param type
- * @param name
- * @return 0 on success, -1 if the symbol already exists, -2 if the table is full
- * -3 if the name doesn't start by _
- */
- int add_temp_symbol(SymbolTable* table, enum Type type, char *name);
-
- /**
- * Marks the given symbol as initialized
- *
- * @param table
- * @param name
- * @return 0 on success, -1 if the symbol was not found, -2 if the symbol was already initialized
- */
- int mark_symbol_initialized(SymbolTable* table, char *name);
-
- /**
- * Prints the whole table to the console
- *
- * @param table
- */
- void print_table(SymbolTable* table);
-
- /**
- * Prints the given item to the console
- *
- * @param item
- */
- void print_item(struct SymbolItem *item);
-
- /**
- * Converts a Type to a string
- *
- * @param type
- * @return
- */
- char* type_to_string(enum Type type);
-
- /**
- * Gets the table line for the given symbol name
- *
- * @param table
- * @param name
- * @return the item if found, NULL otherwise
- */
- SymbolItem *get_symbol_item(SymbolTable* table, char *name);
-
- #endif /* !SYMBOL_TABLE_H_INCLUDED */
|