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