Guest User

symbol table headerfile

a guest
Feb 17th, 2018
421
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* maximum size of hash table */
  2. #define SIZE 211
  3.  
  4. /* maximum size of tokens-identifiers */
  5. #define MAXTOKENLEN 40
  6.  
  7. /* token types */
  8. #define UNDEF 0
  9. #define INT_TYPE 1
  10. #define REAL_TYPE 2
  11. #define STR_TYPE 3
  12. #define LOGIC_TYPE 4
  13. #define ARRAY_TYPE 5
  14. #define FUNCTION_TYPE 6
  15.  
  16. /* how parameter is passed */
  17. #define BY_VALUE 1
  18. #define BY_REFER 2
  19.  
  20. /* parameter struct */
  21. typedef struct Param{
  22.     int par_type;
  23.     char param_name[MAXTOKENLEN];
  24.     // to store value
  25.     int ival; double fval; char *st_sval;
  26.     int passing; // value or reference
  27. }Param;
  28.  
  29. /* a linked list of references (lineno's) for each variable */
  30. typedef struct RefList{
  31.     int lineno;
  32.     struct RefList *next;
  33.     int type;
  34. }RefList;
  35.  
  36. // struct that represents a list node
  37. typedef struct list_t{
  38.     char st_name[MAXTOKENLEN];
  39.     int st_size;
  40.     int scope;
  41.     RefList *lines;
  42.     // to store value and sometimes more information
  43.     int st_ival; double st_fval; char *st_sval;
  44.     // type
  45.     int st_type;
  46.     int inf_type; // for arrays (info type) and functions (return type)
  47.     // array stuff
  48.     int *i_vals; double *f_vals; char **s_vals;
  49.     int array_size;
  50.     // function parameters
  51.     Param *parameters;
  52.     int num_of_pars;
  53.     // pointer to next item in the list
  54.     struct list_t *next;
  55. }list_t;
  56.  
  57. /* the hash table */
  58. static list_t **hash_table;
  59.  
  60. // Function Declarations
  61. void init_hash_table(); // initialize hash table
  62. unsigned int hash(char *key); // hash function
  63. void insert(char *name, int len, int type, int lineno); // insert entry
  64. list_t *lookup(char *name); // search for entry
  65. list_t *lookup_scope(char *name); // search for entry in scope
  66. void hide(); // hide the current scope
  67. void hide_scope(int scope); // hide a specific scope
  68. void symtab_dump(FILE *of); // dump file
RAW Paste Data