⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vs1.0_tokens.l

📁 使用stl技术,(还没看,是听说的)
💻 L
📖 第 1 页 / 共 5 页
字号:
//		newyyin = fopen( incFileName, "r" );

		if ( ! newyyin )
		{
			LexError("Unable to open include file %s\n", incFileName);
			BEGIN(SAVELINE);
		}
		else
		{
			gIncludeStack[gIncludeStackIndex].fileName = gCurFileName;
			gIncludeStack[gIncludeStackIndex].lineNo = yylineno;
//			gIncludeStack[gIncludeStackIndex].fileHandle = yyin;
			gIncludeStack[gIncludeStackIndex].prevString = myin;
			gIncludeStack[gIncludeStackIndex].nextString = newyyin;
			gIncludeStack[gIncludeStackIndex].lastInvokeMacro = gInvokeMacro;
			gIncludeStack[gIncludeStackIndex].lastParseMacro = gParseMacro;
			gIncludeStack[gIncludeStackIndex].lastMacroLineParse = gMacroLineParse;
			gIncludeStack[gIncludeStackIndex].lastbInsideMacro = gbInsideMacro;
			gIncludeStack[gIncludeStackIndex].lastbInsideInclude = gbInsideInclude;
			gIncludeStack[gIncludeStackIndex].buffer = YY_CURRENT_BUFFER;
			gIncludeStack[gIncludeStackIndex].lastbProcessingIFDEF = gbProcessingIFDEF;
			gIncludeStackIndex++;

			gbProcessingIFDEF = false;

			gCurFileName = strdup(incFileName);
//			yyin = newyyin;
			myin = newyyin;

//			GenSwitchFileNames(gCurFileName);

			yylineno = 1;

			yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );

			gbInsideInclude = true;

			BEGIN(SAVELINE);
		}
	}
}

<EATCOMMENT><<EOF>> {
	LexError("End of file reached before end of comment started on line %d.\n", gCommentStartLine);
	BEGIN(INITIAL);
}

<EATCOMMENT>.*\n {
	char *endComment;
	unsigned int keepSize;

	strcpy(gSaveLine, yytext);
	endComment = strstr(yytext, "*/");

	char *cmt;
	if (endComment != NULL)
	{
		keepSize = (endComment - yytext+2);
		yyless(keepSize);
		BEGIN(INITIAL);

		if ( yytext[0] == '/' && yytext[1] == '*' )
		{
			cmt = new char[yyleng];
			strncpy( cmt+3, yytext+2, yyleng-2 );
			cmt[0] = '#';
			cmt[1] = ' ';
			cmt[2] = ' ';
			cmt[yyleng-1] = '\0';
		}
		else
		{
			cmt = new char[yyleng];
			strncpy( cmt+1, yytext, yyleng-2 );
			cmt[0] = '#';
			cmt[yyleng-1] = '\0';
		}
		vs10_lval.comment = cmt;
		return COMMENT;
	}
	else
	{
//		GenDebugLine();
//		GenListString();
		gLinesAssembled++;
		yylineno++;

		if ( yytext[0] == '/' && yytext[1] == '*' )
		{
			cmt = new char[yyleng+2];
			strncpy( cmt+3, yytext+2, yyleng-2 );
			cmt[0] = '#';
			cmt[1] = ' ';
			cmt[2] = ' ';
			cmt[yyleng+1] = '\0';
		}
		else
		{
			cmt = new char[yyleng+2];
			strncpy( cmt+1, yytext, yyleng );
			cmt[0] = '#';
			cmt[yyleng+1] = '\0';
		}
		vs10_lval.comment = cmt;
		return COMMENT;
	}
}

<DEFSTR><<EOF>> {
	LexError("#define was incomplete before end of file\n");
	BEGIN(INITIAL);
}

<DEFINE><<EOF>> {
	LexError("#define was incomplete before end of file\n");
	BEGIN(INITIAL);
}

<DEFSPACE><<EOF>> {
	LexError("#define was incomplete before end of file\n");
	BEGIN(INITIAL);
}

<INCLUDE><<EOF>> {
	LexError("#include was incomplete before end of file\n");
	BEGIN(INITIAL);
}

<MACROBODY><<EOF>> {
	LexError("End of file reached before end of #define or endm was found, macro started on line %d.\n", gMacroStartLine);
	BEGIN(INITIAL);
}

<IFDEFBODY><<EOF>> {
	LexError("End of file reached before #endif found, macro started on line %d.\n", gIfDefStartLine);
	BEGIN(INITIAL);
}

<DEFSTR>\n {
	LexError("#define was incomplete before end of line\n");
	BEGIN(SAVELINE);
//	GenDebugLine();
//	GenListString();
	gLinesAssembled++;
	yylineno++;
}

<DEFINE>\n {
	LexError("#define was incomplete before end of line\n");
	BEGIN(SAVELINE);
//	GenDebugLine();
//	GenListString();
	gLinesAssembled++;
	yylineno++;
}

<DEFSPACE>\n {
	LexError("#define was incomplete before end of line\n");
	BEGIN(SAVELINE);
//	GenDebugLine();
//	GenListString();
	gLinesAssembled++;
	yylineno++;
}

"#ifdef"[ \t]+ {
	if (gIfDefStackIndex >= MAX_IFDEF_DEPTH)
	{
		LexError("Out of stack space for #ifdef, aborting.\n");
		exit( 1 );
	}
	else
	{
		gIfDefStack[gIfDefStackIndex].lastbProcessingIFDEF = gbProcessingIFDEF;
		gIfDefStack[gIfDefStackIndex].lastbIFDEF = gbIFDEF;
		gIfDefStack[gIfDefStackIndex].lastbCompareDefine = gbCompareDefine;
		gIfDefStack[gIfDefStackIndex].lastIfDefStartLine = gIfDefStartLine;
		gIfDefStackIndex++;
		gIfDefStartLine = yylineno;

		gbCompareDefine = true;
		BEGIN(IFDEFNAME);
	}
}

"#ifndef"[ \t]+ {
	if (gIfDefStackIndex >= MAX_IFDEF_DEPTH)
	{
		LexError("Out of stack space for #ifdef, aborting.\n");
		exit( 1 );
	}
	else
	{
		gIfDefStack[gIfDefStackIndex].lastbProcessingIFDEF = gbProcessingIFDEF;
		gIfDefStack[gIfDefStackIndex].lastbIFDEF = gbIFDEF;
		gIfDefStack[gIfDefStackIndex].lastbCompareDefine = gbCompareDefine;
		gIfDefStack[gIfDefStackIndex].lastIfDefStartLine = gIfDefStartLine;
		gIfDefStackIndex++;
		gIfDefStartLine = yylineno;

		gbCompareDefine = false;
		BEGIN(IFDEFNAME);
	}
}

<INITIAL,IFDEFBODY>"#else"[ \t]*((";"|"//").*)* {
	if (!gbProcessingIFDEF)
	{
		LexError("Unexpected #else found at line %d, skipping.\n", yylineno);
	}
	else
	{
		gbCompareDefine = !gbCompareDefine;
		BEGIN(INITIAL);
	}
}

<IFDEFNAME>.*\n {
	char *defineName;
	unsigned int sLen;


	defineName = FindAlphaNum(yytext, &sLen);
	if (defineName == NULL)
	{
		defineName = strdup(yytext);
		defineName[yyleng-1] = '\0';	// kill \n
		LexWarning("Mangled name (%s) for #ifdef, assuming not defined.\n", defineName);
		free(defineName);
		gbIFDEF = false;
	}
	else
	{
		if (FindNMacro(defineName, sLen) != NULL)
		{
			gbIFDEF = true;
		}
		else
		{
			gbIFDEF = false;
		}
	}

	gbProcessingIFDEF = true;
	if (gbIFDEF != gbCompareDefine)
	{
		BEGIN(IFDEFBODY);
	}
	else
	{
		BEGIN(SAVELINE);
	}

//	GenDebugLine();
//	GenListString();
	gLinesAssembled++;
	yylineno++;
}

<INITIAL,IFDEFBODY>[ \t]*"#endif"[ \t]*((";"|"//").*)* {
	if (!gbProcessingIFDEF)
	{
		LexError("Unexpected #endif found at line %d, skipping.\n", yylineno);
	}
	else
	{
		gIfDefStackIndex--;
		gbProcessingIFDEF = gIfDefStack[gIfDefStackIndex].lastbProcessingIFDEF;
		gbIFDEF = gIfDefStack[gIfDefStackIndex].lastbIFDEF;
		gbCompareDefine = gIfDefStack[gIfDefStackIndex].lastbCompareDefine;
		gIfDefStartLine = gIfDefStack[gIfDefStackIndex].lastIfDefStartLine;

	}

	if (YYSTATE == IFDEFBODY)
	{
		strncpy(gSaveLine, yytext, MAXSAVELINE);
	}

	BEGIN(ENDMACRO);

}

<ENDMACRO>.* {
	LexWarning("Garbage at end of #endif or endm will be ignored.\n");
}

<ENDMACRO>\n {
	BEGIN(SAVELINE);
	return '\n';
}

<ENDMACRO><<EOF>> {
	BEGIN(INITIAL);
}

<IFDEFBODY>.* {
	// eat line, because we are not in a TRUE #ifdef, or FALSE #ifndef
	strncpy(gSaveLine, yytext, MAXSAVELINE);
}

<IFDEFBODY>\n {
	strcat(gSaveLine, yytext);
//	GenDebugLine();
//	GenListString();
	yylineno++;
	gLinesAssembled++;
}

"#define"[ \t]+   { 
	gbProcessingDefine = true;
	gMacroStartLine = yylineno;
	gCountParen = 0;
	BEGIN(MACRONAME); 
} 

<SKIPLINE>.*\n	{
	BEGIN(SAVELINE);
//	GenDebugLine();
//	GenListString();
	gLinesAssembled++;
	yylineno++;
}

"vs."{digits}"."{digits}[ \t]*[\n]? {
//	unsigned int majorVersion;
//	unsigned int minorVersion;
//	int minorOffset;
//	
//
//	majorVersion = (unsigned int)(atoi(&yytext[3]));
//	// skip "ps." + second '.'
//	minorOffset = strcspn(&yytext[3], ".")+4;
//	minorVersion = (unsigned int)(atoi(&yytext[minorOffset]));
//	yylval.ival = D3DVS_VERSION(majorVersion, minorVersion);
//

//	fprintf( stderr, "%s", yytext );
	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;
	return VERTEX_SHADER;
}

{digits}	{ 
//	fprintf( stderr, "%s", yytext );
	vs10_lval.ival = atoi(yytext);
	return INTVAL;
}


{pt} { 
		BEGIN(MODIFIER);
//fprintf( stderr, "." );
		return yytext[0];
}

<MODIFIER>[w-z][w-z][w-z][w-z][ \t]*[\n]? {
//	fprintf( stderr, "%s", yytext );
	BEGIN(INITIAL);

	vs10_lval.mask[0] = tolower(yytext[0]);
	vs10_lval.mask[1] = tolower(yytext[1]);
	vs10_lval.mask[2] = tolower(yytext[2]);
	vs10_lval.mask[3] = tolower(yytext[3]);

	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;

	return XYZW_MODIFIER;

#if 0
 	char temp[6];

	temp[0] = '\0';
	strncat(temp, yytext, 4);
	strlwr(temp);
	vs10_lval.lval = FindSwizzleValue(temp);

	BEGIN(INITIAL);
	return SWIZZLE_MODIFIER;
#endif

}

<MODIFIER>[w-z][w-z]?[w-z]?[w-z]?[ \t]*[\n]? {
//	fprintf( stderr, "%s", yytext );
	BEGIN(INITIAL);

	int validLen = strspn(yytext, "xyzw");
        int i;
	for ( i = 0; i < validLen; i++ )
		vs10_lval.mask[i] = tolower( yytext[i] );
	while ( i < 4 )
	{
		vs10_lval.mask[i] = 0;
		i++;
	}

	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;

	return XYZW_MODIFIER;

#if 0
 	//char temp[6];
 	char *temp = new char[6];
	unsigned int registerMask;
	unsigned int validLen;

	temp[0] = '\0';
	validLen = strspn(yytext, "xyzw");
	strncat(temp, yytext,  validLen);
	for ( int i = 0; i < validLen; i++ )
		temp[i] = tolower( temp[i] );
	registerMask = MakeRegisterMask(temp);

	if (registerMask != 0)
	{
		//vs10_lval.sval = temp;
		vs10_lval.lval = registerMask;
		BEGIN(INITIAL);
		return XYZW_MODIFIER;
	}
	else
	{
		//vs10_lval.sval = temp;
		vs10_lval.lval = FindSwizzleValue(temp);
		BEGIN(INITIAL);
		return SWIZZLE_MODIFIER;	
	}
#endif
}

<MODIFIER>. {
		BEGIN(INITIAL);
		yyless(0);
}

<MACRONAME>[^ \t(]+ {
	/* setup and save off #define/macro name */
	if (FindMacro(yytext) != NULL)
	{
		LexWarning("Redefinition of #define/macro %s, ignoring.\n", yytext);
		if (gbProcessingDefine)
		{
			BEGIN(EATDEFINE);
		}
		else
		{
			BEGIN(EATMACRO);
		}
	}
	else
	{

		BEGIN(MACROPARMSTART);
		// %%%%% This should be setup to use memory pools
		gTempMacro = (MACROENTRY *)malloc(sizeof(MACROENTRY));
		if (gTempMacro == NULL)
		{
			LexError("Out of memory for macro table.\n");
			if (gbProcessingDefine)
			{
				BEGIN(EATDEFINE);
			}
			else
			{
				BEGIN(EATMACRO);
			}
		}
		else
		{
			gTempMacro->prev = gLastMacro;
			gTempMacro->next = NULL;

			gTempMacro->firstMacroParms = NULL;
			gTempMacro->lastMacroParms = NULL;
			gTempMacro->firstMacroLines = NULL;
			gTempMacro->lastMacroLines = NULL;
			gTempMacro->numParms = 0;
			gTempMacro->bIsDefine = gbProcessingDefine;
			gTempMacro->nLines = 0;

			if (gCurFileName != NULL)
			{
				gTempMacro->fileName = strdup(gCurFileName);
			}
			else
			{
				gTempMacro->fileName = NULL;
			}

			gTempMacro->lineNo = yylineno;

			/* %%%%% this should be set up in memory pools. */
			gTempMacro->macroName = (char *)malloc(strlen(yytext)+1);
			if (gTempMacro->macroName == NULL)
			{
				LexError("Out of memory for string table.\n");
				SAFEFREE(gTempMacro);
				if (gbProcessingDefine)
				{
					BEGIN(EATDEFINE);
				}
				else
				{
					BEGIN(EATMACRO);
				}
			}
			else
			{
				strcpy(gTempMacro->macroName, yytext);
			}
		}
	}
}

<MACRONAME>\n {
	LexError("No macro name specified, skipping macro definition.\n");
	SAFEFREE(gTempMacro->fileName);
	SAFEFREE(gTempMacro);
	if (gbProcessingDefine)
	{
		BEGIN(EATDEFINE);
	}
	else
	{
		BEGIN(EATMACRO);
	}

//	GenDebugLine();
//	GenListString();
	gLinesAssembled++;
	yylineno++;
}

<MACROPARMSTART>"(" {
	gCountParen++; 
}

<MACROPARMSTART>[ \t]+ {}

<MACROPARMSTART>. {
	if (gbProcessingDefine && (gCountParen == 0))
	{
		EndMacroParms();
	}
	else
	{
		BEGIN(MACROPARM);
	}
	yyless(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -