symtable.h 834 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef _SYMTABLE_H_
  2. #define _SYMTABLE_H_
  3. // type for index on the system table
  4. typedef int symtable_index;
  5. /* entry in the symbol table and its data
  6. */
  7. struct entry {
  8. char *lexptr;
  9. int token;
  10. int value;
  11. };
  12. // init
  13. void symtable_init();
  14. // lookup and insert functions
  15. symtable_index symtable_lookup(char s[]);
  16. symtable_index symtable_insert(char s[], int tok);
  17. /* scope functions
  18. * push: create a new (empty) symtable as a child of the current one
  19. * pop : remove current symtable (including clean) and assign parent as the current one
  20. */
  21. void symtable_push();
  22. void symtable_pop ();
  23. // responsible for cleaning memory
  24. void symtable_clean();
  25. // mostly for debugging, just print the table
  26. void symtable_print();
  27. // from an index to the symtable, get the entry
  28. struct entry *symtable_entryat(symtable_index index);
  29. #endif