コード例 #1
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
		}
	}
コード例 #2
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
}