Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
1.9 KiB

  1. #include "defs.h"
  2. /* TABLE_SIZE is the number of entries in the symbol table. */
  3. /* TABLE_SIZE must be a power of two. */
  4. #define TABLE_SIZE 1024
  5. bucket **symbol_table;
  6. bucket *first_symbol;
  7. bucket *last_symbol;
  8. int
  9. hash(name)
  10. char *name;
  11. {
  12. register char *s;
  13. register int c, k;
  14. assert(name && *name);
  15. s = name;
  16. k = *s;
  17. while (c = *++s)
  18. k = (31*k + c) & (TABLE_SIZE - 1);
  19. return (k);
  20. }
  21. bucket *
  22. make_bucket(name)
  23. char *name;
  24. {
  25. register bucket *bp;
  26. assert(name);
  27. bp = (bucket *) MALLOC(sizeof(bucket));
  28. if (bp == 0) no_space();
  29. bp->link = 0;
  30. bp->next = 0;
  31. bp->name = MALLOC(strlen(name) + 1);
  32. if (bp->name == 0) no_space();
  33. bp->tag = 0;
  34. bp->value = UNDEFINED;
  35. bp->index = 0;
  36. bp->prec = 0;
  37. bp-> class = UNKNOWN;
  38. bp->assoc = TOKEN;
  39. if (bp->name == 0) no_space();
  40. strcpy(bp->name, name);
  41. return (bp);
  42. }
  43. bucket *
  44. lookup(name)
  45. char *name;
  46. {
  47. register bucket *bp, **bpp;
  48. bpp = symbol_table + hash(name);
  49. bp = *bpp;
  50. while (bp)
  51. {
  52. if (strcmp(name, bp->name) == 0) return (bp);
  53. bpp = &bp->link;
  54. bp = *bpp;
  55. }
  56. *bpp = bp = make_bucket(name);
  57. last_symbol->next = bp;
  58. last_symbol = bp;
  59. return (bp);
  60. }
  61. #if defined(KYLEP_CHANGE)
  62. void
  63. #endif
  64. create_symbol_table()
  65. {
  66. register int i;
  67. register bucket *bp;
  68. symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *));
  69. if (symbol_table == 0) no_space();
  70. for (i = 0; i < TABLE_SIZE; i++)
  71. symbol_table[i] = 0;
  72. bp = make_bucket("error");
  73. bp->index = 1;
  74. bp->class = TERM;
  75. first_symbol = bp;
  76. last_symbol = bp;
  77. symbol_table[hash("error")] = bp;
  78. }
  79. #if defined(KYLEP_CHANGE)
  80. void
  81. #endif
  82. free_symbol_table()
  83. {
  84. FREE(symbol_table);
  85. symbol_table = 0;
  86. }
  87. #if defined(KYLEP_CHANGE)
  88. void
  89. #endif
  90. free_symbols()
  91. {
  92. register bucket *p, *q;
  93. for (p = first_symbol; p; p = q)
  94. {
  95. q = p->next;
  96. FREE(p);
  97. }
  98. }