home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / jikepg12.zip / jikespg / src / common.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-04  |  32.9 KB  |  840 lines

  1. /* $Id: common.h,v 1.2 1999/11/04 14:02:21 shields Exp $ */
  2. /*
  3.  This software is subject to the terms of the IBM Jikes Compiler
  4.  License Agreement available at the following URL:
  5.  http://www.ibm.com/research/jikes.
  6.  Copyright (C) 1983, 1999, International Business Machines Corporation
  7.  and others.  All Rights Reserved.
  8.  You must accept the terms of that agreement to use this software.
  9. */
  10. #ifndef COMMON_INCLUDED
  11. #define COMMON_INCLUDED
  12.  
  13. /*******************************************************************/
  14. /* One of the switches below may have to be set prior to building  */
  15. /* JIKES PG. OS2 is for all C compilers running under OS2. DOS is  */
  16. /* for all C compilers running under DOS. Note that to run under   */
  17. /* DOS, the compiler used must support the Huge model (32-bit ptr  */
  18. /* simulation). C370 is for the IBM C compiler running under CMS   */
  19. /* or MVS. CW is for the Waterloo C compiler running under VM/CMS. */
  20. /*                                                                 */
  21. /* This system was built to run on a vanilla Unix or AIX system.   */
  22. /* No switch need to be set for such an environment.  Set other    */
  23. /* switch(es) as needed. Note that the switch C370 should always   */
  24. /* be accompanied by either the switch VM or the switch MVS.       */
  25. /*                                                                 */
  26. /*******************************************************************/
  27. /*
  28. #define DOS
  29. #define OS2
  30. #define MVS
  31. #define CW
  32. #define C370
  33. #define VM
  34. */
  35.  
  36. #include <assert.h>
  37. #include <stddef.h>
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <limits.h>
  41. #include "c370.h"
  42.  
  43. /*******************************************************************/
  44. /*******************************************************************/
  45. /**                                                               **/
  46. /**                         GLOBAL CONSTANTS                      **/
  47. /**                                                               **/
  48. /*******************************************************************/
  49. /*******************************************************************/
  50. #define PR_HEADING  \
  51.     { \
  52.         fprintf(syslis, "\f\n\n %-39s%s %-30.24s Page %d\n\n",\
  53.                         HEADER_INFO, VERSION, timeptr, ++page_no);\
  54.                         output_line_no = 4;\
  55.     }
  56. #define MAX_PARM_SIZE      22
  57. #define SYMBOL_SIZE        256
  58. #define MAX_MSG_SIZE       (256 + SYMBOL_SIZE)
  59. #define PRINT_LINE_SIZE    80
  60. #define PARSER_LINE_SIZE   80
  61. #define MAX_LINE_SIZE      256
  62.  
  63. #undef  PAGE_SIZE
  64. #define PAGE_SIZE          55
  65. #define OPTIMIZE_TIME      1
  66. #define OPTIMIZE_SPACE     2
  67. #define MINIMUM_NAMES      1
  68. #define MAXIMUM_NAMES      2
  69. #define OPTIMIZE_PHRASES   3
  70. #define NOTRACE            0
  71. #define TRACE_CONFLICTS    1
  72. #define TRACE_FULL         2
  73. #define STATE_TABLE_UBOUND 1020
  74. #define STATE_TABLE_SIZE   (STATE_TABLE_UBOUND + 1) /* 1021 is a prime */
  75. #define SHIFT_TABLE_UBOUND 400
  76. #define SHIFT_TABLE_SIZE   (SHIFT_TABLE_UBOUND + 1) /* 401 is a prime */
  77. #define SCOPE_UBOUND       100
  78. #define SCOPE_SIZE         (SCOPE_UBOUND + 1)   /* 101 is prime */
  79. #undef  FALSE
  80. #undef  TRUE
  81. #define FALSE              0
  82. #define TRUE               1
  83. #define IS_A_TERMINAL      <= num_terminals
  84. #define IS_A_NON_TERMINAL  > num_terminals
  85.  
  86. #define SPACE          ' '
  87. #define COMMA          ','
  88. #define INFINITY       ((short) SHRT_MAX)
  89. #define OMEGA          ((short) SHRT_MIN)
  90. #define NIL            ((short) SHRT_MIN + 1)
  91. #define DEFAULT_SYMBOL 0
  92.  
  93. /*******************************************************************/
  94. /*******************************************************************/
  95. /**                                                               **/
  96. /**                       ALLOCATE/FREE MACROS                    **/
  97. /**                                                               **/
  98. /*******************************************************************/
  99. /*******************************************************************/
  100. /* The following macro definitions are used to preprocess calls to */
  101. /* allocate routines that require locations. The FFREE macro is    */
  102. /* normally an invocation to the FREE routine. It is encoded as    */
  103. /* a macro here in case we need to do some debugging on dynamic    */
  104. /* storage.                                                        */
  105. /*******************************************************************/
  106. #define Allocate_node()           allocate_node(hostfile, __LINE__)
  107. #define Allocate_int_array(n)     allocate_int_array(n, hostfile, __LINE__)
  108. #define Allocate_short_array(n)   allocate_short_array(n, hostfile, __LINE__)
  109. #define Allocate_boolean_array(n) allocate_boolean_array(n, hostfile, __LINE__)
  110. #define Allocate_goto_map(n)      allocate_goto_map(n, hostfile, __LINE__)
  111. #define Allocate_shift_map(n)     allocate_shift_map(n, hostfile, __LINE__)
  112. #define Allocate_reduce_map(n)    allocate_reduce_map(n, hostfile, __LINE__)
  113.  
  114. #define ffree(x) free(x) /* { free(x); x = (void *) ULONG_MAX; } */
  115.  
  116. /*******************************************************************/
  117. /*******************************************************************/
  118. /**                                                               **/
  119. /**                          PARSING MACROS                       **/
  120. /**                                                               **/
  121. /*******************************************************************/
  122. /*******************************************************************/
  123. /* The following macro definitions are used only in processing the */
  124. /* input source.                                                   */
  125. /*******************************************************************/
  126. #define EQUAL_STRING(symb, p) \
  127.         (strcmp((symb), string_table + (p) -> st_ptr) == 0)
  128.  
  129. #define EXTRACT_STRING(indx) (&string_table[indx])
  130.  
  131. #define HT_SIZE           701     /* 701 is a prime */
  132. #define RULEHDR_INCREMENT 1024
  133. #define ACTELMT_INCREMENT 1024
  134. #define DEFELMT_INCREMENT 16
  135.  
  136. #ifdef DOS
  137. #define IOBUFFER_SIZE 8192
  138. #else
  139. #define IOBUFFER_SIZE 65536
  140. #endif
  141.  
  142. /*******************************************************************/
  143. /*******************************************************************/
  144. /**                                                               **/
  145. /**                         BIT SET MACROS                        **/
  146. /**                                                               **/
  147. /*******************************************************************/
  148. /*******************************************************************/
  149. /* The following macros are used to define operations on sets that */
  150. /* are represented as bit-strings.  BOOLEAN_CELL is a type that is */
  151. /* used as the elemental unit used to construct the sets.  For     */
  152. /* example, if BOOLEAN_CELL consists of four bytes and assumming   */
  153. /* that each byte contains 8 bits then the constant SIZEOF_BC      */
  154. /* represents the total number of bits that is contained in each   */
  155. /* elemental unit.                                                 */
  156. /*                                                                 */
  157. /* In general, a parameter called "set" or "set"i, where i is an   */
  158. /* integer, is a pointer to a set or array of sets; a parameter    */
  159. /* called "i" or "j" represents an index in an array of sets; a    */
  160. /* parameter called "b" represents a particular element (or bit)   */
  161. /* within a set.                                                   */
  162. /*                                                                 */
  163. /*******************************************************************/
  164. #define SIZEOF_BC (sizeof(BOOLEAN_CELL) * CHAR_BIT)
  165. #define BC_OFFSET (SIZEOF_BC - 1)
  166.  
  167. /*******************************************************************/
  168. /* This macro takes as argument an array of bit sets called "set", */
  169. /* an integer "nt" indicating the index of a particular set in the */
  170. /* array and an integer "t" indicating a particular element within */
  171. /* the set. IS_IN_SET check whether ot not the element "t" is in   */
  172. /* the set "set(nt)".                                              */
  173. /*                                                                 */
  174. /* The value (nt*term_set_size) is used to determine the starting  */
  175. /* address of the set element in question.  The value              */
  176. /* (??? / SIZEOF_BC) is used to determine the actual BOOLEAN_CELL  */
  177. /* containing the bit in question.  Finally, the value             */
  178. /* (SIZEOF_BC - (t % SIZEOF_BC)) identifies the actual bit in the  */
  179. /* unit. The bit in question is pushed to the first position and   */
  180. /* and-ed with the value 01. This operation yields the value TRUE  */
  181. /* if the bit is on. Otherwise, the value FALSE is obtained.       */
  182. /* Recall that in C, one cannot shift (left or right) by 0. This   */
  183. /* is why the ? is used here.                                      */
  184. /*******************************************************************/
  185. #define IS_IN_SET(set, i, b)    /* is b in set[i] ? */ \
  186.     ((set)[(i) * term_set_size + (((b) - 1) / SIZEOF_BC)] & \
  187.           (((b) + BC_OFFSET) % SIZEOF_BC ? \
  188.            (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
  189.            (BOOLEAN_CELL) 1))
  190.  
  191. /*******************************************************************/
  192. /* The macro SET_UNION takes as argument two arrays of sets:       */
  193. /* "set1" and "set2", and two integers "i" and "j" which are       */
  194. /* indices to be used to access particular sets in "set1" and      */
  195. /* "set2", respectively.  SET_UNION computes the union of the two  */
  196. /* sets in question and places the result in the relevant set in   */
  197. /* "set1".                                                         */
  198. /*                                                                 */
  199. /* The remaining macros are either analoguous to IS_IN_SET or      */
  200. /* SET_UNION.                                                      */
  201. /*                                                                 */
  202. /* Note that a macro with the variable "kji" declared in its body  */
  203. /* should not be invoked with a parameter of the same name.        */
  204. /*                                                                 */
  205. /*******************************************************************/
  206. #define SET_UNION(set1, i, set2, j)    /* set[i] union set2[j] */ \
  207.     { \
  208.         register int kji; \
  209.         for (kji = 0; kji < term_set_size; kji++) \
  210.              (set1)[(i) * term_set_size + kji] |= \
  211.                    (set2)[(j) * term_set_size + kji]; \
  212.     }
  213.  
  214. #define INIT_SET(set)    /* set = {} */ \
  215.     { \
  216.         register int kji; \
  217.         for (kji = 0; kji < term_set_size; kji++) \
  218.              (set)[kji] = 0; \
  219.     }
  220.  
  221. #define ASSIGN_SET(set1, i, set2, j)    /* set1[i] = set2[j] */ \
  222.     { \
  223.         register int kji; \
  224.         for (kji = 0; kji < term_set_size; kji++) \
  225.              (set1)[(i) * term_set_size + kji] = \
  226.                    (set2)[(j) * term_set_size + kji]; \
  227.     }
  228.  
  229. #define SET_BIT_IN(set, i, b)    /* set[i] = set[i] with b; */ \
  230.     (set)[(i) * term_set_size + (((b) - 1) / SIZEOF_BC)] |= \
  231.          (((b) + BC_OFFSET) % SIZEOF_BC ? \
  232.           (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
  233.           (BOOLEAN_CELL) 1);
  234.  
  235. #define RESET_BIT_IN(set, i, b)    /* set[i] = set[i] less b; */ \
  236.     (set)[(i) * term_set_size + (((b) - 1) / SIZEOF_BC)] &= \
  237.          ~(((b) + BC_OFFSET) % SIZEOF_BC ? \
  238.            (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC): \
  239.            (BOOLEAN_CELL) 1);
  240.  
  241. /*******************************************************************/
  242. /* The following macros are analogous to the ones above, except    */
  243. /* that they deal with sets of non-terminals instead of sets of    */
  244. /* terminals.                                                      */
  245. /*******************************************************************/
  246. #define IS_IN_NTSET(set, i, b)    /* is b in set[i] ? */ \
  247.     ((set)[(i) * non_term_set_size + (((b) - 1) / SIZEOF_BC)] & \
  248.           (((b) + BC_OFFSET) % SIZEOF_BC ? \
  249.            (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
  250.            (BOOLEAN_CELL) 1))
  251.  
  252. #define NTSET_UNION(set1, i, set2, j)    /* set1[i] union set2[j] */ \
  253.     { \
  254.         register int kji; \
  255.         for (kji = 0; kji < non_term_set_size; kji++) \
  256.              (set1)[(i) * non_term_set_size + kji] |= \
  257.                    (set2)[(j) * non_term_set_size + kji]; \
  258.     }
  259.  
  260. #define INIT_NTSET(set)    /* set = {} */ \
  261.     { \
  262.         register int kji; \
  263.         for (kji = 0; kji < non_term_set_size; kji++) \
  264.              (set)[kji] = 0; \
  265.     }
  266.  
  267. #define ASSIGN_NTSET(set1, i, set2, j)    /* set1[i] = set2[j] */ \
  268.     { \
  269.         register int kji; \
  270.         for (kji = 0; kji < non_term_set_size; kji++) \
  271.              (set1)[(i) * non_term_set_size + kji] = \
  272.                    (set2)[(j) * non_term_set_size + kji]; \
  273.     }
  274.  
  275. #define NTSET_BIT_IN(set, i, b)    /* set[i] = set[i] with b; */ \
  276.     (set)[(i) * non_term_set_size + (((b) - 1) / SIZEOF_BC)] |= \
  277.          (((b) + BC_OFFSET) % SIZEOF_BC ? \
  278.           (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
  279.           (BOOLEAN_CELL) 1);
  280.  
  281. #define NTRESET_BIT_IN(set, i, b)    /* set[i] = set[i] less b; */ \
  282.     (set)[(i) * non_term_set_size + (((b) - 1) / SIZEOF_BC)] &= \
  283.          ~(((b) + BC_OFFSET) % SIZEOF_BC ? \
  284.            (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC): \
  285.            (BOOLEAN_CELL) 1);
  286.  
  287. /*******************************************************************/
  288. /* The following macros are analogous to the ones above, except    */
  289. /* that they deal with sets of states instead of sets of terminals */
  290. /* or non-terminals.                                               */
  291. /*******************************************************************/
  292. #define SET_COLLECTION_BIT(i, b) \
  293.     collection[(i) * state_set_size + (((b) - 1) / SIZEOF_BC)] |= \
  294.          (((b) + BC_OFFSET) % SIZEOF_BC ? \
  295.           (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
  296.           (BOOLEAN_CELL) 1);
  297.  
  298. #define EMPTY_COLLECTION_SET(i) \
  299.     { \
  300.         register int kji; \
  301.         for (kji = 0; kji < state_set_size; kji++) \
  302.              collection[(i) * state_set_size + kji] = 0; \
  303.     }
  304.  
  305. /*******************************************************************/
  306. /* The following macros can be used to check, set, or reset a bit  */
  307. /* in a bit-string of any length.                                  */
  308. /*******************************************************************/
  309. #define SET_BIT(set, b) \
  310.     (set)[((b) - 1) / SIZEOF_BC] |= \
  311.          (((b) + BC_OFFSET) % SIZEOF_BC ? \
  312.           (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
  313.           (BOOLEAN_CELL) 1);
  314.  
  315. #define RESET_BIT(set, b) \
  316.     (set)[((b) - 1) / SIZEOF_BC] &= \
  317.          ~(((b) + BC_OFFSET) % SIZEOF_BC ? \
  318.            (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC): \
  319.            (BOOLEAN_CELL) 1);
  320.  
  321. #define IS_ELEMENT(set, b)    /* is b in set ? */ \
  322.     ((set)[((b) - 1) / SIZEOF_BC] & \
  323.           (((b) + BC_OFFSET) % SIZEOF_BC ? \
  324.            (BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
  325.            (BOOLEAN_CELL) 1))
  326.  
  327. /*******************************************************************/
  328. /*******************************************************************/
  329. /**                                                               **/
  330. /**                         ITERATION MACROS                      **/
  331. /**                                                               **/
  332. /*******************************************************************/
  333. /*******************************************************************/
  334. /* The following macros (ALL_) are used to iterate over a sequence.*/
  335. /*******************************************************************/
  336. #define ALL_LA_STATES(indx) \
  337.         (indx = num_states + 1; indx <= (int) max_la_state; indx++)
  338.  
  339. #define ALL_TERMINALS(indx) \
  340.         (indx = 1; indx <= num_terminals; indx++)
  341. #define ALL_TERMINALS_BACKWARDS(indx) \
  342.         (indx = num_terminals; indx >= 1; indx--)
  343.  
  344. #define ALL_NON_TERMINALS(indx) \
  345.         (indx = num_terminals + 1; indx <= num_symbols; indx++)
  346. #define ALL_NON_TERMINALS_BACKWARDS(indx) \
  347.         (indx = num_symbols; indx >= num_terminals + 1; indx--)
  348.  
  349. #define ALL_SYMBOLS(indx) (indx = 1; indx <= num_symbols; indx++)
  350.  
  351. #define ALL_ITEMS(indx) (indx = 1; indx <= (int) num_items; indx++)
  352.  
  353. #define ALL_STATES(indx) (indx = 1; indx <= (int) num_states; indx++)
  354.  
  355. #define ALL_RULES(indx) (indx = 0; indx <= num_rules; indx++)
  356. #define ALL_RULES_BACKWARDS(indx) \
  357.         (indx = num_rules; indx >= 0; indx--)
  358.  
  359. #define ENTIRE_RHS(indx, rule_no) (indx = rules[rule_no].rhs;\
  360.                                    indx < rules[(rule_no) + 1].rhs;\
  361.                                    indx++)
  362. #define RHS_SIZE(rule_no) (rules[(rule_no) + 1].rhs - rules[rule_no].rhs)
  363. #define RETRIEVE_STRING(indx) (&string_table[symno[indx].ptr])
  364. #define RETRIEVE_NAME(indx) (&string_table[name[indx]])
  365.  
  366. /*******************************************************************/
  367. /*******************************************************************/
  368. /**                                                               **/
  369. /**                      MISCELLANEOUS MACROS                     **/
  370. /**                                                               **/
  371. /*******************************************************************/
  372. /*******************************************************************/
  373. #define TOUPPER(c) (islower(c) ? toupper(c) : c)
  374. #define MAX(a,b)   (((a) > (b)) ? (a) : (b))
  375. #define MIN(a,b)   (((a) < (b)) ? (a) : (b))
  376.  
  377. #define ABS(x) (((x) < 0) ? -(x) : (x))
  378.  
  379. #define NOT(item) (! item)
  380.  
  381. /**********************************************************************/
  382. /* The following two macros check whether or not the value of an      */
  383. /* integer variable exceeds the maximum limit for a short or a long   */
  384. /* integer, respectively. Note that the user should declare the       */
  385. /* variable in question as a long integer. In the case of INT_CHECK,  */
  386. /* this check is meaningful only if INT and SHORT are the same size.  */
  387. /* Otherwise, if INT and LONG are of the same size, as is usually the */
  388. /* case on large systems, this check is meaningless - too late !!!    */
  389. /**********************************************************************/
  390. #define SHORT_CHECK(var) \
  391.     if (var > SHRT_MAX) \
  392.     { \
  393.         PRNTERR("The limit of a short int value" \
  394.                 " has been exceeded by " #var); \
  395.         exit(12); \
  396.     }
  397.  
  398. #define INT_CHECK(var) \
  399.     if (var > INT_MAX) \
  400.     { \
  401.         PRNTERR("The limit of an int value" \
  402.                 " has been exceeded by " #var); \
  403.         exit(12); \
  404.     }
  405.  
  406. #define ENDPAGE_CHECK if (++output_line_no >= PAGE_SIZE) \
  407.                           PR_HEADING
  408.  
  409. #define PRNT(msg) \
  410.     { \
  411.         printf("%s\n",msg); \
  412.         fprintf(syslis,"%s\n",msg); \
  413.         ENDPAGE_CHECK; \
  414.     }
  415.  
  416. #define PRNTWNG(msg) \
  417.     { \
  418.         printf("***WARNING: %s\n",msg);\
  419.         fprintf(syslis,"***WARNING: %s\n",msg);\
  420.         ENDPAGE_CHECK; \
  421.     }
  422.  
  423. #define PRNTERR(msg) \
  424.     { \
  425.         printf("***ERROR: %s\n",msg);\
  426.         fprintf(syslis,"***ERROR: %s\n",msg);\
  427.         ENDPAGE_CHECK; \
  428.     }
  429.  
  430. /*******************************************************************/
  431. /*******************************************************************/
  432. /**                                                               **/
  433. /**     MACROS FOR DEREFERENCING AUTOMATON HEADER STRUCTURES      **/
  434. /**                                                               **/
  435. /*******************************************************************/
  436. /*******************************************************************/
  437. #define SHIFT_SYMBOL(hdr, indx)   (((hdr).map)[indx].symbol)
  438. #define SHIFT_ACTION(hdr, indx)   (((hdr).map)[indx].action)
  439.  
  440. #define GOTO_SYMBOL(hdr, indx)    (((hdr).map)[indx].symbol)
  441. #define GOTO_ACTION(hdr, indx)    (((hdr).map)[indx].action)
  442. #define GOTO_LAPTR(hdr, indx)     (((hdr).map)[indx].laptr)
  443.  
  444. #define REDUCE_SYMBOL(hdr, indx)  (((hdr).map)[indx].symbol)
  445. #define REDUCE_RULE_NO(hdr, indx) (((hdr).map)[indx].rule_number)
  446.  
  447. /*******************************************************************/
  448. /*******************************************************************/
  449. /**                                                               **/
  450. /**                         OUTPUT MACROS                         **/
  451. /**                                                               **/
  452. /*******************************************************************/
  453. /*******************************************************************/
  454. /* The following macro definitions are used only in processing the */
  455. /* output.                                                         */
  456. /*******************************************************************/
  457. #define BUFFER_CHECK(file) \
  458.     if ((IOBUFFER_SIZE - (output_ptr - &output_buffer[0])) < 73) \
  459.     { \
  460.         fwrite(output_buffer, sizeof(char), \
  461.                output_ptr - &output_buffer[0], file); \
  462.         output_ptr = &output_buffer[0]; \
  463.     }
  464.  
  465. /*******************************************************************/
  466. /*******************************************************************/
  467. /**                                                               **/
  468. /**                      GLOBAL DECLARATIONS                      **/
  469. /**                                                               **/
  470. /*******************************************************************/
  471. /*******************************************************************/
  472. typedef unsigned int BOOLEAN_CELL; /* Basic unit used to represent */
  473.                                    /* Bit sets                     */
  474. typedef BOOLEAN_CELL *SET_PTR;
  475.  
  476. typedef char BOOLEAN;
  477.  
  478. extern const char HEADER_INFO[];
  479. extern const char VERSION[];
  480. extern const char BLANK[];
  481. extern const long MAX_TABLE_SIZE;
  482.  
  483. struct node
  484. {
  485.     struct node *next;
  486.     int          value;
  487. };
  488.  
  489. /*******************************************************************/
  490. /* RULES is the structure that contain the rules of the grammar.   */
  491. /* Every rule of the grammar is mapped into an integer, and given  */
  492. /* rule, and we have access to a value RHS which is the index      */
  493. /* location in the vector RHS where the right-hand-side of the rule*/
  494. /* begins.  The right hand side of a certain rule represented by an*/
  495. /* integer I starts at index location RULES[I].RHS in RHS, and     */
  496. /* ends at index location RULES[I + 1].RHS - 1.  An extra          */
  497. /* NUM_RULES + 1 element is used as a "fence" for the last rule.   */
  498. /* The RHS vector as mentioned above is used to hold a complete    */
  499. /* list of allthe right-hand-side symbols specified in the grammar.*/
  500. /*******************************************************************/
  501. struct ruletab_type
  502. {
  503.     short   lhs,
  504.             rhs;
  505.     BOOLEAN sp;
  506. };
  507.  
  508. struct shift_type
  509. {
  510.     short symbol,
  511.           action;
  512. };
  513.  
  514. struct shift_header_type
  515. {
  516.     struct shift_type *map;
  517.     short              size;
  518. };
  519.  
  520. struct reduce_type
  521. {
  522.     short symbol,
  523.           rule_number;
  524. };
  525.  
  526. struct reduce_header_type
  527. {
  528.     struct reduce_type *map;
  529.     short              size;
  530. };
  531.  
  532. struct goto_type
  533. {
  534.     int   laptr;
  535.     short symbol,
  536.           action;
  537. };
  538.  
  539. struct goto_header_type
  540. {
  541.     struct goto_type *map;
  542.     short             size;
  543. };
  544.  
  545. struct lastats_type
  546. {
  547.     struct reduce_header_type reduce;
  548.     short                     shift_number,
  549.                               in_state;
  550. };
  551.  
  552. struct statset_type
  553. {
  554.     struct node             *kernel_items,
  555.                             *complete_items;
  556.     struct goto_header_type  go_to;
  557.     short                    shift_number;
  558. };
  559.  
  560. extern char *timeptr;
  561.  
  562. extern long output_line_no;
  563.  
  564. extern char grm_file[],
  565.             lis_file[],
  566.             act_file[],
  567.             hact_file[],
  568.             tab_file[],
  569.             prs_file[],
  570.             sym_file[],
  571.             def_file[],
  572.             dcl_file[],
  573.             file_prefix[],
  574.             prefix[],
  575.             suffix[],
  576.             parm[],
  577.             msg_line[];
  578.  
  579. extern FILE *syslis,
  580.             *sysgrm,
  581.             *sysact,
  582.             *syshact,
  583.             *systab,
  584.             *syssym,
  585.             *sysprs,
  586.             *sysdcl,
  587.             *sysprs,
  588.             *sysdef;
  589.  
  590.  
  591. /******************************************************/
  592. /*  The variables below are global counters.          */
  593. /******************************************************/
  594. extern long num_items,
  595.             num_states,
  596.             max_la_state;
  597.  
  598. extern int num_symbols,
  599.            symno_size,  /* NUM_SYMBOLS + 1 */
  600.            num_names,
  601.            num_terminals,
  602.            num_non_terminals,
  603.            num_rules,
  604.            num_conflict_elements,
  605.            num_single_productions,
  606.            gotodom_size;
  607.  
  608. /******************************************************/
  609. /*  The variables below are used for options setting. */
  610. /******************************************************/
  611. extern BOOLEAN list_bit,
  612.                slr_bit,
  613.                verbose_bit,
  614.                first_bit,
  615.                follow_bit,
  616.                action_bit,
  617.                edit_bit,
  618.                states_bit,
  619.                xref_bit,
  620.                nt_check_bit,
  621.                conflicts_bit,
  622.                read_reduce_bit,
  623.                goto_default_bit,
  624.                shift_default_bit,
  625.                byte_bit,
  626.                warnings_bit,
  627.                single_productions_bit,
  628.                error_maps_bit,
  629.                debug_bit,
  630.                deferred_bit,
  631.                c_bit,
  632.                cpp_bit,
  633.                java_bit,
  634.                scopes_bit;
  635.  
  636. extern int lalr_level,
  637.            default_opt,
  638.            trace_opt,
  639.            table_opt,
  640.            names_opt,
  641.            increment,
  642.            maximum_distance,
  643.            minimum_distance,
  644.            stack_size;
  645.  
  646. extern char escape,
  647.             ormark,
  648.             record_format;
  649.  
  650. extern char blockb[],
  651.             blocke[],
  652.             hblockb[],
  653.             hblocke[],
  654.             errmsg[],
  655.             gettok[],
  656.             smactn[],
  657.             tkactn[];
  658.  
  659. /*********************************************************************/
  660. /*   The variables below are used to hold information about special  */
  661. /* grammar symbols.                                                  */
  662. /*********************************************************************/
  663. extern short accept_image,
  664.              eoft_image,
  665.              eolt_image,
  666.              empty,
  667.              error_image;
  668.  
  669.                        /* Miscellaneous counters. */
  670.  
  671. extern int num_first_sets,
  672.            num_shift_maps,
  673.            page_no;
  674.  
  675. extern long string_offset,
  676.             string_size,
  677.             num_shifts,
  678.             num_shift_reduces,
  679.             num_gotos,
  680.             num_goto_reduces,
  681.             num_reductions,
  682.             num_sr_conflicts,
  683.             num_rr_conflicts,
  684.             num_entries;
  685.  
  686. extern char *string_table;
  687.  
  688. extern short *rhs_sym;
  689.  
  690. extern struct ruletab_type *rules;
  691.  
  692. /***********************************************************************/
  693. /* CLOSURE is a mapping from non-terminal to a set (linked-list) of    */
  694. /* non-terminals.  The set consists of non-terminals that are          */
  695. /* automatically introduced via closure when the original non-terminal */
  696. /* is introduced.                                                      */
  697. /* CL_ITEMS is a mapping from each non-terminal to a set (linked list) */
  698. /* of items which are the first item of the rules generated by the     */
  699. /* non-terminal in question. ADEQUATE_ITEM is a mapping from each rule */
  700. /* to the last (complete) item produced by that rule.                  */
  701. /* ITEM_TABLE is used to map each item into a number. Given that       */
  702. /* number one can retrieve the rule the item belongs to, the position  */
  703. /* of the dot,  the symbol following the dot, and FIRST of the suffix  */
  704. /* following the "dot symbol".                                         */
  705. /***********************************************************************/
  706. extern struct node **closure,
  707.                    **clitems,
  708.                    **adequate_item;
  709.  
  710. extern struct itemtab
  711. {
  712.     short symbol,
  713.           rule_number,
  714.           suffix_index,
  715.           dot;
  716. } *item_table;
  717.  
  718. /***********************************************************************/
  719. /* SYMNO is an array that maps symbol numbers to actual symbols.       */
  720. /***********************************************************************/
  721. extern struct symno_type
  722. {
  723.     int ptr,
  724.         name_index;
  725. } *symno;
  726.  
  727. /***********************************************************************/
  728. /* These variables hold the number of BOOLEAN_CELLS required to form a */
  729. /* set of terminals, non-terminals and states, respectively.           */
  730. /***********************************************************************/
  731. extern int term_set_size,
  732.            non_term_set_size,
  733.            state_set_size;
  734.  
  735. /***********************************************************************/
  736. /* NULL_NT is a boolean vector that indicates whether or not a given   */
  737. /* non-terminal is nullable.                                           */
  738. /***********************************************************************/
  739. extern BOOLEAN *null_nt;
  740.  
  741. /***********************************************************************/
  742. /* FOLLOW is a mapping from non-terminals to a set of terminals that   */
  743. /* may appear immediately after the non-terminal.                      */
  744. /***********************************************************************/
  745. extern SET_PTR nt_first,
  746.                first,
  747.                follow;
  748.  
  749. /***********************************************************************/
  750. /* NAME is an array containing names to be associated with symbols.    */
  751. /* REDUCE is a mapping from each state to reduce actions in that state.*/
  752. /* SHIFT is an array used to hold the complete set of all shift maps   */
  753. /* needed to construct the state automaton. Though its size is         */
  754. /* NUM_STATES, the actual number of elements used in it is indicated   */
  755. /* by the integer NUM_SHIFT_MAPS. NUM_STATES elements were allocated,  */
  756. /* because if the user requests that certain single productions be     */
  757. /* removed, a Shift map containing actions involving such productions  */
  758. /* cannot be shared.                                                   */
  759. /***********************************************************************/
  760. extern struct shift_header_type  *shift;
  761.  
  762. extern struct reduce_header_type *reduce;
  763.  
  764. extern short *gotodef,
  765.              *shiftdf,
  766.              *gd_index,
  767.              *gd_range;
  768.  
  769. extern int *name;
  770.  
  771. /***********************************************************************/
  772. /* STATSET is a mapping from state number to state information.        */
  773. /* LASTATS is a similar mapping for look-ahead states.                 */
  774. /* IN_STAT is a mapping from each state to the set of states that have */
  775. /* a transition into the state in question.                            */
  776. /***********************************************************************/
  777. extern struct statset_type *statset;
  778.  
  779. extern struct lastats_type *lastats;
  780. extern struct node **in_stat;
  781.  
  782. extern int num_scopes,
  783.            scope_rhs_size,
  784.            scope_state_size,
  785.            num_error_rules;
  786.  
  787. extern struct scope_type
  788. {
  789.     short prefix,
  790.           suffix,
  791.           lhs_symbol,
  792.           look_ahead,
  793.           state_set;
  794. } *scope;
  795.  
  796. extern short *scope_right_side,
  797.              *scope_state;
  798.  
  799. /*******************************************************************/
  800. /*******************************************************************/
  801. /**                                                               **/
  802. /**                        OUTPUT DECLARATIONS                    **/
  803. /**                                                               **/
  804. /*******************************************************************/
  805. /*******************************************************************/
  806. /* The following external variables are used only in processing    */
  807. /* output.                                                         */
  808. /*******************************************************************/
  809. extern char *output_ptr,
  810.             *output_buffer;
  811.  
  812. extern short *symbol_map,
  813.              *ordered_state,
  814.              *state_list;
  815.  
  816. extern int *next,
  817.            *previous,
  818.            *state_index;
  819.  
  820. extern long table_size,
  821.             action_size,
  822.             increment_size;
  823.  
  824. extern short last_non_terminal,
  825.              last_terminal;
  826.  
  827. extern int accept_act,
  828.            error_act,
  829.            first_index,
  830.            last_index,
  831.            last_symbol,
  832.            max_name_length;
  833.  
  834. extern SET_PTR naction_symbols,
  835.                action_symbols;
  836.  
  837. extern BOOLEAN byte_terminal_range;
  838.  
  839. #endif /* COMMON_INCLUDED */
  840.