_vs1.0_lexer.cpp

来自「赫赫大名的 OGRE 游戏引擎」· C++ 代码 · 共 2,221 行 · 第 1/5 页

CPP
2,221
字号
      767,  767,  767,    0,  737,  767,    0,    0,  718,  191,
      767,  185,  195,  178,    0,  736,  767,  767,  724,  725,
      732,  198,  767,  199,  200,  767,  201,  767,    0,  211,

      767,  732,  767,  730,  767,    0,  213,  767,  706,    0,
      767,  217,  221,  705,  704,  175,  201,  232,  767,  767,
        0,  715,    0,  234,    0,  237,  239,  241,  243,  245,
      255,  268,  270,  277,  281,  726,  272,  724,  767,  723,
      767,  722,  767,    0,  721,  767,    0,  702,  285,  283,
      228,  701,  291,  767,   43,    0,  719,  709,  708,    0,
      715,  767,  293,  222,  295,  206,  767,  208,  767,  298,
      767,  300,  715,  713,  767,    0,  303,  689,  232,    0,
      308,  711,  700,  709,  294,  679,  683,  674,  683,  282,
      683,    0,  767,    0,  314,  767,  322,  767,  324,  328,

      330,  332,  339,  334,  767,  341,  767,  692,  703,  297,
       82,  345,  672,  668,  675,  692,  767,  661,  659,  651,
      644,  640,  630,  355,  767,  357,  767,  360,  767,  366,
      368,  370,  372,  767,  374,  767,  376,  767,  254,  378,
      379,  383,  629,  606,  599,  381,  603,  598,  593,  558,
      395,  767,  398,  767,  400,  767,  402,  767,  404,  767,
      502,  406,  374,  396,  410,  767,  412,  767,  416,  453,
      439,  420,  445,  336,  421,  452,  423,  395,  422,  767,
      435,  767,  437,  767,  439,  430,  431,  434,  454,  446,
      403,  351,  458,  408,  413,  417,  449,  461,  376,  453,

      353,  343,  314,  475,  767,  466,  480,  457,  471,  475,
      483,  309,  476,  311,  479,  484,  487,  490,  250,  162,
      491,  494,  495,  498,  499,  115,  502,  767,  517,  522,
      527,  532,  537,  542,  547,  552,  557,  562,  567,  572,
      577,  582,  587,  592,   95,   89,  597,  602,  607,   40,
      612,  617,  622,  627,  632,  637,  642,  647,  652,  657,
      662,  667,  672,  677,  682,  687,  692,  697
    } ;

static yyconst short int yy_def[369] =
    {   0,
      328,    1,  329,  329,  330,  330,  330,  330,  330,  330,
      331,  331,  332,  332,  333,  333,  334,  334,  335,  335,
      336,  336,  337,  337,  338,  338,  339,  339,  328,   29,
      340,  340,  341,  341,  342,  342,  343,  343,  330,  330,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  344,  345,  346,  345,  345,  345,  345,  345,  328,
      328,  347,  328,  328,  328,  328,  348,  328,  349,  328,
      328,  328,  328,  350,  351,  328,  352,  352,  353,  353,
      328,  353,  353,  353,  354,  354,  328,  328,  354,  355,
      356,  356,  328,  356,  357,  328,  357,  328,  346,  346,

      328,  328,  328,  358,  328,  359,  359,  328,  359,  360,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      361,  328,  344,  345,  346,  345,  345,  345,  345,  345,
      345,  345,  345,  345,  328,  328,  328,  347,  328,  348,
      328,  349,  328,  350,  351,  328,  352,  353,  353,  353,
      353,  353,  353,  328,  353,  354,  354,  355,  355,  362,
      356,  328,  356,  356,  356,  357,  328,  357,  328,  328,
      328,  346,  328,  358,  328,  359,  359,  359,  359,  360,
      328,  328,  328,  363,  328,  328,  328,  328,  328,  328,
      328,  361,  328,  346,  328,  328,  328,  328,  345,  345,

      345,  345,  345,  328,  328,  328,  328,  328,  328,  353,
      356,  346,  359,  359,  359,  363,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  345,
      345,  345,  328,  328,  328,  328,  328,  328,  328,  353,
      356,  346,  359,  359,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  353,  353,  364,  356,  328,  328,  328,  359,  359,
      328,  328,  328,  365,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  364,  364,  364,  364,  359,
      359,  366,  359,  328,  365,  365,  365,  328,  328,  367,

      328,  328,  328,  328,  328,  364,  364,  366,  366,  366,
      359,  359,  368,  328,  365,  367,  367,  367,  328,  328,
      366,  368,  368,  368,  367,  328,  368,    0,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328
    } ;

static yyconst short int yy_nxt[807] =
    {   0,
       42,   43,   44,   45,   46,   47,   47,   47,   47,   48,
       47,   49,   50,   51,   52,   53,   53,   53,   53,   53,
       45,   54,   55,   56,   53,   53,   53,   53,   53,   53,
       53,   53,   57,   58,   53,   53,   53,   59,   53,   60,
       63,   78,   92,   93,  144,   63,   96,   61,   71,   71,
       72,   73,   73,   73,   73,   73,   73,   73,   73,   73,
       73,  120,   73,  149,   97,  121,   94,  210,   73,   71,
       71,   72,   73,   73,   73,   73,   73,   73,   73,   73,
       73,   73,   96,   73,  162,   63,   78,   80,   81,   73,
       63,   80,   81,  125,   86,   87,   92,   93,   82,  124,

       97,  113,   82,   88,  114,   89,   83,   90,   86,   87,
       83,   84,  241,  102,   63,   84,  326,   88,  103,   89,
       94,   90,   98,   98,   63,   98,   98,   98,   98,   98,
       98,   98,   98,   98,   98,   98,   98,   99,   99,   99,
       99,   99,   98,   99,   99,   99,   99,   99,   99,   99,
       99,   99,   99,   99,   99,   99,   99,   99,   99,   99,
      100,  102,   63,  326,  107,  108,  103,  109,  107,  108,
      126,  109,  115,  116,  118,  119,  117,  127,  125,  128,
      129,  130,  131,  132,  125,  125,  133,  135,  137,  119,
      114,  125,  150,  152,  125,  136,  153,  154,  149,  163,

      162,  162,  167,  169,  188,  149,  189,  134,  167,  155,
      169,  149,  170,  171,  177,  149,  151,  178,  181,  182,
      168,  168,  113,  164,  162,  114,  168,  190,  168,  183,
      165,  184,  191,  118,  119,  193,  193,  185,  195,  196,
      197,  198,  193,  193,  193,  193,  193,  193,  149,  172,
      126,  319,  127,  165,  199,  194,  193,  193,  194,  155,
      194,  214,  194,  215,  194,  261,  194,  239,  203,  204,
      205,  206,  207,  137,  119,  200,  194,  201,  193,  193,
      202,  132,  135,  133,  150,  114,  153,  154,  208,  194,
      136,  194,  153,  154,  163,  162,  182,  162,  194,  170,

      171,  170,  171,  149,  177,  149,  221,  178,  151,  181,
      182,  149,  314,  222,  185,  224,  225,  149,  164,  211,
      183,  313,  184,  226,  227,  228,  229,  240,  185,  193,
      193,  193,  193,  193,  193,  235,  236,  199,  212,  320,
      233,  234,  237,  238,  319,  194,  170,  171,  296,  194,
      297,  194,  203,  194,  301,  230,  224,  225,  226,  227,
      194,  251,  252,  309,  231,  310,  232,  253,  254,  255,
      256,  257,  258,  259,  260,  235,  236,  237,  238,  262,
      265,  266,  272,  242,  267,  268,  264,  194,  300,  194,
      263,  194,  264,  273,  149,  274,  251,  252,  149,  279,

      280,  281,  282,  283,  284,  259,  260,  262,  287,  314,
      288,  265,  266,  267,  268,  292,  289,  290,  263,  303,
      264,  272,  298,  279,  280,  296,  149,  297,  291,  315,
      292,  297,  273,  299,  274,  300,  281,  282,  283,  284,
      304,  305,  287,  306,  288,  288,  287,  290,  288,  302,
      289,  289,  285,  301,  289,  307,  154,  274,  291,  311,
      292,  296,  298,  297,  294,  317,  287,  318,  288,  309,
      312,  310,  313,  299,  289,  300,  304,  305,  306,  293,
      288,  307,  154,  321,  311,  310,  289,  309,  323,  310,
      324,  315,  287,  297,  288,  312,  317,  313,  318,  325,

      289,  318,  317,  321,  318,  310,  323,  327,  324,  324,
      323,  325,  324,  318,  327,  285,  324,   62,   62,   62,
       62,   62,   63,   63,   63,   63,   63,   67,   67,   67,
       67,   67,   69,   69,   69,   69,   69,   74,   74,   74,
       74,   74,   75,   75,   75,   75,   75,   77,   77,   77,
       77,   77,   79,   79,   79,   79,   79,   85,   85,   85,
       85,   85,   91,   91,   91,   91,   91,   95,   95,   95,
       95,   95,  101,  101,  101,  101,  101,  104,  104,  104,
      104,  104,  106,  106,  106,  106,  106,  110,  110,  110,
      110,  110,  123,  123,  278,  123,  123,  138,  138,  138,

      138,  138,  140,  140,  140,  140,  140,  142,  142,  142,
      142,  142,  145,  145,  145,  145,  145,  147,  277,  147,
      147,  147,  148,  148,  276,  148,  148,  156,  156,  275,
      271,  156,  159,  159,  270,  159,  159,  161,  161,  161,
      161,  161,  166,  166,  166,  166,  166,  174,  174,  174,
      174,  174,  176,  176,  269,  176,  176,  180,  180,  250,
      180,  180,  192,  192,  249,  192,  192,  160,  160,  248,
      160,  160,  216,  216,  216,  216,  216,  286,  286,  247,
      286,  286,  295,  295,  246,  295,  295,  308,  308,  245,
      308,  308,  316,  316,  217,  316,  316,  322,  322,  244,

      322,  322,  243,  215,  209,  239,  223,  220,  219,  218,
      189,  217,  184,  182,  213,  175,  173,  162,  160,  160,
      157,  149,  149,  146,  143,  141,  139,  209,  122,  187,
      186,  179,  175,  173,  162,  160,  158,  157,  149,  146,
      143,  141,  139,  125,  122,  328,  112,  112,  111,  111,
      105,  105,   76,   76,   70,   70,   68,   68,   66,   66,
       65,   65,   64,   64,   63,   63,   41,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,

      328,  328,  328,  328,  328,  328
    } ;

static yyconst short int yy_chk[807] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    2,
       19,   19,   25,   25,  350,   19,   27,    2,   15,   15,
       15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
       15,   50,   15,  155,   27,   50,   25,  155,   15,   16,
       16,   16,   16,   16,   16,   16,   16,   16,   16,   16,
       16,   16,   28,   16,  211,   20,   20,   21,   21,   16,
       20,   22,   22,  346,   23,   23,   26,   26,   21,  345,

       28,   43,   22,   23,   43,   23,   21,   23,   24,   24,
       22,   21,  211,   31,   31,   22,  326,   24,   31,   24,
       26,   24,   29,   29,   29,   29,   29,   29,   29,   29,
       29,   29,   29,   29,   29,   29,   29,   29,   29,   29,
       29,   29,   29,   29,   29,   29,   29,   29,   29,   29,
       29,   29,   29,   29,   29,   29,   29,   29,   29,   29,
       29,   32,   32,  320,   35,   35,   32,   35,   36,   36,
       55,   36,   46,   46,   48,   48,   46,   56,   55,   57,
       57,   57,   57,   58,   57,   56,   59,   60,   61,   61,
       60,   58,   80,   82,   59,   60,   83,   83,   84,   92,

       92,   94,   95,   97,  116,   82,  116,   59,  166,   84,
      168,   80,  100,  100,  107,   83,   80,  107,  112,  112,
       95,   97,  113,   92,  164,  113,  166,  117,  168,  112,
       94,  112,  117,  118,  118,  124,  124,  112,  126,  126,
      127,  127,  128,  128,  129,  129,  130,  130,  151,  100,
      126,  319,  127,  164,  128,  124,  131,  131,  126,  151,
      127,  179,  128,  179,  129,  239,  130,  239,  131,  132,
      132,  133,  133,  137,  137,  129,  131,  130,  134,  134,
      130,  132,  135,  133,  150,  135,  149,  149,  134,  132,
      135,  133,  153,  153,  163,  163,  185,  165,  134,  170,

      170,  172,  172,  150,  177,  149,  190,  177,  150,  181,
      181,  153,  314,  190,  185,  195,  195,  210,  163,  165,
      181,  312,  181,  197,  197,  199,  199,  210,  181,  200,
      200,  201,  201,  202,  202,  204,  204,  199,  172,  303,
      203,  203,  206,  206,  302,  199,  212,  212,  274,  200,
      274,  201,  203,  202,  301,  200,  224,  224,  226,  226,
      203,  228,  228,  292,  201,  292,  202,  230,  230,  231,
      231,  232,  232,  233,  233,  235,  235,  237,  237,  240,
      241,  241,  246,  212,  242,  242,  263,  230,  299,  231,
      240,  232,  240,  246,  263,  246,  251,  251,  240,  253,

      253,  255,  255,  257,  257,  259,  259,  262,  264,  294,
      264,  265,  265,  267,  267,  291,  264,  269,  262,  278,
      262,  272,  275,  279,  279,  295,  262,  295,  269,  296,
      269,  296,  272,  275,  272,  275,  281,  281,  283,  283,
      285,  285,  286,  287,  286,  287,  288,  290,  288,  277,
      286,  287,  285,  276,  288,  289,  289,  273,  290,  293,
      290,  297,  298,  297,  271,  300,  289,  300,  289,  308,
      293,  308,  293,  298,  289,  298,  304,  304,  306,  270,
      306,  307,  307,  309,  311,  309,  306,  310,  313,  310,
      313,  315,  307,  315,  307,  311,  316,  311,  316,  317,

      307,  317,  318,  321,  318,  321,  322,  323,  322,  323,
      324,  325,  324,  325,  327,  261,  327,  329,  329,  329,
      329,  329,  330,  330,  330,  330,  330,  331,  331,  331,
      331,  331,  332,  332,  332,  332,  332,  333,  333,  333,
      333,  333,  334,  334,  334,  334,  334,  335,  335,  335,
      335,  335,  336,  336,  336,  336,  336,  337,  337,  337,
      337,  337,  338,  338,  338,  338,  338,  339,  339,  339,
      339,  339,  340,  340,  340,  340,  340,  341,  341,  341,
      341,  341,  342,  342,  342,  342,  342,  343,  343,  343,
      343,  343,  344,  344,  250,  344,  344,  347,  347,  347,

      347,  347,  348,  348,  348,  348,  348,  349,  349,  349,
      349,  349,  351,  351,  351,  351,  351,  352,  249,  352,
      352,  352,  353,  353,  248,  353,  353,  354,  354,  247,
      245,  354,  355,  355,  244,  355,  355,  356,  356,  356,
      356,  356,  357,  357,  357,  357,  357,  358,  358,  358,
      358,  358,  359,  359,  243,  359,  359,  360,  360,  223,
      360,  360,  361,  361,  222,  361,  361,  362,  362,  221,
      362,  362,  363,  363,  363,  363,  363,  364,  364,  220,
      364,  364,  365,  365,  219,  365,  365,  366,  366,  218,
      366,  366,  367,  367,  216,  367,  367,  368,  368,  215,

      368,  368,  214,  213,  209,  208,  191,  189,  188,  187,
      186,  184,  183,  182,  178,  174,  173,  161,  159,  158,
      157,  152,  148,  145,  142,  140,  138,  136,  122,  115,
      114,  109,  104,  102,   91,   90,   89,   86,   79,   75,
       69,   67,   62,   53,   51,   41,   40,   39,   38,   37,
       34,   33,   18,   17,   14,   13,   12,   11,   10,    9,
        8,    7,    6,    5,    4,    3,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,

      328,  328,  328,  328,  328,  328
    } ;

static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;
static char *yy_full_match;
static int yy_lp;
#define REJECT \
{ \
*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \
yy_cp = yy_full_match; /* restore poss. backed-over text */ \
++yy_lp; \
goto find_rule; \
}
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "vs1.0_tokens.l"
#define INITIAL 0
#define INCLUDE 1
#define DEFINE 2
#define DEFSTR 3
#define DEFSPACE 4
#define SKIPLINE 5
#define EATCOMMENT 6
#define EATSTRING 7
#define SAVELINE 8
 
#define MACRONAME 9
#define MACROBODY 10
#define MACROPARM 11
#define EATMACRO 12
#define EATDEFINE 13
#define MODIFIER 14
#define MACROPARMSTART 15

#define IFDEFNAME 16
#define IFDEFBODY 17
#define ENDMACRO 18
#define MACROPARMEND 19

#line 7 "vs1.0_tokens.l"

#include <stdarg.h>
#include <stdlib.h>
#ifdef _WIN32
#include <io.h>
#else
#include <sys/types.h>
#include <ctype.h>
#define _stat stat
#define _open open
#define _O_RDONLY O_RDONLY
#define _fstat fstat
#define _close close
#define stricmp strcasecmp

#endif
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include "macro.h"
#include "nvparse_errors.h"
#include "vs1.0_inst_list.h"
#include "_vs1.0_parser.h"
#define yylineno line_number
#include "nvparse_externs.h"

#define yylineno line_number
int line_incr;
void LexError(char *format, ...);
void LexWarning(char *format, ...);
char *ReadTextFile(const char * filename);

unsigned int MakeRegisterMask(char *findName);
unsigned int FindSwizzleValue(char *swizzleText);


enum ERROR_VALUES {
	ERROR_NONE = 0,
	ERROR_MEMORY_ALLOC,
	ERROR_FILE_OPEN,
	ERROR_UNSUCCESSFUL_ASSEMBLE,
	ERROR_TOO_MANY_PARMS,
	ERROR_DEST_WRITE,
	ERROR_LIST_OPEN,
	ERROR_DEST_OPEN,
	ERROR_NO_ARGUMENTS,
	ERROR_MACRO_OVERRUN
};



//extern void GenSwitchFileNames(char *fileName);
//extern unsigned int gLinesAssembled;
unsigned int gLinesAssembled;

#define YY_INPUT(buf,result,max_size) \
{ \
	int c = *myin++; \
	result = (c == 0) ? YY_NULL : (buf[0] = c, 1); \
}

#define SAFEDELETEARRAY(x) if ((x) != NULL) \
						delete [] (x)
#define SAFEFREE(x) if ((x) != NULL) \
						free((x))

#define MAXREPLACESTRING 255

char gReplaceText[MAXREPLACESTRING+1];

//
// forward prototypes for macro functions
//
void MacroIncFunction(char *, unsigned int *, char **);
void MacroDecFunction(char *, unsigned int *, char **);
void MacroAddFunction(char *, unsigned int *, char **);
void MacroSubFunction(char *, unsigned int *, char **);

MACROFUNCTIONS gMacroFunctions[] = { 
	{ "inc(", MacroIncFunction },
	{ "dec(", MacroDecFunction },
	{ "add(", MacroAddFunction },
	{ "sub(", MacroSubFunction }
};

#define NUM_MACRO_FUNCTIONS (sizeof(gMacroFunctions) / sizeof(MACROFUNCTIONS))

#define MAX_INCLUDE_DEPTH 1024
typedef struct INCLUDEINFO
{
	char	*fileName;
	unsigned int lineNo;
	YY_BUFFER_STATE buffer;
	MACROENTRY *lastInvokeMacro;				// save off in case nested macros.
	MACROENTRY *lastParseMacro;				// recursive macros
	MACROTEXT *lastMacroLineParse;			// save off for recursive lines of macros working on.
	bool lastbInsideMacro;					// save off for recursive macros
	bool lastbInsideDefine;					// save off for recursive macros/defines
	bool lastbInsideInclude;
	bool lastbProcessingIFDEF; 				// save off #define information
//	FILE *fileHandle;
	char *prevString;
	char *nextString;
} INCLUDEINFO;

INCLUDEINFO gIncludeStack[MAX_INCLUDE_DEPTH];
int gIncludeStackIndex = 0;

IFDEFINFO gIfDefStack[MAX_IFDEF_DEPTH];
int gIfDefStackIndex = 0;

unsigned int &base_linenumber = gIncludeStack[0].lineNo;

bool gbInsideInclude = false;
bool gbProcessingBuiltIn = false;
bool gbProcessingDefine = false;
unsigned int gCountParen = 0;

bool gbProcessingIFDEF = false;
bool gbIFDEF = false;
bool gbCompareDefine = false;
unsigned int gIfDefStartLine;


MACROENTRY *gLastMacro;
MACROENTRY *gInvokeMacro;
MACROENTRY *gTempMacro;					// until all the parameters are read
MACROENTRY *FindMacro(char *macroName);
MACROENTRY *FindNMacro(char *macroName, unsigned int sLen);

MACROFUNCTIONPTR gMacroCallFunction;

char *builtInMacros =	"macro m3x2 reg1, reg2, reg3\n"
						"	dp3	%reg1.x, %reg2, %reg3\n"
						"	dp3 %reg1.y, %reg2, %inc(%reg3)\n"
						"endm";

//
// local prototypes
//
void CleanUp();

⌨️ 快捷键说明

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