1 /***********************************************************************/
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the Q Public License version 1.0. */
11 /***********************************************************************/
13 /* Based on public-domain code from Berkeley Yacc */
15 /* $Id: defs.h 6244 2004-04-21 23:26:06Z doligez $ */
23 #include "../config/s.h"
25 /* machine-dependent definitions */
26 /* the following definitions are for the Tahoe */
27 /* they might have to be changed for other machines */
29 /* MAXCHAR is the largest unsigned character value */
30 /* MAXSHORT is the largest value of a C short */
31 /* MINSHORT is the most negative value of a C short */
32 /* MAXTABLE is the maximum table size */
33 /* BITS_PER_WORD is the number of bits in a C unsigned */
34 /* WORDSIZE computes the number of words needed to */
36 /* BIT returns the value of the n-th bit starting */
37 /* from r (0-indexed) */
38 /* SETBIT sets the n-th bit starting from r */
40 #define MAXCHAR UCHAR_MAX
41 #define MAXSHORT SHRT_MAX
42 #define MINSHORT SHRT_MIN
43 #define MAXTABLE 32500
45 #define BITS_PER_WORD (8*sizeof(unsigned))
46 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
47 #define BIT(r, n) ((((r)[(n)/BITS_PER_WORD])>>((n)%BITS_PER_WORD))&1)
48 #define SETBIT(r, n) ((r)[(n)/BITS_PER_WORD]|=(1<<((n)%BITS_PER_WORD)))
52 #define NUL '\0' /* the null character */
53 #define NEWLINE '\n' /* line feed */
54 #define SP ' ' /* space */
55 #define BS '\b' /* backspace */
56 #define HT '\t' /* horizontal tab */
57 #define VT '\013' /* vertical tab */
58 #define CR '\r' /* carriage return */
59 #define FF '\f' /* form feed */
60 #define QUOTE '\'' /* single quote */
61 #define DOUBLE_QUOTE '\"' /* double quote */
62 #define BACKSLASH '\\' /* backslash */
65 /* defines for constructing filenames */
67 #define CODE_SUFFIX ".code.c"
68 #define DEFINES_SUFFIX ".tab.h"
69 #define OUTPUT_SUFFIX ".ml"
70 #define VERBOSE_SUFFIX ".output"
71 #define INTERFACE_SUFFIX ".mli"
93 /* the undefined value */
95 #define UNDEFINED (-1)
104 /* character macros */
106 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
107 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
108 #define NUMERIC_VALUE(c) ((c) - '0')
113 #define ISTOKEN(s) ((s) < start_symbol)
114 #define ISVAR(s) ((s) >= start_symbol)
117 /* storage allocation macros */
119 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
120 #define FREE(x) (free((char*)(x)))
121 #define MALLOC(n) (malloc((unsigned)(n)))
122 #define NEW(t) ((t*)allocate(sizeof(t)))
123 #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
124 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
127 /* the structure of a symbol table entry */
129 typedef struct bucket bucket;
145 /* TABLE_SIZE is the number of entries in the symbol table. */
146 /* TABLE_SIZE must be a power of two. */
148 #define TABLE_SIZE 4096
150 /* the structure of the LR(0) state machine */
152 typedef struct core core;
158 short accessing_symbol;
164 /* the structure used to record shifts */
166 typedef struct shifts shifts;
176 /* the structure used to store reductions */
178 typedef struct reductions reductions;
181 struct reductions *next;
188 /* the structure used to represent parser actions */
190 typedef struct action action;
203 /* global variables */
212 extern char big_endian;
218 extern char *virtual_input_file_name;
221 extern char *action_file_name;
222 extern char *entry_file_name;
223 extern char *code_file_name;
224 extern char *defines_file_name;
225 extern char *input_file_name;
226 extern char *output_file_name;
227 extern char *text_file_name;
228 extern char *union_file_name;
229 extern char *verbose_file_name;
230 extern char *interface_file_name;
232 extern FILE *action_file;
233 extern FILE *entry_file;
234 extern FILE *code_file;
235 extern FILE *defines_file;
236 extern FILE *input_file;
237 extern FILE *output_file;
238 extern FILE *text_file;
239 extern FILE *union_file;
240 extern FILE *verbose_file;
241 extern FILE *interface_file;
245 extern int ntotalrules;
251 extern char unionized;
252 extern char line_format[];
254 extern int start_symbol;
255 extern char **symbol_name;
256 extern short *symbol_value;
257 extern short *symbol_prec;
258 extern char *symbol_assoc;
259 extern char **symbol_tag;
260 extern char *symbol_true_token;
268 extern short **derives;
269 extern char *nullable;
271 extern bucket *first_symbol;
272 extern bucket *last_symbol;
275 extern core *first_state;
276 extern shifts *first_shift;
277 extern reductions *first_reduction;
278 extern short *accessing_symbol;
279 extern core **state_table;
280 extern shifts **shift_table;
281 extern reductions **reduction_table;
283 extern short *LAruleno;
284 extern short *lookaheads;
285 extern short *goto_map;
286 extern short *from_state;
287 extern short *to_state;
289 extern action **parser;
292 extern short *SRconflicts;
293 extern short *RRconflicts;
294 extern short *defred;
295 extern short *rules_used;
296 extern short nunused;
297 extern short final_state;
299 /* global functions */
302 /* Works only in GCC 2.5 and later */
303 #define Noreturn __attribute ((noreturn))
308 extern char *allocate(unsigned int n);
309 extern bucket *lookup(char *name);
310 extern bucket *make_bucket(char *name);
311 extern action *parse_actions(register int stateno);
312 extern action *get_shifts(int stateno);
313 extern action *add_reductions(int stateno, register action *actions);
314 extern action *add_reduce(register action *actions, register int ruleno, register int symbol);
315 extern void closure (short int *nucleus, int n);
316 extern void create_symbol_table (void);
317 extern void default_action_error (void);
318 extern void done (int k) Noreturn;
319 extern void entry_without_type (char *s);
320 extern void fatal (char *msg);
321 extern void finalize_closure (void);
322 extern void free_parser (void);
323 extern void free_symbol_table (void);
324 extern void free_symbols (void);
325 extern void illegal_character (char *c_cptr);
326 extern void illegal_token_ref (int i, char *name);
327 extern void lalr (void);
328 extern void lr0 (void);
329 extern void make_parser (void);
330 extern void no_grammar (void);
331 extern void no_space (void);
332 extern void open_error (char *filename);
333 extern void output (void);
334 extern void over_unionized (char *u_cptr);
335 extern void prec_redeclared (void);
336 extern void polymorphic_entry_point(char *s);
337 extern void reader (void);
338 extern void reflexive_transitive_closure (unsigned int *R, int n);
339 extern void reprec_warning (char *s);
340 extern void retyped_warning (char *s);
341 extern void revalued_warning (char *s);
342 extern void set_first_derives (void);
343 extern void syntax_error (int st_lineno, char *st_line, char *st_cptr) Noreturn, terminal_lhs (int s_lineno);
344 extern void terminal_start (char *s);
345 extern void tokenized_start (char *s);
346 extern void too_many_entries (void);
347 extern void undefined_goal (char *s);
348 extern void undefined_symbol (char *s);
349 extern void unexpected_EOF (void);
350 extern void unknown_rhs (int i);
351 extern void unterminated_action (int a_lineno, char *a_line, char *a_cptr);
352 extern void unterminated_comment (int c_lineno, char *c_line, char *c_cptr);
353 extern void unterminated_string (int s_lineno, char *s_line, char *s_cptr);
354 extern void unterminated_text (int t_lineno, char *t_line, char *t_cptr);
355 extern void unterminated_union (int u_lineno, char *u_line, char *u_cptr);
356 extern void used_reserved (char *s);
357 extern void verbose (void);
358 extern void write_section (char **section);