home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 342a.lha / Yacc_v1.0a / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-05  |  6.2 KB  |  293 lines

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