home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / BYACC.ZIP / DEFS.H < prev    next >
C/C++ Source or Header  |  1992-03-16  |  6KB  |  286 lines

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