📄 vs1.0_tokens.l
字号:
<MACROPARM>[ \t]* {
if ((gCountParen == 0) && gbProcessingDefine)
{
EndMacroParms();
}
}
<MACROPARM>(";"|"//").* {
if (gCountParen == 0)
{
EndMacroParms();
}
}
<MACROPARM>"," {}
<MACROPARM><<EOF>> {
EndMacroParms();
// GenDebugLine();
// GenListString();
yylineno++;
gLinesAssembled++;
BEGIN(INITIAL);
}
<MACROPARM>\n {
if (gbProcessingDefine && (gCountParen > 0))
{
LexError("Malformed #define, skipping.\n");
BEGIN(SAVELINE);
}
else
{
EndMacroParms();
// GenDebugLine();
// GenListString();
yylineno++;
gLinesAssembled++;
if (gbProcessingDefine)
{
gbProcessingDefine = false;
BEGIN(SAVELINE);
}
}
}
<MACROPARM>[^\n,]+ {
MACROTEXT *tMacro;
char *macroParmEnd;
unsigned int startOffset;
bool bFoundEndParen;
unsigned int leftParenCount;
unsigned int rightParenCount;
bFoundEndParen = false;
// sheesh, we gotta count the parenthesis....
macroParmEnd = yytext;
leftParenCount = 0;
rightParenCount = 0;
while (*macroParmEnd)
{
if (*macroParmEnd == ')')
{
rightParenCount++;
}
if (*macroParmEnd == '(')
{
leftParenCount++;
}
macroParmEnd++;
}
// if we found the last right parenthesis.
if (rightParenCount == leftParenCount+1)
{
// find if we got the last parenthesis on this line
macroParmEnd = strrchr(yytext, ')');
yyless((macroParmEnd - yytext));
BEGIN(MACROPARMEND);
}
startOffset = strspn(yytext, " \t");
tMacro = SaveMacroText(&yytext[startOffset], gTempMacro->lastMacroParms);
if (tMacro == NULL)
{
LexError("Out of memory for string table for macro parameter(s).\n");
FreeMacroEntry(gTempMacro);
BEGIN(EATMACRO);
}
else
{
// if first one wasn't set then set it
if (gTempMacro->firstMacroParms == NULL)
{
gTempMacro->firstMacroParms = tMacro;
}
gTempMacro->lastMacroParms = tMacro;
gTempMacro->numParms++;
}
}
<MACROPARMEND>")"[ \t]*"\\"*\n* {
if (!gbProcessingDefine && !gbTempInsideMacro)
{
LexError("Malformed macro, skipping.\n");
BEGIN(EATMACRO);
}
else
{
gCountParen--;
// we can get multiple \n's here
while (yytext[yyleng-2] == '\n')
{
yyleng--;
}
yyless(yyleng);
// if there isn't a \n on this line, macro starts on this line,
// not next, like in a macro definition
if (yytext[yyleng-1] != '\n')
{
EndMacroParms();
}
else
{
if (yytext[yyleng-1] == '\n')
{
gTempMacro->lineNo++;
}
// count this line
gTempMacro->nLines++;
// GenDebugLine();
// GenListString();
EndMacroParms();
if (!gbInsideMacro)
{
yylineno++;
}
gLinesAssembled++;
}
}
}
<MACROPARMEND>")"[ \t]*(";"|"//").*\n {
if (!gbProcessingDefine && !gbTempInsideMacro)
{
LexError("Malformed macro, skipping.\n");
BEGIN(EATMACRO);
}
else
{
// no matter what count this line
gTempMacro->nLines++;
gCountParen--;
EndMacroParms();
if (!gbInsideMacro)
{
yylineno++;
}
gLinesAssembled++;
}
}
<MACROPARMEND>")"[ \t]+ {
if (!gbProcessingDefine && !gbTempInsideMacro)
{
LexError("Malformed macro, skipping.\n");
BEGIN(EATMACRO);
}
else
{
gCountParen--;
if (gCountParen == 0)
{
// no matter what count this line
gTempMacro->nLines++;
EndMacroParms();
if (!gbInsideMacro)
{
yylineno++;
}
gLinesAssembled++;
}
else
{
REJECT;
}
}
}
<MACROBODY>.*"\\"[ \t]*\n {
MACROTEXT *tMacro;
unsigned int copyLen;
char *endLine;
gSaveLine[0] ='\0';
endLine = strchr(yytext, '\\');
copyLen = (endLine - yytext);
if (copyLen > MAXSAVELINE)
{
copyLen = MAXSAVELINE;
}
strncat(gSaveLine, yytext, copyLen);
strcat(gSaveLine, "\n");
tMacro = SaveMacroText(gSaveLine, gLastMacro->lastMacroLines);
if (tMacro == NULL)
{
LexError("Out of memory for string table for macro parameter(s).\n");
BEGIN(EATDEFINE);
}
else
{
gLastMacro->nLines++;
// if first one wasn't set then set it
if (gLastMacro->firstMacroLines == NULL)
{
gLastMacro->firstMacroLines = tMacro;
}
gLastMacro->lastMacroLines = tMacro;
}
// GenDebugLine();
// GenListString();
yylineno++;
gLinesAssembled++;
}
<MACROBODY>[ \t]*"endm"[ \t]*((";"|"//").*)* {
strncpy(gSaveLine, yytext, MAXSAVELINE);
if (gbProcessingDefine)
{
LexError("Malformed #define, skipping.\n");
}
BEGIN(ENDMACRO);
}
<MACROBODY>[^\n]* {
MACROTEXT *tMacro;
// check if processing #define and only one line, if not then append \n
if (!gbProcessingDefine || (gLastMacro->nLines >= 1))
{
gSaveLine[0] = '\0';
strncat(gSaveLine, yytext, MAXSAVELINE);
strcat(gSaveLine, "\n");
tMacro = SaveMacroText(gSaveLine, gLastMacro->lastMacroLines);
gLastMacro->nLines++;
}
else if (gLastMacro->numParms > 0) // check if parameters were there
{
// if so, we need the '\n' appended
gMacroLine[0] = '\0';
strncat(gMacroLine, yytext, MAXSAVELINE);
strcat(gMacroLine, "\n");
tMacro = SaveMacroText(gMacroLine, gLastMacro->lastMacroLines);
gLastMacro->nLines++;
}
else // straight no newline macro replace
{
tMacro = SaveMacroText(yytext, gLastMacro->lastMacroLines);
}
if (tMacro == NULL)
{
LexError("Out of memory for string table for macro parameter(s).\n");
BEGIN(EATMACRO);
}
else
{
// if first one wasn't set then set it
if (gLastMacro->firstMacroLines == NULL)
{
gLastMacro->firstMacroLines = tMacro;
}
gLastMacro->lastMacroLines = tMacro;
}
}
<MACROBODY>\n {
MACROTEXT *tMacro;
// GenDebugLine();
// GenListString();
yylineno++;
gLinesAssembled++;
if (gbProcessingDefine)
{
gbProcessingDefine = false;
BEGIN(SAVELINE);
}
else
{
// this means \n by itself inside macro body
if (((yylineno-1) - gLastMacro->lineNo) != gLastMacro->nLines)
{
strcpy(gMacroLine, "\n");
tMacro = SaveMacroText(gMacroLine, gLastMacro->lastMacroLines);
gLastMacro->nLines++;
if (tMacro == NULL)
{
LexError("Out of memory for string table for macro parameter(s).\n");
BEGIN(EATMACRO);
}
else
{
// if first one wasn't set then set it
if (gLastMacro->firstMacroLines == NULL)
{
gLastMacro->firstMacroLines = tMacro;
}
gLastMacro->lastMacroLines = tMacro;
}
}
}
}
<EATMACRO>[ \t]*"endm"[ \t]*\n {
BEGIN(SAVELINE);
// GenDebugLine();
// GenListString();
gLinesAssembled++;
yylineno++;
}
<EATMACRO>.*\n {
strncpy(gSaveLine, yytext, MAXSAVELINE);
// GenDebugLine();
// GenListString();
gLinesAssembled++;
yylineno++;
}
<EATDEFINE>.*"\\"\n {
strncpy(gSaveLine, yytext, MAXSAVELINE);
// GenDebugLine();
// GenListString();
gLinesAssembled++;
yylineno++;
}
<EATDEFINE>.*\n {
strncpy(gSaveLine, yytext, MAXSAVELINE);
// GenDebugLine();
// GenListString();
gLinesAssembled++;
yylineno++;
BEGIN(SAVELINE);
}
<INITIAL,MODIFIER>{alpha}{alphadigs}* {
gTempParseMacro = FindMacro(yytext);
if (gTempParseMacro != NULL)
{
if (gIncludeStackIndex >= MAX_INCLUDE_DEPTH )
{
LexError("macros nested too deeply");
exit( 1 );
}
if (gTempParseMacro->firstMacroLines != NULL)
{
gTempMacro = (MACROENTRY *)malloc(sizeof(MACROENTRY));
if (gTempMacro == NULL)
{
LexError("Out of memory allocating MACROENTRY structure.\n");
}
else
{
gTempMacro->next = NULL;
gTempMacro->prev = NULL;
gTempMacro->macroName = NULL;
gTempMacro->firstMacroParms = NULL;
gTempMacro->lastMacroParms = NULL;
gTempMacro->firstMacroLines = NULL;
gTempMacro->lastMacroLines = NULL;
gTempMacro->numParms = 0;
gTempMacro->nLines = 0;
gbTempInsideMacro = true; // flag we are currently doing a macro replace.
gInvokeState = YYSTATE;
if (gTempParseMacro->numParms > 0)
{
BEGIN(MACROPARMSTART);
}
else
{
EndMacroParms();
gbTempInsideMacro = false; // no longer waiting for macro invocation
}
}
}
}
else
{
BEGIN(INITIAL);
REJECT;
}
}
[,\[\]\-\+\(\)\*\<\>\/\%_\.] {
// fprintf( stderr, "%c ", yytext[0] );
return yytext[0];
}
[ \t]+ {}
<DEFINE>\n {
LexError("Didn't find label string for #define.\n");
BEGIN(SAVELINE);
// return '\n';
}
"\n" {
//fprintf(stderr, "\n");
// line_incr = 1;
line_incr++;
BEGIN(SAVELINE);
return '\n';
}
<EATSTRING>{alphadigs}+ {
BEGIN(INITIAL);
// fprintf( stderr, "%s", yytext );
if (yyleng == 1)
return yytext[0];
else
LexError("Unrecognized Token: %s\n", yytext);
return UNKNOWN_STRING;
}
<EATSTRING>[\001-\040] {
// vs10_lval.ival = yytext[0];
LexError("Illegal character: %d decimal.\n", yytext[0]);
return(ILLEGAL);
}
[\001-\040] {
// vs10_lval.ival = yytext[0];
LexError("Illegal character: %d decimal.\n", yytext[0]);
return(ILLEGAL);
}
<EATSTRING>. {
return yytext[0];
}
. {
BEGIN(EATSTRING);
yyless(0);
}
<<EOF>> {
bool wasInMacro;
bool oneLiner;
char *macroText;
wasInMacro = gbInsideMacro;
oneLiner = false;
// if we are inside the macro then do next line until their are no more
if (gbInsideMacro)
{
oneLiner = (gParseMacro->nLines == 0);
// free the temporary parameter replaced line we were working on.
// get next line in macro text, if any
gMacroLineParse = gMacroLineParse->next;
// more lines to parse?
if (gMacroLineParse != NULL)
{
macroText = gMacroLine;
// if no replacement text, just use source line
if (gParseMacro->firstMacroParms == NULL)
{
macroText = gMacroLineParse->macroText;
}
else
{
// replace the macro parameters
ReplaceMacroParms(gMacroLineParse->macroText, gMacroLine, gParseMacro, gInvokeMacro);
}
// if (gExpandMacros)
// {
// strcpy(gSaveLine, macroText);
// }
BEGIN(INITIAL);
// and lex it.
yy_scan_string(macroText);
}
else
{
// no more lines in this macro, so free the working macro
SAFEFREE(gInvokeMacro);
// shut off flag for inside a macro replacement state.
gbInsideMacro = false;
}
}
if (gbProcessingIFDEF && !wasInMacro)
{
LexError("End of file reached before #endif found, macro started on line %d.\n", gIfDefStartLine);
}
if (!gbInsideMacro)
{
if ( gIncludeStackIndex == 0 )
{
if (!gbProcessingBuiltIn)
CleanUp();
return 0;
// return TOKEN_EOF;
}
else
{
yy_delete_buffer( YY_CURRENT_BUFFER );
SAFEFREE(gCurFileName);
// SAFEDELETE(myin);
// SAFECLOSE(yyin);
}
gIncludeStackIndex--;
SAFEDELETEARRAY( gIncludeStack[gIncludeStackIndex].nextString );
yy_switch_to_buffer(gIncludeStack[gIncludeStackIndex].buffer );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -