home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / develop / yacc.lha / Yacc / src / defs.h < prev    next >
C/C++ Source or Header  |  1993-07-09  |  6KB  |  290 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 Tahoe        */
  8. /*  they might have to be changed for other machines    */
  9.  
  10. /*  MAXCHAR is the largest unsigned 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]|=((unsigned)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 CODE_SUFFIX    ".code.c"
  49. #define    DEFINES_SUFFIX    ".tab.h"
  50. #define    OUTPUT_SUFFIX    ".tab.c"
  51. #define    VERBOSE_SUFFIX    ".output"
  52.  
  53.  
  54. /* keyword codes */
  55.  
  56. #define TOKEN 0
  57. #define LEFT 1
  58. #define RIGHT 2
  59. #define NONASSOC 3
  60. #define MARK 4
  61. #define TEXT 5
  62. #define TYPE 6
  63. #define START 7
  64. #define UNION 8
  65. #define IDENT 9
  66.  
  67.  
  68. /*  symbol classes  */
  69.  
  70. #define UNKNOWN 0
  71. #define TERM 1
  72. #define NONTERM 2
  73.  
  74.  
  75. /*  the undefined value  */
  76.  
  77. #define UNDEFINED (-1)
  78.  
  79.  
  80. /*  action codes  */
  81.  
  82. #define SHIFT 1
  83. #define REDUCE 2
  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 CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
  102. #define    FREE(x)        (free((char*)(x)))
  103. #define MALLOC(n)    (malloc((unsigned)(n)))
  104. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  105. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  106. #define REALLOC(p,n)    (realloc((char*)(p),(unsigned)(n)))
  107.  
  108.  
  109. /*  the structure of a symbol table entry  */
  110.  
  111. typedef struct bucket bucket;
  112. struct bucket
  113. {
  114.     struct bucket *link;
  115.     struct bucket *next;
  116.     char *name;
  117.     char *tag;
  118.     short value;
  119.     short index;
  120.     short prec;
  121.     char class;
  122.     char assoc;
  123. };
  124.  
  125.  
  126. /*  the structure of the LR(0) state machine  */
  127.  
  128. typedef struct core core;
  129. struct core
  130. {
  131.     struct core *next;
  132.     struct core *link;
  133.     short number;
  134.     short accessing_symbol;
  135.     short nitems;
  136.     short items[1];
  137. };
  138.  
  139.  
  140. /*  the structure used to record shifts  */
  141.  
  142. typedef struct shifts shifts;
  143. struct shifts
  144. {
  145.     struct shifts *next;
  146.     short number;
  147.     short nshifts;
  148.     short shift[1];
  149. };
  150.  
  151.  
  152. /*  the structure used to store reductions  */
  153.  
  154. typedef struct reductions reductions;
  155. struct reductions
  156. {
  157.     struct reductions *next;
  158.     short number;
  159.     short nreds;
  160.     short rules[1];
  161. };
  162.  
  163.  
  164. /*  the structure used to represent parser actions  */
  165.  
  166. typedef struct action action;
  167. struct action
  168. {
  169.     struct action *next;
  170.     short symbol;
  171.     short number;
  172.     short prec;
  173.     char action_code;
  174.     char assoc;
  175.     char suppressed;
  176. };
  177.  
  178.  
  179. /* global variables */
  180.  
  181. extern char dflag;
  182. extern char lflag;
  183. extern char rflag;
  184. extern char tflag;
  185. extern char vflag;
  186. extern char *symbol_prefix;
  187.  
  188. extern char *myname;
  189. extern char *cptr;
  190. extern char *line;
  191. extern int lineno;
  192. extern int outline;
  193.  
  194. extern char *banner[];
  195. extern char *tables[];
  196. extern char *header[];
  197. extern char *body[];
  198. extern char *trailer[];
  199.  
  200. extern char *action_file_name;
  201. extern char *code_file_name;
  202. extern char *defines_file_name;
  203. extern char *input_file_name;
  204. extern char *output_file_name;
  205. extern char *text_file_name;
  206. extern char *union_file_name;
  207. extern char *verbose_file_name;
  208.  
  209. extern FILE *action_file;
  210. extern FILE *code_file;
  211. extern FILE *defines_file;
  212. extern FILE *input_file;
  213. extern FILE *output_file;
  214. extern FILE *text_file;
  215. extern FILE *union_file;
  216. extern FILE *verbose_file;
  217.  
  218. extern int nitems;
  219. extern int nrules;
  220. extern int nsyms;
  221. extern int ntokens;
  222. extern int nvars;
  223. extern int ntags;
  224.  
  225. extern char unionized;
  226. extern char line_format[];
  227.  
  228. extern int   start_symbol;
  229. extern char  **symbol_name;
  230. extern short *symbol_value;
  231. extern short *symbol_prec;
  232. extern char  *symbol_assoc;
  233.  
  234. extern short *ritem;
  235. extern short *rlhs;
  236. extern short *rrhs;
  237. extern short *rprec;
  238. extern char  *rassoc;
  239.  
  240. extern short **derives;
  241. extern char *nullable;
  242.  
  243. extern bucket *first_symbol;
  244. extern bucket *last_symbol;
  245.  
  246. extern int nstates;
  247. extern core *first_state;
  248. extern shifts *first_shift;
  249. extern reductions *first_reduction;
  250. extern short *accessing_symbol;
  251. extern core **state_table;
  252. extern shifts **shift_table;
  253. extern reductions **reduction_table;
  254. extern unsigned *LA;
  255. extern short *LAruleno;
  256. extern short *lookaheads;
  257. extern short *goto_map;
  258. extern short *from_state;
  259. extern short *to_state;
  260.  
  261. extern action **parser;
  262. extern int SRtotal;
  263. extern int RRtotal;
  264. extern short *SRconflicts;
  265. extern short *RRconflicts;
  266. extern short *defred;
  267. extern short *rules_used;
  268. extern short nunused;
  269. extern short final_state;
  270.  
  271. /* global functions */
  272.  
  273. extern char *allocate();
  274. extern bucket *lookup();
  275. extern bucket *make_bucket();
  276.  
  277.  
  278. /* system variables */
  279.  
  280. extern int errno;
  281.  
  282.  
  283. /* system functions */
  284.  
  285. extern void free();
  286. extern char *calloc();
  287. extern char *malloc();
  288. extern char *realloc();
  289. extern char *strcpy();
  290.