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

📄 _vs1.0_lexer.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void ReplaceMacroParms(char *srcLine, char *destLine, 
							MACROENTRY *srcParms, MACROENTRY *invParms);

MACROTEXT *SaveMacroText(char *srcText, MACROTEXT *lastMacroText);
void FreeMacroEntry(MACROENTRY *macEntry);
void EndMacroParms();
char *FindAlphaNum(char *srcStr, unsigned int *sLen);
void DebugUnhandledState();


unsigned int gCommentStartLine;
unsigned int gMacroStartLine;

char *gCurFileName = NULL;

#define MAXSAVELINE 4095

char gSaveLine[MAXSAVELINE+1];
char gMacroLine[MAXSAVELINE+1];

#if 1
#ifdef _DEBUG
#define ECHO DebugUnhandledState();
#else
#define ECHO
#endif
#endif

bool gbInsideMacro = false;		// flag if we are doing a macro replace or not.
bool gbTempInsideMacro = false;
unsigned int gInvokeState = INITIAL;


MACROENTRY *gParseMacro;		// which source macro entry we are using
MACROENTRY *gTempParseMacro;	// temporary holder until parameters are received.
MACROTEXT *gMacroLineParse;		// which line we are currently parsing inside the macro invocation

typedef enum OPCODETYPE
{
	TYPE_NONE = 0,
	TYPE_VERTEX_SHADER = 1,
	TYPE_PIXEL_SHADER = 2
};
typedef struct OPCODEMAP
{
	char *string;				// string for opcode
	int tokenName;              // name of the corresponding token
	int numArguments;			// number of arguments for opcode
	float version;				// minimum version supported in.
	int opcodeTypeFlags;		// whether opcode can be used in vertex shader or pixel shader
	bool opcodeModify;			// if opcode modifiers can be used
	bool textureOpcode;			// only outputs to the texture unit
} OPCODEMAP;

#ifndef TRUE
#define TRUE true
#endif
#ifndef FALSE
#define FALSE false
#endif

OPCODEMAP theOpcodes[] = {
	{ "add",  ADD_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER | TYPE_PIXEL_SHADER, TRUE, FALSE },
	{ "dp3",  DP3_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER | TYPE_PIXEL_SHADER, TRUE, FALSE },
	{ "dp4",  DP4_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "dst",  DST_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "exp",  EXP_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "expp", EXPP_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "frc",  FRC_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "lit",  LIT_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "log",  LOG_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "logp", LOGP_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "m3x2", M3X2_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "m3x3", M3X3_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "m3x4", M3X4_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "m4x3", M4X3_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "m4x4", M4X4_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "mad",  MAD_INSTR, 4, 1.0f, TYPE_VERTEX_SHADER | TYPE_PIXEL_SHADER, TRUE, FALSE },
	{ "max",  MAX_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "min",  MIN_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "mov",  MOV_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER | TYPE_PIXEL_SHADER, TRUE, FALSE },
	{ "mul",  MUL_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER | TYPE_PIXEL_SHADER, TRUE, FALSE },
	{ "nop",  NOP_INSTR, 0, 1.0f, TYPE_VERTEX_SHADER | TYPE_PIXEL_SHADER, TRUE, FALSE },
	{ "rcp",  RCP_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "rsq",  RSQ_INSTR, 2, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "sge",  SGE_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "slt",  SLT_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER, FALSE, FALSE },
	{ "sub",  SUB_INSTR, 3, 1.0f, TYPE_VERTEX_SHADER | TYPE_PIXEL_SHADER, TRUE, FALSE },
};

#define NUMOPCODES (sizeof(theOpcodes) / sizeof(OPCODEMAP))
OPCODEMAP *FindOpcode(char *findName);


#line 986 "_vs1.0_lexer.cpp"

/* Macros after this point can all be overridden by user definitions in
 * section 1.
 */

#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int yywrap YY_PROTO(( void ));
#else
extern int yywrap YY_PROTO(( void ));
#endif
#endif

#ifndef YY_NO_UNPUT
static void yyunput YY_PROTO(( int c, char *buf_ptr ));
#endif

#ifndef yytext_ptr
static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
#endif

#ifdef YY_NEED_STRLEN
static int yy_flex_strlen YY_PROTO(( yyconst char * ));
#endif

#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput YY_PROTO(( void ));
#else
static int input YY_PROTO(( void ));
#endif
#endif

#if YY_STACK_USED
static int yy_start_stack_ptr = 0;
static int yy_start_stack_depth = 0;
static int *yy_start_stack = 0;
#ifndef YY_NO_PUSH_STATE
static void yy_push_state YY_PROTO(( int new_state ));
#endif
#ifndef YY_NO_POP_STATE
static void yy_pop_state YY_PROTO(( void ));
#endif
#ifndef YY_NO_TOP_STATE
static int yy_top_state YY_PROTO(( void ));
#endif

#else
#define YY_NO_PUSH_STATE 1
#define YY_NO_POP_STATE 1
#define YY_NO_TOP_STATE 1
#endif

#ifdef YY_MALLOC_DECL
YY_MALLOC_DECL
#else
#if __STDC__
#ifndef __cplusplus
#include <stdlib.h>
#endif
#else
/* Just try to get by without declaring the routines.  This will fail
 * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
 * or sizeof(void*) != sizeof(int).
 */
#endif
#endif

/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif

/* Copy whatever the last rule matched to the standard output. */

#ifndef ECHO
/* This used to be an fputs(), but since the string might contain NUL's,
 * we now use fwrite().
 */
#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
#endif

/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 * is returned in "result".
 */
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
	if ( yy_current_buffer->yy_is_interactive ) \
		{ \
		int c = '*', n; \
		for ( n = 0; n < max_size && \
			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
			buf[n] = (char) c; \
		if ( c == '\n' ) \
			buf[n++] = (char) c; \
		if ( c == EOF && ferror( yyin ) ) \
			YY_FATAL_ERROR( "input in flex scanner failed" ); \
		result = n; \
		} \
	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
		  && ferror( yyin ) ) \
		YY_FATAL_ERROR( "input in flex scanner failed" );
#endif

/* No semi-colon after return; correct usage is to write "yyterminate();" -
 * we don't want an extra ';' after the "return" because that will cause
 * some compilers to complain about unreachable statements.
 */
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif

/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif

/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
#endif

/* Default declaration of generated scanner - a define so the user can
 * easily add parameters.
 */
#ifndef YY_DECL
#define YY_DECL int yylex YY_PROTO(( void ))
#endif

/* Code executed at the beginning of each rule, after yytext and yyleng
 * have been set up.
 */
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif

/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK break;
#endif

#define YY_RULE_SETUP \
	if ( yyleng > 0 ) \
		yy_current_buffer->yy_at_bol = \
				(yytext[yyleng - 1] == '\n'); \
	YY_USER_ACTION

YY_DECL
	{
	register yy_state_type yy_current_state;
	register char *yy_cp = NULL, *yy_bp = NULL;
	register int yy_act;

#line 256 "vs1.0_tokens.l"


#line 1143 "_vs1.0_lexer.cpp"

	if ( yy_init )
		{
		yy_init = 0;

#ifdef YY_USER_INIT
		YY_USER_INIT;
#endif

		if ( ! yy_start )
			yy_start = 1;	/* first start state */

		if ( ! yyin )
			yyin = stdin;

		if ( ! yyout )
			yyout = stdout;

		if ( ! yy_current_buffer )
			yy_current_buffer =
				yy_create_buffer( yyin, YY_BUF_SIZE );

		yy_load_buffer_state();
		}

	while ( 1 )		/* loops until end-of-file is reached */
		{
		yy_cp = yy_c_buf_p;

		/* Support of yytext. */
		*yy_cp = yy_hold_char;

		/* yy_bp points to the position in yy_ch_buf of the start of
		 * the current run.
		 */
		yy_bp = yy_cp;

		yy_current_state = yy_start;
		yy_current_state += YY_AT_BOL();
		yy_state_ptr = yy_state_buf;
		*yy_state_ptr++ = yy_current_state;
yy_match:
		do
			{
			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
				{
				yy_current_state = (int) yy_def[yy_current_state];
				if ( yy_current_state >= 329 )
					yy_c = yy_meta[(unsigned int) yy_c];
				}
			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
			*yy_state_ptr++ = yy_current_state;
			++yy_cp;
			}
		while ( yy_base[yy_current_state] != 767 );

yy_find_action:
		yy_current_state = *--yy_state_ptr;
		yy_lp = yy_accept[yy_current_state];
find_rule: /* we branch to this label when backing up */
		for ( ; ; ) /* until we find what rule we matched */
			{
			if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )
				{
				yy_act = yy_acclist[yy_lp];
					{
					yy_full_match = yy_cp;
					break;
					}
				}
			--yy_cp;
			yy_current_state = *--yy_state_ptr;
			yy_lp = yy_accept[yy_current_state];
			}

		YY_DO_BEFORE_ACTION;


do_action:	/* This label is used only to access EOF actions. */


		switch ( yy_act )
	{ /* beginning of action switch */
case 1:
YY_RULE_SETUP
#line 258 "vs1.0_tokens.l"
{
	gbProcessingDefine = false;
	gSaveLine[0] = '\0';
	strncat(gSaveLine, yytext, MAXSAVELINE);
//	GenDebugLine();
	if (gbProcessingIFDEF && (gbCompareDefine != gbIFDEF))
	{
		BEGIN(IFDEFBODY);
	}
	else
	{
		BEGIN(INITIAL);
	}
	yyless(0);
}
	YY_BREAK
case 2:
YY_RULE_SETUP
#line 274 "vs1.0_tokens.l"
{
	gbProcessingDefine = false;
	gSaveLine[0] = '\0';
	strncat(gSaveLine, yytext, MAXSAVELINE);
//	GenDebugLine();
	if (gbProcessingIFDEF && (gbCompareDefine != gbIFDEF))
	{
		BEGIN(IFDEFBODY);
	}
	else
	{
		BEGIN(INITIAL);
	}
	yyless(0);
}
	YY_BREAK
case 3:
YY_RULE_SETUP
#line 290 "vs1.0_tokens.l"
{ 
//	fprintf( stderr, "%s", yytext );
	vs10_lval.reg.type = TYPE_ADDRESS_REG;
	vs10_lval.reg.index = atoi(&yytext[1]);
	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;
	return REGISTER;
}
	YY_BREAK
case 4:
YY_RULE_SETUP
#line 299 "vs1.0_tokens.l"
{ 
//	fprintf( stderr, "%s", yytext );
	vs10_lval.reg.type = TYPE_VERTEX_ATTRIB_REG;
	vs10_lval.reg.index = atoi(&yytext[1]);
	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;
	return REGISTER;
}
	YY_BREAK
case 5:
YY_RULE_SETUP
#line 308 "vs1.0_tokens.l"
{ 
//	fprintf( stderr, "%s", yytext );
	vs10_lval.reg.type = TYPE_TEMPORARY_REG;
	vs10_lval.reg.index = atoi(&yytext[1]);
	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;
	return REGISTER;
}
	YY_BREAK
case 6:
YY_RULE_SETUP
#line 317 "vs1.0_tokens.l"
{ 
//	fprintf( stderr, "%s", yytext );
	vs10_lval.reg.type = TYPE_CONSTANT_MEM_REG;
	vs10_lval.reg.index = atoi(&yytext[1]);
	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;
	return REGISTER;
}
	YY_BREAK
case 7:
YY_RULE_SETUP
#line 326 "vs1.0_tokens.l"
{ 
//	fprintf( stderr, "%s", yytext );
	vs10_lval.reg.type = TYPE_TEXTURE_RESULT_REG;
	vs10_lval.reg.index = atoi(&yytext[2]);
	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;
	return REGISTER;
}
	YY_BREAK
case 8:
YY_RULE_SETUP
#line 335 "vs1.0_tokens.l"
{ 
//	fprintf( stderr, "%s", yytext );
	vs10_lval.reg.type = TYPE_COLOR_RESULT_REG;
	vs10_lval.reg.index = atoi(&yytext[2]);
	if ( yytext[yyleng-1] == '\n' )
		line_incr = 1;
	return REGISTER;
}

⌨️ 快捷键说明

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