hbase

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

yaccpar (12957B)


      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 "yaccpar	6.18	05/06/08 SMI"	*/
     31 
     32 /*
     33  * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
     34  *
     35  * Sccsid @(#)yaccpar	1.5 (gritter) 11/26/05
     36  */
     37 
     38 /*
     39 ** Skeleton parser driver for yacc output
     40 */
     41 
     42 /*
     43 ** yacc user known macros and defines
     44 */
     45 #define YYERROR		goto yyerrlab
     46 #define YYACCEPT	return(0)
     47 #define YYABORT		return(1)
     48 #define YYBACKUP( newtoken, newvalue )\
     49 {\
     50 	if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
     51 	{\
     52 		yyerror( "syntax error - cannot backup" );\
     53 		goto yyerrlab;\
     54 	}\
     55 	yychar = newtoken;\
     56 	yystate = *yyps;\
     57 	yylval = newvalue;\
     58 	goto yynewstate;\
     59 }
     60 #define YYRECOVERING()	(!!yyerrflag)
     61 #define YYNEW(type)	malloc(sizeof(type) * yynewmax)
     62 #define YYCOPY(to, from, type) \
     63 	(type *) memcpy(to, (char *) from, yymaxdepth * sizeof (type))
     64 #define YYENLARGE( from, type) \
     65 	(type *) realloc((char *) from, yynewmax * sizeof(type))
     66 #ifndef YYDEBUG
     67 #	define YYDEBUG	1	/* make debugging available */
     68 #endif
     69 
     70 /*
     71 ** user known globals
     72 */
     73 int yydebug;			/* set to 1 to get debugging */
     74 
     75 /*
     76 ** driver internal defines
     77 */
     78 #define YYFLAG		(-10000000)
     79 
     80 /*
     81 ** global variables used by the parser
     82 */
     83 YYSTYPE *yypv;			/* top of value stack */
     84 int *yyps;			/* top of state stack */
     85 
     86 int yystate;			/* current state */
     87 int yytmp;			/* extra var (lasts between blocks) */
     88 
     89 int yynerrs;			/* number of errors */
     90 int yyerrflag;			/* error recovery flag */
     91 int yychar;			/* current input token number */
     92 
     93 
     94 
     95 #ifdef YYNMBCHARS
     96 #define YYLEX()		yycvtok(yylex())
     97 /*
     98 ** yycvtok - return a token if i is a wchar_t value that exceeds 255.
     99 **	If i<255, i itself is the token.  If i>255 but the neither 
    100 **	of the 30th or 31st bit is on, i is already a token.
    101 */
    102 #if defined(__STDC__) || defined(__cplusplus)
    103 int yycvtok(int i)
    104 #else
    105 int yycvtok(i) int i;
    106 #endif
    107 {
    108 	int first = 0;
    109 	int last = YYNMBCHARS - 1;
    110 	int mid;
    111 	wchar_t j;
    112 
    113 	if(i&0x60000000){/*Must convert to a token. */
    114 		if( yymbchars[last].character < i ){
    115 			return i;/*Giving up*/
    116 		}
    117 		while ((last>=first)&&(first>=0)) {/*Binary search loop*/
    118 			mid = (first+last)/2;
    119 			j = yymbchars[mid].character;
    120 			if( j==i ){/*Found*/ 
    121 				return yymbchars[mid].tvalue;
    122 			}else if( j<i ){
    123 				first = mid + 1;
    124 			}else{
    125 				last = mid -1;
    126 			}
    127 		}
    128 		/*No entry in the table.*/
    129 		return i;/* Giving up.*/
    130 	}else{/* i is already a token. */
    131 		return i;
    132 	}
    133 }
    134 #else/*!YYNMBCHARS*/
    135 #define YYLEX()		yylex()
    136 #endif/*!YYNMBCHARS*/
    137 
    138 /*
    139 ** yyparse - return 0 if worked, 1 if syntax error not recovered from
    140 */
    141 #if defined(__STDC__) || defined(__cplusplus)
    142 int yyparse(void)
    143 #else
    144 int yyparse()
    145 #endif
    146 {
    147 	register YYSTYPE *yypvt = 0;	/* top of value stack for $vars */
    148 
    149 #if defined(__cplusplus) || defined(lint) || defined(__GNUC__)
    150 /*
    151 	hacks to please C++, lint, and gcc - goto's inside
    152 	switch should never be executed
    153 */
    154 	static int _yaccpar_lint_hack = -1;
    155 	switch (_yaccpar_lint_hack)
    156 	{
    157 		case 1: goto yyerrlab;
    158 		case 2: goto yynewstate;
    159 	}
    160 #endif
    161 
    162 	/*
    163 	** Initialize externals - yyparse may be called more than once
    164 	*/
    165 	yypv = &yyv[-1];
    166 	yyps = &yys[-1];
    167 	yystate = 0;
    168 	yytmp = 0;
    169 	yynerrs = 0;
    170 	yyerrflag = 0;
    171 	yychar = -1;
    172 
    173 #if YYMAXDEPTH <= 0
    174 	if (yymaxdepth <= 0)
    175 	{
    176 		if ((yymaxdepth = YYEXPAND(0)) <= 0)
    177 		{
    178 			yyerror("yacc initialization error");
    179 			YYABORT;
    180 		}
    181 	}
    182 #endif
    183 
    184 	{
    185 		register YYSTYPE *yy_pv;	/* top of value stack */
    186 		register int *yy_ps;		/* top of state stack */
    187 		register int yy_state;		/* current state */
    188 		register int  yy_n;		/* internal state number info */
    189 	goto yystack;	/* moved from 6 lines above to here to please C++ */
    190 
    191 		/*
    192 		** get globals into registers.
    193 		** branch to here only if YYBACKUP was called.
    194 		*/
    195 	yynewstate:
    196 		yy_pv = yypv;
    197 		yy_ps = yyps;
    198 		yy_state = yystate;
    199 		goto yy_newstate;
    200 
    201 		/*
    202 		** get globals into registers.
    203 		** either we just started, or we just finished a reduction
    204 		*/
    205 	yystack:
    206 		yy_pv = yypv;
    207 		yy_ps = yyps;
    208 		yy_state = yystate;
    209 
    210 		/*
    211 		** top of for (;;) loop while no reductions done
    212 		*/
    213 	yy_stack:
    214 		/*
    215 		** put a state and value onto the stacks
    216 		*/
    217 #if YYDEBUG
    218 		/*
    219 		** if debugging, look up token value in list of value vs.
    220 		** name pairs.  0 and negative (-1) are special values.
    221 		** Note: linear search is used since time is not a real
    222 		** consideration while debugging.
    223 		*/
    224 		if ( yydebug )
    225 		{
    226 			register int yy_i;
    227 
    228 			printf( "State %d, token ", yy_state );
    229 			if ( yychar == 0 )
    230 				printf( "end-of-file\n" );
    231 			else if ( yychar < 0 )
    232 				printf( "-none-\n" );
    233 			else
    234 			{
    235 				for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
    236 					yy_i++ )
    237 				{
    238 					if ( yytoks[yy_i].t_val == yychar )
    239 						break;
    240 				}
    241 				printf( "%s\n", yytoks[yy_i].t_name );
    242 			}
    243 		}
    244 #endif /* YYDEBUG */
    245 		if ( ++yy_ps >= &yys[ yymaxdepth ] )	/* room on stack? */
    246 		{
    247 			/*
    248 			** reallocate and recover.  Note that pointers
    249 			** have to be reset, or bad things will happen
    250 			*/
    251 			long yyps_index = (yy_ps - yys);
    252 			long yypv_index = (yy_pv - yyv);
    253 			long yypvt_index = (yypvt - yyv);
    254 			int yynewmax;
    255 #ifdef YYEXPAND
    256 			yynewmax = YYEXPAND(yymaxdepth);
    257 #else
    258 			yynewmax = 2 * yymaxdepth;	/* double table size */
    259 			if (yymaxdepth == YYMAXDEPTH)	/* first time growth */
    260 			{
    261 				char *newyys = (char *)YYNEW(int);
    262 				char *newyyv = (char *)YYNEW(YYSTYPE);
    263 				if (newyys != 0 && newyyv != 0)
    264 				{
    265 					yys = YYCOPY(newyys, yys, int);
    266 					yyv = YYCOPY(newyyv, yyv, YYSTYPE);
    267 				}
    268 				else
    269 					yynewmax = 0;	/* failed */
    270 			}
    271 			else				/* not first time */
    272 			{
    273 				yys = YYENLARGE(yys, int);
    274 				yyv = YYENLARGE(yyv, YYSTYPE);
    275 				if (yys == 0 || yyv == 0)
    276 					yynewmax = 0;	/* failed */
    277 			}
    278 #endif
    279 			if (yynewmax <= yymaxdepth)	/* tables not expanded */
    280 			{
    281 				yyerror( "yacc stack overflow" );
    282 				YYABORT;
    283 			}
    284 			yymaxdepth = yynewmax;
    285 
    286 			yy_ps = yys + yyps_index;
    287 			yy_pv = yyv + yypv_index;
    288 			yypvt = yyv + yypvt_index;
    289 		}
    290 		*yy_ps = yy_state;
    291 		*++yy_pv = yyval;
    292 
    293 		/*
    294 		** we have a new state - find out what to do
    295 		*/
    296 	yy_newstate:
    297 		if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
    298 			goto yydefault;		/* simple state */
    299 #if YYDEBUG
    300 		/*
    301 		** if debugging, need to mark whether new token grabbed
    302 		*/
    303 		yytmp = yychar < 0;
    304 #endif
    305 		if ( ( yychar < 0 ) && ( ( yychar = YYLEX() ) < 0 ) )
    306 			yychar = 0;		/* reached EOF */
    307 #if YYDEBUG
    308 		if ( yydebug && yytmp )
    309 		{
    310 			register int yy_i;
    311 
    312 			printf( "Received token " );
    313 			if ( yychar == 0 )
    314 				printf( "end-of-file\n" );
    315 			else if ( yychar < 0 )
    316 				printf( "-none-\n" );
    317 			else
    318 			{
    319 				for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
    320 					yy_i++ )
    321 				{
    322 					if ( yytoks[yy_i].t_val == yychar )
    323 						break;
    324 				}
    325 				printf( "%s\n", yytoks[yy_i].t_name );
    326 			}
    327 		}
    328 #endif /* YYDEBUG */
    329 		if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
    330 			goto yydefault;
    331 		if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )	/*valid shift*/
    332 		{
    333 			yychar = -1;
    334 			yyval = yylval;
    335 			yy_state = yy_n;
    336 			if ( yyerrflag > 0 )
    337 				yyerrflag--;
    338 			goto yy_stack;
    339 		}
    340 
    341 	yydefault:
    342 		if ( ( yy_n = yydef[ yy_state ] ) == -2 )
    343 		{
    344 #if YYDEBUG
    345 			yytmp = yychar < 0;
    346 #endif
    347 			if ( ( yychar < 0 ) && ( ( yychar = YYLEX() ) < 0 ) )
    348 				yychar = 0;		/* reached EOF */
    349 #if YYDEBUG
    350 			if ( yydebug && yytmp )
    351 			{
    352 				register int yy_i;
    353 
    354 				printf( "Received token " );
    355 				if ( yychar == 0 )
    356 					printf( "end-of-file\n" );
    357 				else if ( yychar < 0 )
    358 					printf( "-none-\n" );
    359 				else
    360 				{
    361 					for ( yy_i = 0;
    362 						yytoks[yy_i].t_val >= 0;
    363 						yy_i++ )
    364 					{
    365 						if ( yytoks[yy_i].t_val
    366 							== yychar )
    367 						{
    368 							break;
    369 						}
    370 					}
    371 					printf( "%s\n", yytoks[yy_i].t_name );
    372 				}
    373 			}
    374 #endif /* YYDEBUG */
    375 			/*
    376 			** look through exception table
    377 			*/
    378 			{
    379 				register YYCONST int *yyxi = yyexca;
    380 
    381 				while ( ( *yyxi != -1 ) ||
    382 					( yyxi[1] != yy_state ) )
    383 				{
    384 					yyxi += 2;
    385 				}
    386 				while ( ( *(yyxi += 2) >= 0 ) &&
    387 					( *yyxi != yychar ) )
    388 					;
    389 				if ( ( yy_n = yyxi[1] ) < 0 )
    390 					YYACCEPT;
    391 			}
    392 		}
    393 
    394 		/*
    395 		** check for syntax error
    396 		*/
    397 		if ( yy_n == 0 )	/* have an error */
    398 		{
    399 			/* no worry about speed here! */
    400 			switch ( yyerrflag )
    401 			{
    402 			case 0:		/* new error */
    403 				yyerror( "syntax error" );
    404 				goto skip_init;
    405 			yyerrlab:
    406 				/*
    407 				** get globals into registers.
    408 				** we have a user generated syntax type error
    409 				*/
    410 				yy_pv = yypv;
    411 				yy_ps = yyps;
    412 				yy_state = yystate;
    413 			skip_init:
    414 				yynerrs++;
    415 				/* FALLTHRU */
    416 			case 1:
    417 			case 2:		/* incompletely recovered error */
    418 					/* try again... */
    419 				yyerrflag = 3;
    420 				/*
    421 				** find state where "error" is a legal
    422 				** shift action
    423 				*/
    424 				while ( yy_ps >= yys )
    425 				{
    426 					yy_n = yypact[ *yy_ps ] + YYERRCODE;
    427 					if ( yy_n >= 0 && yy_n < YYLAST &&
    428 						yychk[yyact[yy_n]] == YYERRCODE)					{
    429 						/*
    430 						** simulate shift of "error"
    431 						*/
    432 						yy_state = yyact[ yy_n ];
    433 						goto yy_stack;
    434 					}
    435 					/*
    436 					** current state has no shift on
    437 					** "error", pop stack
    438 					*/
    439 #if YYDEBUG
    440 #	define _POP_ "Error recovery pops state %d, uncovers state %d\n"
    441 					if ( yydebug )
    442 						printf( _POP_, *yy_ps,
    443 							yy_ps[-1] );
    444 #	undef _POP_
    445 #endif
    446 					yy_ps--;
    447 					yy_pv--;
    448 				}
    449 				/*
    450 				** there is no state on stack with "error" as
    451 				** a valid shift.  give up.
    452 				*/
    453 				YYABORT;
    454 			case 3:		/* no shift yet; eat a token */
    455 #if YYDEBUG
    456 				/*
    457 				** if debugging, look up token in list of
    458 				** pairs.  0 and negative shouldn't occur,
    459 				** but since timing doesn't matter when
    460 				** debugging, it doesn't hurt to leave the
    461 				** tests here.
    462 				*/
    463 				if ( yydebug )
    464 				{
    465 					register int yy_i;
    466 
    467 					printf( "Error recovery discards " );
    468 					if ( yychar == 0 )
    469 						printf( "token end-of-file\n" );
    470 					else if ( yychar < 0 )
    471 						printf( "token -none-\n" );
    472 					else
    473 					{
    474 						for ( yy_i = 0;
    475 							yytoks[yy_i].t_val >= 0;
    476 							yy_i++ )
    477 						{
    478 							if ( yytoks[yy_i].t_val
    479 								== yychar )
    480 							{
    481 								break;
    482 							}
    483 						}
    484 						printf( "token %s\n",
    485 							yytoks[yy_i].t_name );
    486 					}
    487 				}
    488 #endif /* YYDEBUG */
    489 				if ( yychar == 0 )	/* reached EOF. quit */
    490 					YYABORT;
    491 				yychar = -1;
    492 				goto yy_newstate;
    493 			}
    494 		}/* end if ( yy_n == 0 ) */
    495 		/*
    496 		** reduction by production yy_n
    497 		** put stack tops, etc. so things right after switch
    498 		*/
    499 #if YYDEBUG
    500 		/*
    501 		** if debugging, print the string that is the user's
    502 		** specification of the reduction which is just about
    503 		** to be done.
    504 		*/
    505 		if ( yydebug )
    506 			printf( "Reduce by (%d) \"%s\"\n",
    507 				yy_n, yyreds[ yy_n ] );
    508 #endif
    509 		yytmp = yy_n;			/* value to switch over */
    510 		yypvt = yy_pv;			/* $vars top of value stack */
    511 		/*
    512 		** Look in goto table for next state
    513 		** Sorry about using yy_state here as temporary
    514 		** register variable, but why not, if it works...
    515 		** If yyr2[ yy_n ] doesn't have the low order bit
    516 		** set, then there is no action to be done for
    517 		** this reduction.  So, no saving & unsaving of
    518 		** registers done.  The only difference between the
    519 		** code just after the if and the body of the if is
    520 		** the goto yy_stack in the body.  This way the test
    521 		** can be made before the choice of what to do is needed.
    522 		*/
    523 		{
    524 			/* length of production doubled with extra bit */
    525 			register int yy_len = yyr2[ yy_n ];
    526 
    527 			if ( !( yy_len & 01 ) )
    528 			{
    529 				yy_len >>= 1;
    530 				yyval = ( yy_pv -= yy_len )[1];	/* $$ = $1 */
    531 				yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
    532 					*( yy_ps -= yy_len ) + 1;
    533 				if ( yy_state >= YYLAST ||
    534 					yychk[ yy_state =
    535 					yyact[ yy_state ] ] != -yy_n )
    536 				{
    537 					yy_state = yyact[ yypgo[ yy_n ] ];
    538 				}
    539 				goto yy_stack;
    540 			}
    541 			yy_len >>= 1;
    542 			yyval = ( yy_pv -= yy_len )[1];	/* $$ = $1 */
    543 			yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
    544 				*( yy_ps -= yy_len ) + 1;
    545 			if ( yy_state >= YYLAST ||
    546 				yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
    547 			{
    548 				yy_state = yyact[ yypgo[ yy_n ] ];
    549 			}
    550 		}
    551 					/* save until reenter driver code */
    552 		yystate = yy_state;
    553 		yyps = yy_ps;
    554 		yypv = yy_pv;
    555 	}
    556 	/*
    557 	** code supplied by user is placed in this switch
    558 	*/
    559 	switch( yytmp )
    560 	{
    561 		$A
    562 	}
    563 	goto yystack;		/* reset registers in driver code */
    564 }
    565