
# line 2 "ct.y"
/*
 *
 *	Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology
 *    	Developed by the MIT Student Information Processing Board (SIPB).
 *    	For copying information, see the file mit-copyright.h in this release.
 *
 */
#include <stdio.h>
#include "copyright.h"

char *str_concat3(), *ds(), *generate_rqte(), *malloc(), *realloc(), *quote();
long flag_value();
char *last_token = (char *)NULL;
FILE *output_file;
long gensym_n = 0;


# line 19 "ct.y"
typedef union  {
	char *dynstr;
	long flags;
} YYSTYPE;
# define COMMAND_TABLE 257
# define REQUEST 258
# define UNKNOWN 259
# define UNIMPLEMENTED 260
# define END 261
# define STRING 262
# define FLAGNAME 263
# define OPTIONS 264

# line 32 "ct.y"
#include "ss.h"
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern short yyerrflag;
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 150
#endif
YYSTYPE yylval, yyval;
# define YYERRCODE 256

# line 79 "ct.y"

short yyexca[] ={
-1, 1,
	0, -1,
	-2, 0,
	};
# define YYNPROD 15
# define YYLAST 228
short yyact[]={

   8,   9,  10,   6,  35,  32,  39,  15,  23,  22,
  21,  16,  13,   5,   3,  19,  28,  19,  33,  12,
  11,  37,  25,  24,  38,  20,  17,  14,   1,  31,
  30,  29,  18,  34,   7,   4,   2,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,  26,  27,   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,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,  36,   0,  22 };
short yypact[]={

-243,-1000,-1000,-249,-258, -39, -40,-1000,-250,-255,
-251,-1000,-1000, -18, -27,-1000, -19,-252,-1000,-253,
-254, -21,-1000, -22,-255,-255, -28, -29, -35,-1000,
-1000, -41, -37,-1000, -20,-1000,-1000,-1000,-256,-1000 };
short yypgo[]={

   0,  27,  36,  35,  34,  33,  29,  28 };
short yyr1[]={

   0,   7,   2,   3,   3,   4,   4,   4,   4,   6,
   6,   5,   5,   1,   1 };
short yyr2[]={

   0,   4,   3,   2,   0,   9,   7,   3,   7,   3,
   2,   3,   1,   1,   3 };
short yychk[]={

-1000,  -7,  -2, 257,  -3, 262, 261,  -4, 258, 259,
 260,  59,  59, 262,  -1, 262, 262,  44,  59,  44,
  44, 262, 262, 262,  44,  44,  -1,  -1,  44,  59,
  59,  -6,  40,  59,  -5,  41, 262,  41,  44, 262 };
short yydef[]={

   0,  -2,   4,   0,   0,   0,   0,   3,   0,   0,
   0,   2,   1,   0,   0,  13,   0,   0,   7,   0,
   0,   0,  14,   0,   0,   0,   0,   0,   0,   6,
   8,   0,   0,   5,   0,  10,  12,   9,   0,  11 };
/*
 *	$Source: /afs/rel-eng.athena.mit.edu/project/release/current/source/bsd-4.3/common/usr.bin/yacc/RCS/yaccpar,v $
 *	$Author: epeisach $
 *	$Locker:  $
 *	$Header: /afs/rel-eng.athena.mit.edu/project/release/current/source/bsd-4.3/common/usr.bin/yacc/RCS/yaccpar,v 1.4 90/03/30 10:09:19 epeisach Exp $
 */

#ifndef lint
static char yaccpar_sccsid[] = "@(#)yaccpar	4.1	(Berkeley)	2/11/83";
#endif /* not lint */

# 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 */

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 1:
# line 37 "ct.y"
{ write_ct(yypvt[-3].dynstr, yypvt[-2].dynstr); } break;
case 2:
# line 41 "ct.y"
{ yyval.dynstr = yypvt[-1].dynstr; } break;
case 3:
# line 45 "ct.y"
{ yyval.dynstr = str_concat3(yypvt[-1].dynstr, yypvt[-0].dynstr, ""); } break;
case 4:
# line 47 "ct.y"
{ yyval.dynstr = ""; } break;
case 5:
# line 51 "ct.y"
{ yyval.dynstr = generate_rqte(yypvt[-7].dynstr, quote(yypvt[-5].dynstr), yypvt[-3].dynstr, yypvt[-1].flags); } break;
case 6:
# line 53 "ct.y"
{ yyval.dynstr = generate_rqte(yypvt[-5].dynstr, quote(yypvt[-3].dynstr), yypvt[-1].dynstr, 0); } break;
case 7:
# line 55 "ct.y"
{ yyval.dynstr = generate_rqte("ss_unknown_request",
					(char *)NULL, yypvt[-1].dynstr, 0); } break;
case 8:
# line 58 "ct.y"
{ yyval.dynstr = generate_rqte("ss_unimplemented", quote(yypvt[-3].dynstr), yypvt[-1].dynstr, 3); } break;
case 9:
# line 62 "ct.y"
{ yyval.flags = yypvt[-1].flags; } break;
case 10:
# line 64 "ct.y"
{ yyval.flags = 0; } break;
case 11:
# line 68 "ct.y"
{ yyval.flags = yypvt[-2].flags | flag_val(yypvt[-0].dynstr); } break;
case 12:
# line 70 "ct.y"
{ yyval.flags = flag_val(yypvt[-0].dynstr); } break;
case 13:
# line 74 "ct.y"
{ yyval.dynstr = quote(ds(yypvt[-0].dynstr)); } break;
case 14:
# line 76 "ct.y"
{ yyval.dynstr = str_concat3(yypvt[-2].dynstr, quote(yypvt[-0].dynstr), ",\n    "); } break;
		}
		goto yystack;  /* stack new state and value */

	}
