/* KJT 20/01/23: added function prototypes */

int yyparse();

# line 2 "gram.y"
/* Revision 2000/07/00  16:32:00  kjt
   changed YYMAXDEPTH to 512 */

# include "swbus.h"
# define YYMAXDEPTH      512
# define YYSTYPE         yystype
# define putgrn(n)       (void)ITadd(n, gl)
# define class(nt)       { cls= 0; xxc= nt-1;   \
	       for (xc= 0; xc < nt; xc++, xxc--)    \
			     if (stpick(xc)->type != tNULL) \
		 cls += (1 << xxc);}
# define ndput(tp)   { stput(tp);   \
	       if (gn != NULL){gn->value0=  \
		  (CLR_TYPE)IAT_IT_add(gl, grnl); \
		  gl->size= 0;} \
	       gn= (sttype() == tNULL) ? NULL : sttop(); }
# define ndterm(tp, val) { stput (tp);  \
		       staclr (c_lexv, (CLR_TYPE)val.name); \
		       staclr (c_line, (CLR_TYPE)val.line);}

IT* gl;
TNODE*  gn;
int cls;
int xc;
int xxc;

# define R 260
# define INTEGER 261
# define OF 262
# define IDENTIFIER 263
# define SPECIAL 264
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern short yyerrflag;
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 150
#endif
#ifndef YYSTYPE
#define YYSTYPE int
#endif
YYSTYPE yylval, yyval;
# define YYERRCODE 256

# line 458 "gram.y"


PRIVATE int
yylex ()
{
    token *tk;

   tk = gtk ();
   yylval = tk->yylval;
   return tk->type;
}

PUBLIC TNODE*
bast ()
{
   gl= ITcreate (4, 2, 1);
   gn= NULL;
   (void)yyparse();
   if (gn != NULL) gn->value0= (CLR_TYPE)IAT_IT_add(gl, grnl);
   return sttop();
}
short yyexca[] ={
-1, 0,
	58, 4,
	-2, 18,
-1, 1,
	0, -1,
	-2, 0,
-1, 2,
	263, 18,
	58, 4,
	-2, 3,
	};
# define YYNPROD 43
# define YYLAST 227
short yyact[]={

  47,  49,  46,  45,  20,  54,  13,  31,  42,  36,
  55,  40,  16,  39,  15,  48,  17,   9,  38,  29,
  35,   7,  18,   3,  44,  53,  14,  34,  19,  33,
  32,  41,  30,  25,  21,  27,  22,  28,  26,  37,
  12,  10,  24,   8,   6,  23,  50,   5,   4,   2,
   1,   0,   0,   0,   0,  43,   0,   0,  52,  51,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  56,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,  11 };
short yypact[]={

 -34,-1000, -34,-1000, -44,-1000, -47,-1000, -28,-1000,
-259,-259,-1000,-259,-1000, -34, -34, -34,-254, -24,
-1000,-1000, -23, -45, -48,-1000,-1000,-1000,-1000,-1000,
-253,-1000,-1000,-1000, -24,-1000,-261,-262,-1000,-254,
 -34,-1000,-1000,-1000,-257,-1000,-1000,-1000,-1000,-1000,
 -49,-1000,-1000,-1000,-262,-1000,-1000 };
short yypgo[]={

   0,  50,  49,  23,  48,  47,  46,  19,  45,  44,
  21,  43,  17,  42,  41,  40,  37,  22,  32,  31,
  30,  29,  28,  27,  20,  25,  15,  24 };
short yyr1[]={

   0,   2,   2,   1,   4,   4,   6,   6,   3,   9,
   9,   5,  11,  11,  10,  13,  13,   8,  14,  14,
  16,  16,  12,  12,  15,   7,  18,  19,  20,  20,
  17,  23,  23,  21,  25,  25,  24,  24,  22,  27,
  27,  27,  26 };
short yyr2[]={

   0,   1,   2,   1,   0,   1,   0,   1,   6,   1,
   3,   1,   1,   3,   1,   1,   3,   1,   0,   1,
   0,   1,   3,   2,   3,   2,   1,   1,   0,   1,
   2,   1,   2,   1,   0,   2,   3,   2,   1,   1,
   1,   1,   1 };
short yychk[]={

-1000,  -1,  -2,  -3,  -4,  -5,  -9, -10, -11, -12,
 -14, 260, -15,  40,  -3,  58,  59,  44, -17, -22,
 263, -17, -17,  -8, -13, -12, -10, -12, -16,  -7,
 -18, 261, -20, -21, -23, -24,  33,  63,  41,  58,
  59, -19, 261, -24, -27, 264, 263, 261, -26, 263,
  -6,  -7, -12, -25, 262,  59, -26 };
short yydef[]={

  -2,  -2,  -2,   1,   0,   5,  11,   9,  14,  12,
   0,   0,  19,   0,   2,  18,  18,  18,  20,  28,
  38,  23,   0,   0,  17,  15,  10,  13,  22,  21,
   0,  26,  30,  29,  33,  31,   0,   0,  24,   6,
  18,  25,  27,  32,  34,  39,  40,  41,  37,  42,
   0,   7,  16,  36,   0,   8,  35 };
# line 1 "/usr/lib/yaccpar"
#ifndef lint
static char yaccpar_sccsid[] = "@(#)yaccpar	4.1	(Berkeley)	2/11/83";
#endif

# define YYFLAG -1000
# define YYERROR goto yyerrlab
# define YYACCEPT return(0)
# define YYABORT return(1)

/*	parser for yacc output	*/

#ifdef YYDEBUG
int yydebug = 0; /* 1 for debugging */
#endif
YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
int yychar = -1; /* current input token number */
int yynerrs = 0;  /* number of errors */
short yyerrflag = 0;  /* error recovery flag */

/* KJT 20/01/23: added "int" type */
int yyparse() {

	short yys[YYMAXDEPTH];
	short yyj, yym;
	register YYSTYPE *yypvt;
	register short yystate, *yyps, yyn;
	register YYSTYPE *yypv;
	register short *yyxi;

	yystate = 0;
	yychar = -1;
	yynerrs = 0;
	yyerrflag = 0;
	yyps= &yys[-1];
	yypv= &yyv[-1];

 yystack:    /* put a state and value onto the stack */

#ifdef YYDEBUG
	if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
#endif
		if( ++yyps>= &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
		*yyps = yystate;
		++yypv;
		*yypv = yyval;

 yynewstate:

	yyn = yypact[yystate];

	if( yyn<= YYFLAG ) goto yydefault; /* simple state */

	if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
	if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;

	if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
		yychar = -1;
		yyval = yylval;
		yystate = yyn;
		if( yyerrflag > 0 ) --yyerrflag;
		goto yystack;
		}

 yydefault:
	/* default state action */

	if( (yyn=yydef[yystate]) == -2 ) {
		if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
		/* look through exception table */

		for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */

		while( *(yyxi+=2) >= 0 ){
			if( *yyxi == yychar ) break;
			}
		if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
		}

	if( yyn == 0 ){ /* error */
		/* error ... attempt to resume parsing */

		switch( yyerrflag ){

		case 0:   /* brand new error */

			yyerror( "syntax error" );
		yyerrlab:
			++yynerrs;

		case 1:
		case 2: /* incompletely recovered error ... try again */

			yyerrflag = 3;

			/* find a state where "error" is a legal shift action */

			while ( yyps >= yys ) {
			   yyn = yypact[*yyps] + YYERRCODE;
			   if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
			      yystate = yyact[yyn];  /* simulate a shift of "error" */
			      goto yystack;
			      }
			   yyn = yypact[*yyps];

			   /* the current yyps has no shift onn "error", pop stack */

#ifdef YYDEBUG
			   if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
#endif
			   --yyps;
			   --yypv;
			   }

			/* there is no state on the stack with an error shift ... abort */

	yyabort:
			return(1);


		case 3:  /* no shift yet; clobber input char */

#ifdef YYDEBUG
			if( yydebug ) printf( "error recovery discards char %d\n", yychar );
#endif

			if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
			yychar = -1;
			goto yynewstate;   /* try again in the same state */

			}

		}

	/* reduction by production yyn */

#ifdef YYDEBUG
		if( yydebug ) printf("reduce %d\n",yyn);
#endif
		yyps -= yyr2[yyn];
		yypvt = yypv;
		yypv -= yyr2[yyn];
		yyval = yypv[1];
		yym=yyn;
			/* consult goto table to find next state */
		yyn = yyr1[yyn];
		yyj = yypgo[yyn] + *yyps + 1;
		if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
		switch(yym){

case 2:
# line 47 "gram.y"
{ if (errorcount == 0) stlrlink (); } break;
case 3:
# line 52 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(tPTCS);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(1);
	}
	} break;
case 4:
# line 68 "gram.y"
{ ndput (tNULL); } break;
case 6:
# line 77 "gram.y"
{ ndput (tNULL); } break;
case 8:
# line 86 "gram.y"
{
	if (errorcount == 0)
	{
	 class(3);
	 if (sttype() == tNULL) stpop();
	 else if (stpick(1)->type == tNULL) {stswap(); stpop();}
	 else stlrlink();
	 if (sttype() == tNULL) stpop();
	 else if (stpick(1)->type == tNULL) {stswap(); stpop();}
	 else stlrlink();
	 ndput(tPTC);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(2);
	}
	} break;
case 10:
# line 112 "gram.y"
{ if (errorcount == 0) stlrlink (); } break;
case 11:
# line 117 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(tsobjs);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(3);
	}
	} break;
case 13:
# line 137 "gram.y"
{ if (errorcount == 0) stlrlink (); } break;
case 14:
# line 142 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(tCsubobj);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(4);
	}
	} break;
case 16:
# line 162 "gram.y"
{ if (errorcount == 0) stlrlink (); } break;
case 17:
# line 167 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(tobjs);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(5);
	}
	} break;
case 18:
# line 183 "gram.y"
{ ndput (tNULL); } break;
case 20:
# line 192 "gram.y"
{ ndput (tNULL); } break;
case 22:
# line 201 "gram.y"
{
	if (errorcount == 0)
	{
	 class(3);
	 if (sttype() == tNULL) stpop();
	 else if (stpick(1)->type == tNULL) {stswap(); stpop();}
	 else stlrlink();
	 if (sttype() == tNULL) stpop();
	 else if (stpick(1)->type == tNULL) {stswap(); stpop();}
	 else stlrlink();
	 ndput(tobj);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(6);
	}
	} break;
case 23:
# line 223 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(tobj);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(7);
	}
	} break;
case 24:
# line 239 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(tpath);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(8);
	}
	} break;
case 25:
# line 255 "gram.y"
{
	if (errorcount == 0)
	{
	 class(2);
	 stlrlink ();
	 ndput(trange);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(9);
	}
	} break;
case 26:
# line 272 "gram.y"
{
	if (errorcount == 0)
	{
	 ndput(tminl);
	 staclr (c_lexv, (CLR_TYPE)yypvt[-0].name);
	 staclr (c_line, (CLR_TYPE)yypvt[-0].line);
	 putgrn(10);
	}
	} break;
case 27:
# line 285 "gram.y"
{
	if (errorcount == 0)
	{
	 ndput(tmaxl);
	 staclr (c_lexv, (CLR_TYPE)yypvt[-0].name);
	 staclr (c_line, (CLR_TYPE)yypvt[-0].line);
	 putgrn(11);
	}
	} break;
case 28:
# line 298 "gram.y"
{ ndput (tNULL); } break;
case 30:
# line 307 "gram.y"
{
	if (errorcount == 0)
	{
	 class(2);
	 if (sttype() == tNULL) stpop();
	 else if (stpick(1)->type == tNULL) {stswap(); stpop();}
	 else stlrlink();
	 ndput(tlabel);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(12);
	}
	} break;
case 32:
# line 330 "gram.y"
{ if (errorcount == 0) stlrlink (); } break;
case 33:
# line 335 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(texperiment_list);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(13);
	}
	} break;
case 34:
# line 351 "gram.y"
{ ndput (tNULL); } break;
case 36:
# line 360 "gram.y"
{
	if (errorcount == 0)
	{
	 class(2);
	 if (sttype() == tNULL) stpop();
	 else if (stpick(1)->type == tNULL) {stswap(); stpop();}
	 else stlrlink();
	 ndput(texp);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(14);
	}
	} break;
case 37:
# line 379 "gram.y"
{
	if (errorcount == 0)
	{
	 class(1);
	 ndput(texp);
	 sttop()->value1= (CLR_TYPE)cls;
	 if (stpick(1)->type == tNULL)
	      {stswap(); stpop();}
	 else stsflink ();
	 putgrn(15);
	}
	} break;
case 38:
# line 395 "gram.y"
{
	if (errorcount == 0)
	{
	 ndput(tgate_name);
	 staclr (c_lexv, (CLR_TYPE)yypvt[-0].name);
	 staclr (c_line, (CLR_TYPE)yypvt[-0].line);
	 putgrn(16);
	}
	} break;
case 39:
# line 408 "gram.y"
{
	if (errorcount == 0)
	{
	 ndput(tval_id);
	 staclr (c_lexv, (CLR_TYPE)yypvt[-0].name);
	 staclr (c_line, (CLR_TYPE)yypvt[-0].line);
	 putgrn(17);
	}
	} break;
case 40:
# line 421 "gram.y"
{
	if (errorcount == 0)
	{
	 ndput(tval_id);
	 staclr (c_lexv, (CLR_TYPE)yypvt[-0].name);
	 staclr (c_line, (CLR_TYPE)yypvt[-0].line);
	 putgrn(18);
	}
	} break;
case 41:
# line 434 "gram.y"
{
	if (errorcount == 0)
	{
	 ndput(tval_id);
	 staclr (c_lexv, (CLR_TYPE)yypvt[-0].name);
	 staclr (c_line, (CLR_TYPE)yypvt[-0].line);
	 putgrn(19);
	}
	} break;
case 42:
# line 447 "gram.y"
{
	if (errorcount == 0)
	{
	 ndput(tsort_id);
	 staclr (c_lexv, (CLR_TYPE)yypvt[-0].name);
	 staclr (c_line, (CLR_TYPE)yypvt[-0].line);
	 putgrn(20);
	}
	} break;
# line 148 "/usr/lib/yaccpar"

		}
		goto yystack;  /* stack new state and value */

	}
