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