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