#include	"c_varieties.h"
#if __EXTERN_C__
EXTERN_FUNCTION (extern int yylook,());
EXTERN_FUNCTION (extern int yywrap,());
EXTERN_FUNCTION (extern int yyback, (int *, int));
#elif defined (__cplusplus) || defined (c_plusplus)
	extern int yylook();
	extern int yywrap();
	extern int yyback(int *, int);
#endif
# include "stdio.h"
# define U(x) x
# define NLSTATE yyprevious=YYNEWLINE
# define BEGIN yybgin = yysvec + 1 +
# define INITIAL 0
# define YYLERR yysvec
# define YYSTATE (yyestate-yysvec-1)
# define YYOPTIM 1
# define YYLMAX BUFSIZ
# define lex_output(c) putc(c,yyout)
# define lex_input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
# define yymore() (yymorfg=1)
# define ECHO fprintf(yyout, "%s",yytext)
# define REJECT { nstr = yyreject(); goto yyfussy;}
int yyleng; extern char yytext[];
int yymorfg;
extern char *yysptr, yysbuf[];
int yytchar;
FILE *yyin = {stdin}, *yyout = {stdout};
extern int yylineno;
struct yysvf { 
	struct yywork *yystoff;
	struct yysvf *yyother;
	int *yystops;};
struct yysvf *yyestate;
extern struct yysvf yysvec[], *yybgin;

/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

static char sccsid_easn_lex[] = "@(#)easn.lex	1.5 11/6/92 07:29:50  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	8/13/90

	ROUTINE:	Lexical Analyzer for ASN.1_Encoder
			Compile with yacc++

PURPOSE:
	This is the lex spec. used to parse a ASN.1 raw-value specification. The
syntax allows the specification of an ASN.1 encoding without benefit of an
encoding specification. 

CALLED ROUTINES:
	
MODIFICATION HISTORY:


*/


#include "asn1.h"
#include <ctype.h>
#include <malloc.h>
#include <string.h>
#include "y.tab.h"

extern FILE	*listfile;
int vlinenumber=0;

extern YYSTYPE yylval;
void asn_error(char *,char *);

#define verror(X)	asn_error("Lexical Error",X)

void vecho();

# define YYNEWLINE 10
yylex(){
int nstr; extern int yyprevious;
  extern YYSTYPE yylval;
while((nstr = yylook()) >= 0)
#ifdef YYFUSSY
yyfussy:
#endif
	 switch(nstr){
case 0:
if(yywrap()) return(0); break;
case 1:
	{vecho(); return(UNIVERSAL);}
break;
case 2:
		{vecho(); return(CONTEXT);}
break;
case 3:
{vecho(); return(APPLICATION);}
break;
case 4:
		{vecho(); return(PRIVATE);}
break;
case 5:
{vecho(); return(CONSTRUCTED);}
break;
case 6:
			{vecho(); return(CONSTRUCTED);}
break;
case 7:
	{vecho(); return(PRIMITIVE);}
break;
case 8:
			{vecho(); return(PRIMITIVE);}
break;
case 9:
	{vecho(); return(LEFTPAREN);}
break;
case 10:
	{vecho(); return(RIGHTPAREN);}
break;
case 11:
	{vecho(); return(LEFTBRACKET);}
break;
case 12:
	{vecho(); return(RIGHTBRACKET);}
break;
case 13:
	{vecho(); return(LEFTBRACE);}
break;
case 14:
	{vecho(); return(RIGHTBRACE);}
break;
case 15:
	{vecho(); return(ELLIPSES);}
break;
case 16:
	vecho();
break;
case 17:
	vecho();
break;
case 18:
	vecho();
break;
case 19:
	{
				vecho();
				yytext[yyleng] = 0;
				yylval.string = yytext;
				return(NUMBER);
			}
break;
case 20:
	{
				vecho();
				yytext[yyleng] = 0;
				yylval.string = yytext;
				return(HEXNUMBER);
			}
break;
case 21:
		{ vecho();
			  yyleng = 1;
			  do
			  {
			     while ((*yytext=lex_input())!='*')
			        vecho();
			     vecho();
			     *yytext=lex_input();
			     vecho();
			  } while (*yytext != '/');
			}
break;
case 22:
		{verror("Illegal character in input stream");}
break;
case -1:
break;
default:
fprintf(yyout,"bad switch yylook %d",nstr);
} return(0); }
/* end of yylex */
void vecho ()
   /* echo input on the listing file. */
  { static int BeginALine = 1;
	if (BeginALine) {
	  BeginALine = 0;
	  fprintf( listfile, "%4d ", ++vlinenumber );
	};
	yytext[yyleng] = (char) 0;
	fprintf( listfile, "%s", yytext );
	if ( yytext[ yyleng-1 ]=='\n' )
	  BeginALine = 1;
  }; /* vecho */

int yyvstop[] = {
0,

22,
0,

16,
22,
0,

17,
0,

18,
22,
0,

9,
22,
0,

10,
22,
0,

22,
0,

22,
0,

19,
20,
22,
0,

20,
22,
0,

20,
22,
0,

20,
22,
0,

22,
0,

22,
0,

11,
22,
0,

12,
22,
0,

13,
22,
0,

14,
22,
0,

21,
0,

19,
20,
0,

20,
0,

15,
0,

19,
0,

6,
0,

8,
0,

2,
0,

4,
0,

7,
0,

1,
0,

3,
0,

5,
0,
0};
# define YYTYPE char
struct yywork { YYTYPE verify, advance; } yycrank[] = {
0,0,	0,0,	1,3,	0,0,	
0,0,	0,0,	0,0,	0,0,	
0,0,	0,0,	1,4,	1,5,	
0,0,	2,4,	0,0,	0,0,	
0,0,	0,0,	0,0,	0,0,	
0,0,	0,0,	0,0,	0,0,	
0,0,	0,0,	0,0,	0,0,	
0,0,	0,0,	0,0,	0,0,	
0,0,	1,6,	0,0,	0,0,	
2,6,	0,0,	0,0,	0,0,	
0,0,	1,7,	1,8,	10,22,	
2,7,	2,8,	0,0,	1,9,	
1,10,	1,11,	2,9,	2,10,	
9,21,	13,24,	13,24,	13,24,	
13,24,	13,24,	13,24,	13,24,	
13,24,	13,24,	13,24,	21,29,	
0,0,	0,0,	1,12,	1,13,	
1,14,	1,13,	1,13,	0,0,	
0,0,	0,0,	1,3,	0,0,	
27,33,	1,3,	1,3,	1,3,	
1,3,	1,15,	16,28,	1,3,	
1,3,	1,3,	1,16,	1,3,	
0,0,	1,3,	15,27,	25,31,	
1,17,	26,32,	1,18,	2,17,	
28,34,	2,18,	11,23,	11,23,	
11,23,	11,23,	11,23,	11,23,	
11,23,	11,23,	11,23,	11,23,	
27,33,	31,35,	32,36,	32,37,	
33,38,	34,40,	16,28,	11,24,	
11,24,	11,24,	11,24,	11,24,	
11,24,	33,39,	15,27,	25,31,	
1,19,	26,32,	1,20,	2,19,	
28,34,	2,20,	12,24,	12,24,	
12,24,	12,24,	12,24,	12,24,	
12,24,	12,24,	12,24,	12,24,	
0,0,	31,35,	32,36,	32,37,	
33,38,	34,40,	0,0,	11,24,	
11,24,	11,24,	11,24,	11,24,	
11,24,	33,39,	35,41,	36,42,	
37,43,	38,44,	39,45,	40,46,	
41,47,	42,48,	12,25,	0,0,	
14,24,	14,24,	14,24,	14,24,	
14,24,	14,24,	14,24,	14,24,	
14,24,	14,24,	23,30,	23,30,	
23,30,	23,30,	23,30,	23,30,	
23,30,	23,30,	23,30,	23,30,	
43,49,	44,50,	35,41,	36,42,	
37,43,	38,44,	39,45,	40,46,	
41,47,	42,48,	12,25,	14,26,	
45,51,	46,52,	47,53,	48,54,	
49,55,	50,56,	51,57,	52,58,	
53,59,	54,60,	56,61,	58,62,	
59,63,	60,64,	61,65,	62,66,	
63,67,	64,68,	67,69,	68,70,	
43,49,	44,50,	0,0,	0,0,	
0,0,	0,0,	0,0,	0,0,	
0,0,	0,0,	0,0,	14,26,	
45,51,	46,52,	47,53,	48,54,	
49,55,	50,56,	51,57,	52,58,	
53,59,	54,60,	56,61,	58,62,	
59,63,	60,64,	61,65,	62,66,	
63,67,	64,68,	67,69,	68,70,	
0,0};
struct yysvf yysvec[] = {
0,	0,	0,
yycrank+-1,	0,		0,	
yycrank+-4,	yysvec+1,	0,	
yycrank+0,	0,		yyvstop+1,
yycrank+0,	0,		yyvstop+3,
yycrank+0,	0,		yyvstop+6,
yycrank+0,	0,		yyvstop+8,
yycrank+0,	0,		yyvstop+11,
yycrank+0,	0,		yyvstop+14,
yycrank+6,	0,		yyvstop+17,
yycrank+1,	0,		yyvstop+19,
yycrank+50,	0,		yyvstop+21,
yycrank+82,	yysvec+11,	yyvstop+25,
yycrank+5,	yysvec+11,	yyvstop+28,
yycrank+116,	yysvec+11,	yyvstop+31,
yycrank+8,	0,		yyvstop+34,
yycrank+4,	0,		yyvstop+36,
yycrank+0,	0,		yyvstop+38,
yycrank+0,	0,		yyvstop+41,
yycrank+0,	0,		yyvstop+44,
yycrank+0,	0,		yyvstop+47,
yycrank+17,	0,		0,	
yycrank+0,	0,		yyvstop+50,
yycrank+126,	0,		yyvstop+52,
yycrank+0,	0,		yyvstop+55,
yycrank+11,	0,		0,	
yycrank+15,	0,		0,	
yycrank+3,	0,		0,	
yycrank+23,	0,		0,	
yycrank+0,	0,		yyvstop+57,
yycrank+0,	yysvec+23,	yyvstop+59,
yycrank+33,	0,		0,	
yycrank+27,	0,		yyvstop+61,
yycrank+35,	0,		0,	
yycrank+27,	0,		0,	
yycrank+81,	0,		0,	
yycrank+71,	0,		0,	
yycrank+87,	0,		0,	
yycrank+84,	0,		yyvstop+63,
yycrank+93,	0,		0,	
yycrank+90,	0,		0,	
yycrank+93,	0,		0,	
yycrank+79,	0,		0,	
yycrank+96,	0,		0,	
yycrank+101,	0,		0,	
yycrank+112,	0,		0,	
yycrank+115,	0,		0,	
yycrank+133,	0,		0,	
yycrank+114,	0,		0,	
yycrank+116,	0,		0,	
yycrank+128,	0,		0,	
yycrank+133,	0,		0,	
yycrank+120,	0,		0,	
yycrank+120,	0,		0,	
yycrank+138,	0,		0,	
yycrank+0,	0,		yyvstop+65,
yycrank+120,	0,		0,	
yycrank+0,	0,		yyvstop+67,
yycrank+142,	0,		0,	
yycrank+135,	0,		0,	
yycrank+125,	0,		0,	
yycrank+141,	0,		0,	
yycrank+135,	0,		0,	
yycrank+133,	0,		0,	
yycrank+144,	0,		0,	
yycrank+0,	0,		yyvstop+69,
yycrank+0,	0,		yyvstop+71,
yycrank+136,	0,		0,	
yycrank+147,	0,		0,	
yycrank+0,	0,		yyvstop+73,
yycrank+0,	0,		yyvstop+75,
0,	0,	0};
struct yywork *yytop = yycrank+247;
struct yysvf *yybgin = yysvec+1;
char yymatch[] = {
00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
01  ,01  ,012 ,01  ,01  ,01  ,01  ,01  ,
01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
'0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
01  ,'A' ,'B' ,'C' ,'D' ,'E' ,'B' ,01  ,
01  ,'I' ,01  ,01  ,'L' ,'M' ,'N' ,'O' ,
'P' ,01  ,'R' ,'S' ,'T' ,'U' ,'V' ,01  ,
'X' ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
01  ,'A' ,'B' ,'C' ,'D' ,'E' ,'B' ,01  ,
01  ,'I' ,01  ,01  ,'L' ,'M' ,'N' ,'O' ,
'P' ,01  ,'R' ,'S' ,'T' ,'U' ,'V' ,01  ,
'X' ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
0};
char yyextra[] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0};
#ifndef lint
static	char ncform_sccsid[] = "@(#)ncform 1.8 89/09/18 SMI"; /* from S5R2 1.2 */
#endif

int yylineno =1;
# define YYU(x) x
# define NLSTATE yyprevious=YYNEWLINE
char yytext[YYLMAX];
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
char yysbuf[YYLMAX];
char *yysptr = yysbuf;
int *yyfnd;
extern struct yysvf *yyestate;
int yyprevious = YYNEWLINE;
yylook(){
	register struct yysvf *yystate, **lsp;
	register struct yywork *yyt;
	struct yysvf *yyz;
	int yych, yyfirst;
	struct yywork *yyr;
# ifdef LEXDEBUG
	int debug;
# endif
	char *yylastch;
	/* start off machines */
# ifdef LEXDEBUG
	debug = 0;
# endif
	yyfirst=1;
	if (!yymorfg)
		yylastch = yytext;
	else {
		yymorfg=0;
		yylastch = yytext+yyleng;
		}
	for(;;){
		lsp = yylstate;
		yyestate = yystate = yybgin;
		if (yyprevious==YYNEWLINE) yystate++;
		for (;;){
# ifdef LEXDEBUG
			if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
# endif
			yyt = yystate->yystoff;
			if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
				yyz = yystate->yyother;
				if(yyz == 0)break;
				if(yyz->yystoff == yycrank)break;
				}
yych = lex_input();
			*yylastch++ = yych;
			yyfirst=0;
		tryagain:
# ifdef LEXDEBUG
			if(debug){
				fprintf(yyout,"char ");
				allprint(yych);
				putchar('\n');
				}
# endif
			yyr = yyt;
			if ( (int)yyt > (int)yycrank){
				yyt = yyr + yych;
				if (yyt <= yytop && yyt->verify+yysvec == yystate){
					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
						{unput(*--yylastch);break;}
					*lsp++ = yystate = yyt->advance+yysvec;
					goto contin;
					}
				}
# ifdef YYOPTIM
			else if((int)yyt < (int)yycrank) {		/* r < yycrank */
				yyt = yyr = yycrank+(yycrank-yyt);
# ifdef LEXDEBUG
				if(debug)fprintf(yyout,"compressed state\n");
# endif
				yyt = yyt + yych;
				if(yyt <= yytop && yyt->verify+yysvec == yystate){
					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
						{unput(*--yylastch);break;}
					*lsp++ = yystate = yyt->advance+yysvec;
					goto contin;
					}
				yyt = yyr + YYU(yymatch[yych]);
# ifdef LEXDEBUG
				if(debug){
					fprintf(yyout,"try fall back character ");
					allprint(YYU(yymatch[yych]));
					putchar('\n');
					}
# endif
				if(yyt <= yytop && yyt->verify+yysvec == yystate){
					if(yyt->advance+yysvec == YYLERR)	/* error transition */
						{unput(*--yylastch);break;}
					*lsp++ = yystate = yyt->advance+yysvec;
					goto contin;
					}
				}
			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
# ifdef LEXDEBUG
				if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
# endif
				goto tryagain;
				}
# endif
			else
				{unput(*--yylastch);break;}
		contin:
# ifdef LEXDEBUG
			if(debug){
				fprintf(yyout,"state %d char ",yystate-yysvec-1);
				allprint(yych);
				putchar('\n');
				}
# endif
			;
			}
# ifdef LEXDEBUG
		if(debug){
			fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
			allprint(yych);
			putchar('\n');
			}
# endif
		while (lsp-- > yylstate){
			*yylastch-- = 0;
			if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
				yyolsp = lsp;
				if(yyextra[*yyfnd]){		/* must backup */
					while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
						lsp--;
						unput(*yylastch--);
						}
					}
				yyprevious = YYU(*yylastch);
				yylsp = lsp;
				yyleng = yylastch-yytext+1;
				yytext[yyleng] = 0;
# ifdef LEXDEBUG
				if(debug){
					fprintf(yyout,"\nmatch ");
					sprint(yytext);
					fprintf(yyout," action %d\n",*yyfnd);
					}
# endif
				return(*yyfnd++);
				}
			unput(*yylastch);
			}
		if (yytext[0] == 0  /* && feof(yyin) */)
			{
			yysptr=yysbuf;
			return(0);
			}
		yyprevious = yytext[0] = lex_input();
		if (yyprevious>0)
			lex_output(yyprevious);
		yylastch=yytext;
# ifdef LEXDEBUG
		if(debug)putchar('\n');
# endif
		}
	}

#if defined (__cplusplus) || defined (c_plusplus)
yyback(int * p, int m)
#else
yyback(p, m)
	int *p;
#endif
{
if (p==0) return(0);
while (*p)
	{
	if (*p++ == m)
		return(1);
	}
return(0);
}
	/* the following are only used in the lex library */
yyinput(){
	return(lex_input());
	}

#if defined (__cplusplus) || defined (c_plusplus)
void yyoutput (int c) {
#else
yyoutput(c)
  	int c; {
#endif
	lex_output(c);
	}

#if defined (__cplusplus) || defined (c_plusplus)
void yyunput(int c) {
#else
yyunput(c)
   int c; {
#endif
	unput(c);
	}
