avdl_symtable.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef _SYMTABLE_H_
  2. #define _SYMTABLE_H_
  3. #include "avdl_variable_type.h"
  4. #define DD_SYMTABLE_STRUCT 0
  5. #define DD_SYMTABLE_NATIVE 1
  6. // all symtable types
  7. enum symtable_tokens {
  8. SYMTABLE_VARIABLE,
  9. };
  10. // type for index on the system table
  11. typedef int symtable_index;
  12. extern int symtable_current;
  13. /* entry in the symbol table and its data
  14. */
  15. #define ENTRY_LEXPTR_SIZE 100
  16. struct entry {
  17. char lexptr[ENTRY_LEXPTR_SIZE];
  18. int token;
  19. int value;
  20. int isRef;
  21. char *scope;
  22. enum dd_variable_type varType;
  23. };
  24. // init
  25. void symtable_init();
  26. // lookup and insert functions
  27. symtable_index symtable_lookup(const char s[]);
  28. symtable_index symtable_insert(const char s[], int tok);
  29. struct entry *symtable_lookupEntry(const char s[]);
  30. /* scope functions
  31. * push: create a new (empty) symtable as a child of the current one
  32. * pop : remove current symtable (including clean) and assign parent as the current one
  33. */
  34. void symtable_push();
  35. void symtable_pop ();
  36. // responsible for cleaning memory
  37. void symtable_clean();
  38. // mostly for debugging, just print the table
  39. void symtable_print();
  40. // from an index to the symtable, get the entry
  41. struct entry *symtable_entryat(symtable_index index);
  42. #endif