/usr.bin/yacc/defs.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 348 lines · 224 code · 64 blank · 60 comment · 7 complexity · dd19888a394bd823f12ef3cbf087ba8f MD5 · raw file

  1. /*
  2. * Copyright (c) 1989 The Regents of the University of California.
  3. * All rights reserved.
  4. *
  5. * This code is derived from software contributed to Berkeley by
  6. * Robert Paul Corbett.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 4. Neither the name of the University nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * @(#)defs.h 5.6 (Berkeley) 5/24/93
  33. * $FreeBSD$
  34. */
  35. #include <assert.h>
  36. #include <ctype.h>
  37. #include <err.h>
  38. #include <stdio.h>
  39. /* machine-dependent definitions */
  40. /* the following definitions are for the Tahoe */
  41. /* they might have to be changed for other machines */
  42. /* MAXTABLE is the maximum table size */
  43. /* BITS_PER_WORD is the number of bits in a C unsigned */
  44. /* WORDSIZE computes the number of words needed to */
  45. /* store n bits */
  46. /* BIT returns the value of the n-th bit starting */
  47. /* from r (0-indexed) */
  48. /* SETBIT sets the n-th bit starting from r */
  49. #define MAXTABLE 32500
  50. #define BITS_PER_WORD 32
  51. #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  52. #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
  53. #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
  54. /* character names */
  55. #define NUL '\0' /* the null character */
  56. #define NEWLINE '\n' /* line feed */
  57. #define SP ' ' /* space */
  58. #define BS '\b' /* backspace */
  59. #define HT '\t' /* horizontal tab */
  60. #define VT '\013' /* vertical tab */
  61. #define CR '\r' /* carriage return */
  62. #define FF '\f' /* form feed */
  63. #define QUOTE '\'' /* single quote */
  64. #define DOUBLE_QUOTE '\"' /* double quote */
  65. #define BACKSLASH '\\' /* backslash */
  66. /* defines for constructing filenames */
  67. #define CODE_SUFFIX ".code.c"
  68. #define DEFINES_SUFFIX ".tab.h"
  69. #define OUTPUT_SUFFIX ".tab.c"
  70. #define VERBOSE_SUFFIX ".output"
  71. /* keyword codes */
  72. #define TOKEN 0
  73. #define LEFT 1
  74. #define RIGHT 2
  75. #define NONASSOC 3
  76. #define MARK 4
  77. #define TEXT 5
  78. #define TYPE 6
  79. #define START 7
  80. #define UNION 8
  81. #define IDENT 9
  82. #define EXPECT 10
  83. /* symbol classes */
  84. #define UNKNOWN 0
  85. #define TERM 1
  86. #define NONTERM 2
  87. /* the undefined value */
  88. #define UNDEFINED (-1)
  89. /* action codes */
  90. #define SHIFT 1
  91. #define REDUCE 2
  92. /* character macros */
  93. #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  94. #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
  95. #define NUMERIC_VALUE(c) ((c) - '0')
  96. /* symbol macros */
  97. #define ISTOKEN(s) ((s) < start_symbol)
  98. #define ISVAR(s) ((s) >= start_symbol)
  99. /* storage allocation macros */
  100. #define NEW(t) ((t*)allocate(sizeof(t)))
  101. #define NEW2(n,t) ((t*)allocate((n)*sizeof(t)))
  102. /* the structure of a symbol table entry */
  103. typedef struct bucket bucket;
  104. struct bucket
  105. {
  106. struct bucket *link;
  107. struct bucket *next;
  108. char *name;
  109. char *tag;
  110. short value;
  111. short index;
  112. short prec;
  113. char class;
  114. char assoc;
  115. };
  116. /* the structure of the LR(0) state machine */
  117. typedef struct core core;
  118. struct core
  119. {
  120. struct core *next;
  121. struct core *link;
  122. short number;
  123. short accessing_symbol;
  124. short nitems;
  125. short items[1];
  126. };
  127. /* the structure used to record shifts */
  128. typedef struct shifts shifts;
  129. struct shifts
  130. {
  131. struct shifts *next;
  132. short number;
  133. short nshifts;
  134. short shift[1];
  135. };
  136. /* the structure used to store reductions */
  137. typedef struct reductions reductions;
  138. struct reductions
  139. {
  140. struct reductions *next;
  141. short number;
  142. short nreds;
  143. short rules[1];
  144. };
  145. /* the structure used to represent parser actions */
  146. typedef struct action action;
  147. struct action
  148. {
  149. struct action *next;
  150. short symbol;
  151. short number;
  152. short prec;
  153. char action_code;
  154. char assoc;
  155. char suppressed;
  156. };
  157. /* global variables */
  158. extern char dflag;
  159. extern char lflag;
  160. extern char rflag;
  161. extern char tflag;
  162. extern char vflag;
  163. extern const char *symbol_prefix;
  164. extern char *cptr;
  165. extern char *line;
  166. extern int lineno;
  167. extern int outline;
  168. extern const char *banner[];
  169. extern const char *tables[];
  170. extern const char *header[];
  171. extern const char *body[];
  172. extern const char *trailer[];
  173. extern char *action_file_name;
  174. extern char *code_file_name;
  175. extern char *defines_file_name;
  176. extern const char *input_file_name;
  177. extern char *output_file_name;
  178. extern char *text_file_name;
  179. extern char *union_file_name;
  180. extern char *verbose_file_name;
  181. extern FILE *action_file;
  182. extern FILE *code_file;
  183. extern FILE *defines_file;
  184. extern FILE *input_file;
  185. extern FILE *output_file;
  186. extern FILE *text_file;
  187. extern FILE *union_file;
  188. extern FILE *verbose_file;
  189. extern int nitems;
  190. extern int nrules;
  191. extern int nsyms;
  192. extern int ntokens;
  193. extern int nvars;
  194. extern int ntags;
  195. extern char unionized;
  196. extern int start_symbol;
  197. extern char **symbol_name;
  198. extern short *symbol_value;
  199. extern short *symbol_prec;
  200. extern char *symbol_assoc;
  201. extern short *ritem;
  202. extern short *rlhs;
  203. extern short *rrhs;
  204. extern short *rprec;
  205. extern char *rassoc;
  206. extern short **derives;
  207. extern char *nullable;
  208. extern bucket *first_symbol;
  209. extern bucket *last_symbol;
  210. extern int nstates;
  211. extern core *first_state;
  212. extern shifts *first_shift;
  213. extern reductions *first_reduction;
  214. extern short *accessing_symbol;
  215. extern core **state_table;
  216. extern shifts **shift_table;
  217. extern reductions **reduction_table;
  218. extern unsigned *LA;
  219. extern short *LAruleno;
  220. extern short *lookaheads;
  221. extern short *goto_map;
  222. extern short *from_state;
  223. extern short *to_state;
  224. extern action **parser;
  225. extern int SRexpect;
  226. extern int SRtotal;
  227. extern int RRtotal;
  228. extern short *SRconflicts;
  229. extern short *RRconflicts;
  230. extern short *defred;
  231. extern short *rules_used;
  232. extern short nunused;
  233. extern short final_state;
  234. /* global functions */
  235. void *allocate(size_t);
  236. void closure(short *, int);
  237. void create_symbol_table(void);
  238. void default_action_warning(void);
  239. void dollar_error(int, char *, char *) __dead2;
  240. void dollar_warning(int, int);
  241. void done(int) __dead2;
  242. void fatal(const char *msg) __dead2;
  243. void finalize_closure(void);
  244. void free_parser(void);
  245. void free_symbols(void);
  246. void free_symbol_table(void);
  247. void illegal_character(char *) __dead2;
  248. void illegal_tag(int, char *, char *) __dead2;
  249. void lalr(void);
  250. bucket *lookup(char *);
  251. void lr0(void);
  252. bucket *make_bucket(const char *);
  253. void make_parser(void);
  254. void no_grammar(void) __dead2;
  255. void no_space(void) __dead2;
  256. void open_error(const char *) __dead2;
  257. void output(void);
  258. void over_unionized(char *) __dead2;
  259. void prec_redeclared(void);
  260. void reader(void);
  261. void reflexive_transitive_closure(unsigned *, int);
  262. void reprec_warning(char *);
  263. void restarted_warning(void);
  264. void retyped_warning(char *);
  265. void revalued_warning(char *);
  266. void set_first_derives(void);
  267. void syntax_error(int, char *, char *) __dead2;
  268. void terminal_lhs(int) __dead2;
  269. void terminal_start(char *) __dead2;
  270. void tokenized_start(char *) __dead2;
  271. void undefined_goal(char *) __dead2;
  272. void undefined_symbol_warning(char *);
  273. void unexpected_EOF(void) __dead2;
  274. void unknown_rhs(int) __dead2;
  275. void unterminated_action(int, char *, char *) __dead2;
  276. void unterminated_comment(int, char *, char *) __dead2;
  277. void unterminated_string(int, char *, char *) __dead2;
  278. void unterminated_text(int, char *, char *) __dead2;
  279. void unterminated_union(int, char *, char *) __dead2;
  280. void untyped_lhs(void) __dead2;
  281. void untyped_rhs(int, char *) __dead2;
  282. void used_reserved(char *) __dead2;
  283. void verbose(void);
  284. void write_section(const char **);