Guest User

symtab.h

a guest
Mar 18th, 2018
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  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. /* current scope */
  21. int cur_scope = 0;
  22.  
  23. /* parameter struct */
  24. typedef struct Param{
  25.     int par_type;
  26.     char param_name[MAXTOKENLEN];
  27.     // to store value
  28.     int ival; double fval; char *st_sval;
  29.     int passing; // value or reference
  30. }Param;
  31.  
  32. /* a linked list of references (lineno's) for each variable */
  33. typedef struct RefList{
  34.     int lineno;
  35.     struct RefList *next;
  36.     int type;
  37. }RefList;
  38.  
  39. // struct that represents a list node
  40. typedef struct list_t{
  41.     char st_name[MAXTOKENLEN];
  42.     int st_size;
  43.     int scope;
  44.     RefList *lines;
  45.     // to store value and sometimes more information
  46.     int st_ival; double st_fval; char *st_sval;
  47.     // type
  48.     int st_type;
  49.     int inf_type; // for arrays (info type) and functions (return type)
  50.     // array stuff
  51.     int *i_vals; double *f_vals; char **s_vals;
  52.     int array_size;
  53.     // function parameters
  54.     Param *parameters;
  55.     int num_of_pars;
  56.     // pointer to next item in the list
  57.     struct list_t *next;
  58. }list_t;
  59.  
  60. /* the hash table */
  61. static list_t **hash_table;
  62.  
  63. // Function Declarations
  64. void init_hash_table(); // initialize hash table
  65. unsigned int hash(char *key); // hash function
  66. void insert(char *name, int len, int type, int lineno); // insert entry
  67. list_t *lookup(char *name); // search for entry
  68. list_t *lookup_scope(char *name, int scope); // search for entry in scope
  69. void hide_scope(); // hide the current scope
  70. void incr_scope(); // go to next scope
  71. void symtab_dump(FILE *of); // dump file
Add Comment
Please, Sign In to add comment