hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

dextern (7660B)


      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 /* Copyright (c) 1988 AT&T */
     28 /* All Rights Reserved */
     29 
     30 /*	from OpenSolaris "dextern	6.17	05/06/08 SMI"	*/
     31 
     32 /*
     33  * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
     34  *
     35  * Sccsid @(#)dextern	1.6 (gritter) 11/10/05
     36  */
     37 
     38 #include <stdio.h>
     39 #include <ctype.h>
     40 #include <string.h>
     41 #include <stdlib.h>
     42 #include <wctype.h>
     43 
     44 	/*  MANIFEST CONSTANT DEFINITIONS */
     45 #define	WORD32
     46 
     47 	/* base of nonterminal internal numbers */
     48 
     49 #define	NTBASE (10000000)
     50 
     51 	/* internal codes for error and accept actions */
     52 
     53 #define	ERRCODE  8190
     54 #define	ACCEPTCODE 8191
     55 
     56 	/* sizes and limits */
     57 
     58 #define	ACTSIZE 4000
     59 #define	MEMSIZE 2000
     60 #define	PSTSIZE 1024
     61 #define	NSTATES 1000
     62 #define	NTERMS 127
     63 #define	NPROD 300
     64 #define	NNONTERM 600
     65 #define	TEMPSIZE 800
     66 #define	CNAMSZ 1000
     67 #define	LSETSIZE 950
     68 #define	WSETSIZE 850
     69 
     70 #define	NAMESIZE 50
     71 #define	NTYPES 1000
     72 
     73 #define	NMBCHARSZ 100
     74 #define	LKFACTOR 5
     75 
     76 #ifdef WORD32
     77 	/* bit packing macros (may be machine dependent) */
     78 #define	BIT(a, i) ((a)[(i)>>5] & (1<<((i)&037)))
     79 #define	SETBIT(a, i) ((a)[(i)>>5] |= (1<<((i)&037)))
     80 
     81 	/* number of words needed to hold n+1 bits */
     82 #define	NWORDS(n) (((n)+32)/32)
     83 
     84 #else
     85 
     86 	/* bit packing macros (may be machine dependent) */
     87 #define	BIT(a, i) ((a)[(i)>>4] & (1<<((i)&017)))
     88 #define	SETBIT(a, i) ((a)[(i)>>4] |= (1<<((i)&017)))
     89 
     90 	/* number of words needed to hold n+1 bits */
     91 #define	NWORDS(n) (((n)+16)/16)
     92 #endif
     93 
     94 	/*
     95 	 * relationships which must hold:
     96 	 * TBITSET ints must hold NTERMS+1 bits...
     97 	 * WSETSIZE >= NNONTERM
     98 	 * LSETSIZE >= NNONTERM
     99 	 * TEMPSIZE >= NTERMS + NNONTERMs + 1
    100 	 * TEMPSIZE >= NSTATES
    101 	 */
    102 
    103 	/* associativities */
    104 
    105 #define	NOASC 0  /* no assoc. */
    106 #define	LASC 1  /* left assoc. */
    107 #define	RASC 2  /* right assoc. */
    108 #define	BASC 3  /* binary assoc. */
    109 
    110 	/* flags for state generation */
    111 
    112 #define	DONE 0
    113 #define	MUSTDO 1
    114 #define	MUSTLOOKAHEAD 2
    115 
    116 	/* flags for a rule having an action, and being reduced */
    117 
    118 #define	ACTFLAG 04
    119 #define	REDFLAG 010
    120 
    121 	/* output parser flags */
    122 #define	YYFLAG1 (-10000000)
    123 
    124 	/* macros for getting associativity and precedence levels */
    125 
    126 #define	ASSOC(i) ((i)&07)
    127 #define	PLEVEL(i) (((i)>>4)&077)
    128 #define	TYPE(i)  ((i>>10)&077)
    129 
    130 	/* macros for setting associativity and precedence levels */
    131 
    132 #define	SETASC(i, j) i |= j
    133 #define	SETPLEV(i, j) i |= (j<<4)
    134 #define	SETTYPE(i, j) i |= (j<<10)
    135 
    136 	/* looping macros */
    137 
    138 #define	TLOOP(i) for (i = 1; i <= ntokens; ++i)
    139 #define	NTLOOP(i) for (i = 0; i <= nnonter; ++i)
    140 #define	PLOOP(s, i) for (i = s; i < nprod; ++i)
    141 #define	SLOOP(i) for (i = 0; i < nstate; ++i)
    142 #define	WSBUMP(x) ++x
    143 #define	WSLOOP(s, j) for (j = s; j < &wsets[cwp]; ++j)
    144 #define	ITMLOOP(i, p, q) q = pstate[i+1]; for (p = pstate[i]; p < q; ++p)
    145 #define	SETLOOP(i) for (i = 0; i < tbitset; ++i)
    146 
    147 	/* I/O descriptors */
    148 
    149 extern FILE * finput;		/* input file */
    150 extern FILE * faction;		/* file for saving actions */
    151 extern FILE * fdefine;		/* file for #defines */
    152 extern FILE * ftable;		/* y.tab.c file */
    153 extern FILE * ftemp;		/* tempfile to pass 2 */
    154 extern FILE * fdebug;		/* tempfile for two debugging info arrays */
    155 extern FILE * foutput;		/* y.output file */
    156 
    157 	/* structure declarations */
    158 
    159 typedef struct looksets {
    160 	int *lset;
    161 } LOOKSETS;
    162 
    163 typedef struct item {
    164 	int *pitem;
    165 	LOOKSETS *look;
    166 } ITEM;
    167 
    168 typedef struct toksymb {
    169 	wchar_t *name;
    170 	int value;
    171 } TOKSYMB;
    172 
    173 typedef struct mbclit {
    174 	wchar_t character;
    175 	int tvalue; /* token issued for the character */
    176 } MBCLIT;
    177 
    178 typedef struct ntsymb {
    179 	wchar_t *name;
    180 	int tvalue;
    181 } NTSYMB;
    182 
    183 typedef struct wset {
    184 	int *pitem;
    185 	int flag;
    186 	LOOKSETS ws;
    187 } WSET;
    188 
    189 	/* token information */
    190 
    191 extern int ntokens;	/* number of tokens */
    192 extern TOKSYMB *tokset;
    193 extern int ntoksz;
    194 
    195 	/*
    196 	 * multibyte (c > 255) character literals are
    197 	 * handled as though they were tokens except
    198 	 * that it generates a separate mapping table.
    199 	 */
    200 extern int nmbchars;	/* number of mb literals */
    201 extern MBCLIT *mbchars;
    202 extern int nmbcharsz;
    203 
    204 	/* nonterminal information */
    205 
    206 extern int nnonter;	/* the number of nonterminals */
    207 extern NTSYMB *nontrst;
    208 extern int nnontersz;
    209 
    210 	/* grammar rule information */
    211 
    212 extern int nprod;	/* number of productions */
    213 extern int **prdptr;	/* pointers to descriptions of productions */
    214 extern int *levprd;	/* contains production levels to break conflicts */
    215 extern wchar_t *had_act; /* set if reduction has associated action code */
    216 
    217 	/* state information */
    218 
    219 extern int nstate;		/* number of states */
    220 extern ITEM **pstate;	/* pointers to the descriptions of the states */
    221 extern int *tystate;	/* contains type information about the states */
    222 extern int *defact;	/* the default action of the state */
    223 
    224 extern int size;
    225 
    226 	/* lookahead set information */
    227 
    228 extern int TBITSET;
    229 extern LOOKSETS *lkst;
    230 extern int nolook;  /* flag to turn off lookahead computations */
    231 
    232 	/* working set information */
    233 
    234 extern WSET *wsets;
    235 
    236 	/* storage for productions */
    237 
    238 extern int *mem0;
    239 extern int *mem;
    240 extern int *tracemem;
    241 extern int new_memsize;
    242 
    243 	/* storage for action table */
    244 
    245 extern int *amem;
    246 extern int *memp;		/* next free action table position */
    247 extern int *indgo;		/* index to the stored goto table */
    248 extern int new_actsize;
    249 
    250 	/* temporary vector, indexable by states, terms, or ntokens */
    251 
    252 extern int *temp1;
    253 extern int lineno; /* current line number */
    254 
    255 	/* statistics collection variables */
    256 
    257 extern int zzgoent;
    258 extern int zzgobest;
    259 extern int zzacent;
    260 extern int zzexcp;
    261 extern int zzrrconf;
    262 extern int zzsrconf;
    263 
    264 	/* define external functions */
    265 
    266 extern void setup(int, char * []);
    267 extern void closure(int);
    268 extern void output(void);
    269 extern void aryfil(int *, int, int);
    270 extern void error(char *, ...);
    271 extern void warning(int, char *, ...);
    272 extern void putitem(int *, LOOKSETS *);
    273 extern void go2out(void);
    274 extern void hideprod(void);
    275 extern void callopt(void);
    276 extern void warray(wchar_t *, int *, int);
    277 extern wchar_t *symnam(int);
    278 extern wchar_t *writem(int *);
    279 extern void exp_mem(int);
    280 extern void exp_act(int **);
    281 extern int apack(int *, int);
    282 extern int state(int);
    283 extern void fprintf3(FILE *, const char *, const wchar_t *, const char *, ...);
    284 extern void error3(const char *, const wchar_t *, const char *, ...);
    285 
    286 	/* multibyte i/o */
    287 
    288 #undef	getwc
    289 #define	getwc(f)	yacc_getwc(f)
    290 extern wint_t yacc_getwc(FILE *);
    291 #undef	putwc
    292 #define	putwc(c, f)	yacc_putwc(c, f)
    293 extern wint_t yacc_putwc(wchar_t, FILE *);
    294 
    295 	/* yaccpar location */
    296 
    297 extern char *parser;
    298 
    299 	/* default settings for a number of macros */
    300 
    301 	/* name of yacc tempfiles */
    302 
    303 #ifndef TEMPNAME
    304 #define	TEMPNAME "yacc.tmp"
    305 #endif
    306 
    307 #ifndef ACTNAME
    308 #define	ACTNAME "yacc.acts"
    309 #endif
    310 
    311 #ifndef DEBUGNAME
    312 #define	DEBUGNAME "yacc.debug"
    313 #endif
    314 
    315 	/* command to clobber tempfiles after use */
    316 
    317 #ifndef ZAPFILE
    318 #define	ZAPFILE(x) unlink(x)
    319 #endif