home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / BYACC.ZIP / RCS / DEFS.H_V < prev    next >
Text File  |  1992-06-10  |  6KB  |  310 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks; strict;
  5. comment    @ * @;
  6.  
  7.  
  8. 1.1
  9. date    92.06.10.21.55.08;    author downey;    state Exp;
  10. branches;
  11. next    ;
  12.  
  13.  
  14. desc
  15. @
  16. @
  17.  
  18.  
  19. 1.1
  20. log
  21. @Initial revision
  22. @
  23. text
  24. @#include <assert.h>
  25. #include <ctype.h>
  26. #include <stdio.h>
  27.  
  28.  
  29. /*  machine dependent definitions            */
  30. /*  the following definitions are for the VAX        */
  31. /*  they might have to be changed for other machines    */
  32.  
  33. /*  MAXCHAR is the largest character value        */
  34. /*  MAXSHORT is the largest value of a C short        */
  35. /*  MINSHORT is the most negative value of a C short    */
  36. /*  MAXTABLE is the maximum table size            */
  37. /*  BITS_PER_WORD is the number of bits in a C unsigned    */
  38. /*  WORDSIZE computes the number of words needed to    */
  39. /*    store n bits                    */
  40. /*  ROWSIZE computes the number of chars needed to    */
  41. /*    store enough words to represent n bits        */
  42. /*  BIT returns the value of the n-th bit starting    */
  43. /*    from r (0-indexed)                */
  44. /*  SETBIT sets the n-th bit starting from r        */
  45.  
  46. #define    MAXCHAR        255
  47. #define    MAXSHORT    32767
  48. #define MINSHORT    -32768
  49. #define MAXTABLE    32500
  50. #define BITS_PER_WORD    32
  51. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  52. #define    ROWSIZE(n)    (sizeof(unsigned)*WORDSIZE(n))
  53. #define    BIT(r, n)    ((((r)[(n) >> 5]) >> ((n) & 31)) & 1)
  54. #define    SETBIT(r, n)    ((r)[(n) >> 5] |= (1 << ((n) & 31)))
  55.  
  56.  
  57. /*  character names  */
  58.  
  59. #define    NUL        '\0'    /*  the null character  */
  60. #define    NEWLINE        '\n'    /*  line feed  */
  61. #define    SP        ' '     /*  space  */
  62. #define    BS        '\b'    /*  backspace  */
  63. #define    HT        '\t'    /*  horizontal tab  */
  64. #define    VT        '\013'  /*  vertical tab  */
  65. #define    CR        '\r'    /*  carriage return  */
  66. #define    FF        '\f'    /*  form feed  */
  67. #define    QUOTE        '\''    /*  single quote  */
  68. #define    DOUBLE_QUOTE    '\"'    /*  double quote  */
  69. #define    BACKSLASH    '\\'    /*  backslash  */
  70.  
  71.  
  72. /* defines for constructing filenames */
  73.  
  74. #define    DEFINES_SUFFIX    ".tab.h"
  75. #define    OUTPUT_SUFFIX    ".tab.c"
  76. #define    VERBOSE_SUFFIX    ".output"
  77.  
  78.  
  79. /* keyword codes */
  80.  
  81. #define TOKEN 0
  82. #define LEFT 1
  83. #define RIGHT 2
  84. #define NONASSOC 3
  85. #define MARK 4
  86. #define TEXT 5
  87. #define TYPE 6
  88. #define START 7
  89. #define UNION 8
  90. #define IDENT 9
  91.  
  92.  
  93. /*  symbol classes  */
  94.  
  95. #define UNKNOWN 0
  96. #define TERM 1
  97. #define NONTERM 2
  98.  
  99.  
  100. /*  the undefined value  */
  101.  
  102. #define UNDEFINED (-1)
  103.  
  104.  
  105. /*  action codes  */
  106.  
  107. #define SHIFT 1
  108. #define REDUCE 2
  109. #define ERROR 3
  110.  
  111.  
  112. /*  character macros  */
  113.  
  114. #define IS_IDENT(c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  115. #define    IS_OCTAL(c)    ((c) >= '0' && (c) <= '7')
  116. #define    NUMERIC_VALUE(c)    ((c) - '0')
  117.  
  118.  
  119. /*  symbol macros  */
  120.  
  121. #define ISTOKEN(s)    ((s) < start_symbol)
  122. #define ISVAR(s)    ((s) >= start_symbol)
  123.  
  124.  
  125. /*  storage allocation macros  */
  126.  
  127. #define CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
  128. #define    FREE(x)        (free((char*)(x)))
  129. #define MALLOC(n)    (malloc((unsigned)(n)))
  130. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  131. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  132. #define REALLOC(p,n)    (realloc((char*)(p),(unsigned)(n)))
  133.  
  134.  
  135. /*  the structure of a symbol table entry  */
  136.  
  137. typedef struct bucket bucket;
  138. struct bucket
  139. {
  140.     struct bucket *link;
  141.     struct bucket *next;
  142.     char *name;
  143.     char *tag;
  144.     short value;
  145.     short index;
  146.     short prec;
  147.     char class;
  148.     char assoc;
  149. };
  150.  
  151.  
  152. /*  the structure of the LR(0) state machine  */
  153.  
  154. typedef struct core core;
  155. struct core
  156. {
  157.     struct core *next;
  158.     struct core *link;
  159.     short number;
  160.     short accessing_symbol;
  161.     short nitems;
  162.     short items[1];
  163. };
  164.  
  165.  
  166. /*  the structure used to record shifts  */
  167.  
  168. typedef struct shifts shifts;
  169. struct shifts
  170. {
  171.     struct shifts *next;
  172.     short number;
  173.     short nshifts;
  174.     short shifts[1];
  175. };
  176.  
  177.  
  178. /*  the structure used to store reductions  */
  179.  
  180. typedef struct reductions reductions;
  181. struct reductions
  182. {
  183.     struct reductions *next;
  184.     short number;
  185.     short nreds;
  186.     short rules[1];
  187. };
  188.  
  189.  
  190. /*  the structure used to represent parser actions  */
  191.  
  192. typedef struct action action;
  193. struct action
  194. {
  195.     struct action *next;
  196.     short symbol;
  197.     short number;
  198.     short prec;
  199.     char action_code;
  200.     char assoc;
  201.     char suppressed;
  202. };
  203.  
  204.  
  205. /* global variables */
  206.  
  207. extern char dflag;
  208. extern char lflag;
  209. extern char tflag;
  210. extern char vflag;
  211.  
  212. extern char *myname;
  213. extern char *cptr;
  214. extern char *line;
  215. extern int lineno;
  216. extern int outline;
  217.  
  218. extern char *banner[];
  219. extern char *header[];
  220. extern char *body[];
  221. extern char *trailer[];
  222.  
  223. extern char *action_file_name;
  224. extern char *defines_file_name;
  225. extern char *input_file_name;
  226. extern char *output_file_name;
  227. extern char *text_file_name;
  228. extern char *union_file_name;
  229. extern char *verbose_file_name;
  230.  
  231. extern FILE *action_file;
  232. extern FILE *defines_file;
  233. extern FILE *input_file;
  234. extern FILE *output_file;
  235. extern FILE *text_file;
  236. extern FILE *union_file;
  237. extern FILE *verbose_file;
  238.  
  239. extern int nitems;
  240. extern int nrules;
  241. extern int nsyms;
  242. extern int ntokens;
  243. extern int nvars;
  244.  
  245. extern char unionized;
  246. extern char line_format[];
  247.  
  248. extern int   start_symbol;
  249. extern char  **symbol_name;
  250. extern short *symbol_value;
  251. extern short *symbol_prec;
  252. extern char  *symbol_assoc;
  253.  
  254. extern short *ritem;
  255. extern short *rlhs;
  256. extern short *rrhs;
  257. extern short *rprec;
  258. extern char  *rassoc;
  259.  
  260. extern short **derives;
  261. extern char *nullable;
  262.  
  263. extern bucket *first_symbol;
  264.  
  265. extern int nstates;
  266. extern core *first_state;
  267. extern shifts *first_shift;
  268. extern reductions *first_reduction;
  269. extern short *accessing_symbol;
  270. extern core **state_table;
  271. extern shifts **shift_table;
  272. extern reductions **reduction_table;
  273. extern unsigned *LA;
  274. extern short *LAruleno;
  275. extern short *lookaheads;
  276. extern short *goto_map;
  277. extern short *from_state;
  278. extern short *to_state;
  279.  
  280. extern action **parser;
  281. extern int SRtotal;
  282. extern int RRtotal;
  283. extern short *SRconflicts;
  284. extern short *RRconflicts;
  285. extern short *defred;
  286. extern short *rules_used;
  287. extern short nunused;
  288. extern short final_state;
  289.  
  290. /* global functions */
  291.  
  292. extern char *allocate();
  293. extern bucket *lookup();
  294. extern bucket *make_bucket();
  295.  
  296.  
  297. /* system variables */
  298.  
  299. extern int errno;
  300.  
  301.  
  302. /* system functions */
  303.  
  304. extern void free();
  305. extern char *calloc();
  306. extern char *malloc();
  307. extern char *realloc();
  308. extern char *strcpy();
  309. @
  310.