[BACK]Return to defs.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / yacc

Annotation of src/usr.bin/yacc/defs.h, Revision 1.14

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