コード例 #1
0
ファイル: reject.c プロジェクト: carriercomm/plan9-gpl
int
yyracc(int m)
{

	yyolsp = yylsp;
	if(yyextra[m]) {
		while(yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) {
			yylsp--;
			yyunput(yytext[--yyleng]);
		}
	}
	yyprevious = yytext[yyleng-1];
	yytext[yyleng] = 0;
	return m;
}
コード例 #2
0
ファイル: proplex.c プロジェクト: ombt/ombt
yylook()
#endif
{
	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;
				}
#ifndef __cplusplus
			*yylastch++ = yych = input();
#else
			*yylastch++ = yych = lex_input();
#endif
			if(yylastch > &yytext[YYLMAX]) {
				fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
				exit(1);
			}
			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;
					if(lsp > &yylstate[YYLMAX]) {
						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
						exit(1);
					}
					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;
					if(lsp > &yylstate[YYLMAX]) {
						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
						exit(1);
					}
					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;
					if(lsp > &yylstate[YYLMAX]) {
						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
						exit(1);
					}
					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);
			}
#ifndef __cplusplus
		yyprevious = yytext[0] = input();
		if (yyprevious>0)
			output(yyprevious);
#else
		yyprevious = yytext[0] = lex_input();
		if (yyprevious>0)
			lex_output(yyprevious);
#endif
		yylastch=yytext;
# ifdef LEXDEBUG
		if(debug)putchar('\n');
# endif
		}
	}
コード例 #3
0
ファイル: yacc.c プロジェクト: Aliandrana/cc65
yylook()
{
	register struct yysvf *yystate, **lsp;
	register struct yywork *yyt;
	struct yysvf *yyz;
	int yych;
	struct yywork *yyr;
/*
# ifdef LEXDEBUG
	int debug;
# endif
*/
	
	char *yylastch;
	
	/* start off machines */

/*
# ifdef LEXDEBUG
	debug = 1;
# else
	debug = 0;
# endif
*/

# ifdef LEXDEBUG
#define debug 1
# else
#define debug 0
#endif
	
#ifdef YYDEBUG
	fprintf(yyout,"yylook()\n");
# endif
	
	if (!yymorfg)
		yylastch = yytext;
	else
	{
		yymorfg=0;
		yylastch = yytext+yyleng;
	}

#ifdef YYDEBUG
	fprintf(yyout,"yylook: yymorfg=%d\n",yymorfg);
# endif
		
	for(;;)
	{
#ifdef YYDEBUG
		fprintf(yyout,"yylook:  (outer loop)");
		printchar("yyprevious",yyprevious);
# endif
		lsp = yylstate;
		yyestate = yystate = yybgin;
		if (yyprevious==YYNEWLINE) yystate++;

		testbreak=0;
		
		for (;;)
		{
# ifdef LEXDEBUG
			fprintf(yyout,"yylook:   (inner loop) state %d\n",yystate-yysvec-1);
# endif
			if(testbreak==5)
			{
				fprintf(yyout,"yylook:   error, aborted after 5 loops\n");
				exit(0);
			}
			testbreak++;
			
			yyt = yystate->yystoff;

/*			fprintf(yyout,"yylook:   yyt offs: %02x\n",yyt-yycrank); */

			
			if(yyt == yycrank)
			{		/* may not be any transitions */
				yyz = yystate->yyother;
				if(yyz == 0)break;
				if(yyz->yystoff == yycrank)break;
			}
			*yylastch++ = yych = input();

# ifdef LEXDEBUG
			fprintf(yyout,"yylook:   input ");
			printchar("yych",yych);
# endif
			
		tryagain:

# ifdef LEXDEBUG
/*			fprintf(yyout,"yylook:   yych=%02x yymatch[yych]=%02x\n",yych,yymatch[yych]); */
			fprintf(yyout,"yylook:   tryagain\n");
# endif
			yyr = yyt;

/*			fprintf(yyout,"yylook:   yyr offs: %02x\n",yyr-yycrank); */
			
			if ( yyt > yycrank)
			{
				yyt = yyr + yych;
				if (yyt <= yytop && yyt->verify+yysvec == yystate)
				{
					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
					{
# ifdef LEXDEBUG
						fprintf(yyout,"yylook:   unput (1) ");
						printchar("*yylastch",*yylastch);
# endif
						unput(*--yylastch);
						break;
					}
					*lsp++ = yystate = yyt->advance+yysvec;
# ifdef LEXDEBUG
					fprintf(yyout,"yylook:   continue (1)\n");
# endif
					goto contin;
				}
# ifdef LEXDEBUG
				fprintf(yyout,"yylook:   ( yyt > yycrank)\n");
# endif
			}
# ifdef YYOPTIM
			else if(yyt < yycrank) /* r < yycrank */
			{		
				yyt = yyr = yycrank+(yycrank-yyt);
# ifdef LEXDEBUG
				fprintf(yyout,"yylook:   compressed state\n");
# endif
				yyt = yyt + yych;
				if(yyt <= yytop && yyt->verify+yysvec == yystate)
				{
# ifdef LEXDEBUG
					fprintf(yyout,"yylook:   (1)\n");
# endif
					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
					{
# ifdef LEXDEBUG
						fprintf(yyout,"yylook:   unput (2) ");
						printchar("*yylastch",*yylastch);
# endif
						unput(*--yylastch);
						break;
					}
					*lsp++ = yystate = yyt->advance+yysvec;
# ifdef LEXDEBUG
					fprintf(yyout,"yylook:   continue (2)\n");
# endif
					goto contin;
					
				}
# ifdef LEXDEBUG
/*
				fprintf(yyout,"yylook:   yych=%02x yymatch[yych]=%02x\n",yych,yymatch[yych]);
				fprintf(yyout,"yylook:   yyt offs: %02x\n",yyt-yycrank);
				fprintf(yyout,"yylook:   yyr offs: %02x\n",yyr-yycrank);
*/
# endif
				yyt = yyr + YYU(yymatch[yych]);
# ifdef LEXDEBUG
/*
				fprintf(yyout,"yylook:   yyt offs: %02x <= yytop offs: %02x\n",yyt-yycrank,yytop-yycrank);
				fprintf(yyout,"yylook:   yyt->verify=%04x yysvec=%04x (yyt->verify+yysvec)=%04x == yystate=%04x\n",yyt->verify,yysvec,(yyt->verify+yysvec),yystate);
*/
				fprintf(yyout,"yylook:   try fall back character\n");
# endif
				if(yyt <= yytop && yyt->verify+yysvec == yystate) 
				{
# ifdef LEXDEBUG
					fprintf(yyout,"yylook:   (2a)\n");
# endif
					
					if(yyt->advance+yysvec == YYLERR)	/* error transition */
					{
# ifdef LEXDEBUG
/* cc65 compiles this ?!						fprintf(yyout,"yylook:   unput (3) ",); */
						fprintf(yyout,"yylook:   unput (3) ");
						printchar("*yylastch",*yylastch);
# endif
						unput(*--yylastch);
						break;
					}
					*lsp++ = yystate = yyt->advance+yysvec;
# ifdef LEXDEBUG
/*					fprintf(yyout,"yylook:   yyt offs: %02x yyt->advance=%d\n",yyt-yycrank,yyt->advance); */
					fprintf(yyout,"yylook:   continue (3)\n");
# endif
					goto contin;
					
				}
# ifdef LEXDEBUG
				fprintf(yyout,"yylook:   (2)\n");
# endif
			}
			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank)
			{
# ifdef LEXDEBUG
				fprintf(yyout,"yylook:   fall back to state %d\n",yystate-yysvec-1);
# endif
				goto tryagain;
			}
# endif
			else
			{
# ifdef LEXDEBUG
				fprintf(yyout,"yylook:   unput (4) ");
				printchar("*yylastch",*yylastch);
# endif
				unput(*--yylastch);
				break;
			}
		contin:
# ifdef LEXDEBUG
			fprintf(yyout,"yylook:   contin state=%d\n",yystate-yysvec-1);
# endif
			;
		}

# ifdef LEXDEBUG
		if((*(lsp-1)-yysvec-1)<0)
		{
			fprintf(yyout,"yylook:  stopped (end)\n");
		}
		else
		{
			fprintf(yyout,"yylook:  stopped at %d with\n",*(lsp-1)-yysvec-1);
		}
# 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--;
# ifdef LEXDEBUG
						fprintf(yyout,"yylook:   unput (5) ");
						printchar("*yylastch",*yylastch);
# endif
						unput(*yylastch--);
					}
				}
				yyprevious = YYU(*yylastch);
				yylsp = lsp;
				yyleng = yylastch-yytext+1;
				yytext[yyleng] = 0;
# ifdef LEXDEBUG
				fprintf(yyout,"\nyylook:  match action %d\n",*yyfnd);
				fprintf(yyout,"yylook:  done loops: %d\n",testbreak);
# endif
				return(*yyfnd++);
			}
			unput(*yylastch);
		}
		if (yytext[0] == 0  /* && feof(yyin) */)
		{
			yysptr=yysbuf;
# ifdef LEXDEBUG
			fprintf(yyout,"yylook:  done loops: %d\n",testbreak);
# endif
			return(0);
		}
		yyprevious = yytext[0] = input();

# ifdef LEXDEBUG
		fprintf(yyout,"yylook:   input ");
		printchar("yyprevious",yyprevious);
# endif

		if (yyprevious>0)
			output(yyprevious);
		yylastch=yytext;
# ifdef LEXDEBUG
/*		if(debug)putchar('\n'); */
# endif
	}

# ifdef LEXDEBUG
	fprintf(yyout,"yylook: done loops: %d\n",testbreak);
	fprintf(yyout,"yylook: return <void>\n");
# endif
}
コード例 #4
0
ファイル: yycclex.cpp プロジェクト: EASEA/EASEAudioMonitor
int yyclexer::yylex()
{
	while (1) {
		int state = 1 + yystart;
		if (yyeol) {
			state++;
		}
	
		// yymore
		if (yymoreflg) {
			yymoreflg = 0;		// clear flag
		}
		else {
			yyleng = 0;
			yyoldeol = yyeol;
		}
		int oldleng = yyleng;

		// look for a string
		do {
			// get input character (lookahead character)
			int ch = yyinput();
			yyassert(ch >= 0 && ch <= UCHAR_MAX || ch == EOF);
			if (ch == EOF) {
				break;
			}
			
			// check for possible overflow
			if (yyleng == yytext_size) {
				do {
					if (yytextgrow) {
						if (yytext_size != 0) {
							int size = yytext_size * 2;
							if (size / 2 == yytext_size) {		// overflow check
								if (yysettextsize(size)) {
									break;
								}
							}
						}
						else {
							if (yysettextsize(100)) {
								break;
							}
						}
					}
					yytextoverflow();
					exit(EXIT_FAILURE);
				}
				while (0);
			}

			// look for a transition
			int index = yystate[state].base;
			while (1) {
				if (yyctransition[index].next == 0) {
					state = yystate[state].def;
					if (state <= 0) {
						if (state < 0) {
							if (ch >= 0 && ch <= 0xff) {
								state = -state;
							}
							else {
								state = 0;
							}
						}
						break;
					}
				}
				if (ch >= yyctransition[index].first &&
					ch <= yyctransition[index].last) {
					state = yyctransition[index].next;
					break;
				}
				index++;
			}

			int leng = yyleng;		// slightly more efficient code
			yytext[leng] = (char)ch;
			yystatebuf[leng] = state;
			leng++;
			yyleng = leng;
		}
		while (state != 0 && (yystate[state].def != 0 || yystate[state].base != 0));

		// now find a match
		if (yyleng > oldleng) {
			int rejectmatch = 0;
			while (1) {
				int match = yystate[yystatebuf[yyleng - 1]].match;
				if (rejectmatch != 0) {
					if (match < 0) {
						int index = -match;
						do {
							match = yymatch[index++];
						}
						while (match > 0 && match <= rejectmatch);
					}
					else {
						if (match == rejectmatch) {
							match = 0;
						}
					}
					rejectmatch = 0;
				}
				else {
					if (match < 0) {
						match = yymatch[-match];
					}
				}
				if (match > 0) {
					// check for backup
					if (yybackup[match]) {
						while (yyleng > oldleng) {
							int index = yystate[yystatebuf[yyleng - 1]].match;
							if (index < 0) {
								if (yyback(&yymatch[-index], -match)) {
									break;	// found an expression
								}
							}
							yyleng--;
							yyunput((unsigned char)yytext[yyleng]);
						}
					}
					yytext[yyleng] = '\0';
#ifdef YYDEBUG
					yydmatch(match);
#endif
					yyrejectflg = 0;		// clear flag
					int rejectleng = yyleng;

					if (yyleng > 0) {
						yyeol = (unsigned char)(yytext[yyleng - 1] == '\n');
					}
					else {
						yyeol = yyoldeol;
					}

					// perform user action
					int token = yyaction(match);

					if (yyreturnflg) {
						return token;
					}
					if (!yyrejectflg) {
						break;
					}
					if (rejectleng == yyleng) {
						rejectmatch = match;
					}
				}
				else if (yyleng > oldleng + 1) {
					yyleng--;
					yyunput((unsigned char)yytext[yyleng]);
				}
				else {
					yyeol = (unsigned char)(yytext[0] == '\n');
					yyoutput(yytext[0]);	// non-matched character
					break;
				}
			}
		}
		else {
			yyassert(yyleng == oldleng);

			// handles <<EOF>> rules
			int index = 0;
			int match = yystate[state].match;
			if (match < 0) {
				index = -match;
				match = yymatch[index++];
			}
			while (match > 0) {
				yytext[yyleng] = '\0';
#ifdef YYDEBUG
				yydmatch(match);
#endif
				yyrejectflg = 0;		// clear flag

				// perform user action
				int token = yyaction(match);

				if (yyreturnflg) {
					return token;
				}
				if (!yyrejectflg) {
					break;
				}

				if (index == 0) {
					break;
				}
				match = yymatch[index++];
			}

			if (yywrap()) {
				yyoldeol = 1;
				yyeol = 1;
				yystart = 0;
				return 0;			// eof reached
			}
		}
	}
}