📄 scan.re
字号:
#include "as.h"
#include "lexyacc.h"
#include "ytab.h"
#ifdef _STANDALONE_
#include "preproc.h"
#endif
#define BSIZE 8192
#define YYCTYPE char
#define YYCURSOR cursor
#define YYLIMIT limit
#define YYMARKER marker
#define YYFILL( n ) {fill();}
extern YYSTYPE asyylval;
#ifndef _STANDALONE_
extern char *AsmInStr; // The input string.
#endif
#ifdef _STANDALONE_
int CurrLineno = 1; // This pair is used by the parser and the
char *CurrFilename = NULL; // outside world.
int asyylineno = 1; // The lexer uses this pair for their own error
char *asyyfname = NULL; // reporting. (globl also because parser needs
/* NOTE: -- make sure asyylineno is used correctly: update it when we get '\n' and
when we get #line directive.
-- CurrLineno should be set in the parser
*/
#endif
#ifdef _STANDALONE_
static int newlineno;
static char *bot, *pos, *top;
#endif
static char *cursor, *limit, *marker, *tok, *eofPtr, *_yytext;
static int maxyytextlen = 1, yytextlen;
static char *dirOpStr = NULL; // used to keep directive string data
static char *cStr = NULL; // used to keep scanned C-style string data
#ifdef _STANDALONE_
static size_t ppRead( char *buffer, size_t numchar ) {
//****************************************************
size_t count = 0;
int c = 0;
while( c != EOF && count < numchar ) {
buffer[count++] = c = PP_Char();
}
if( c == EOF ) count--;
#ifndef NDEBUG
if( _IsOption( DUMP_LEXER_BUFFER ) ) {
int count2;
printf( "Read in lexer buffer (%d characters):\n", count );
for( count2 = 0; count2 < count; ++count2 ) putchar( buffer[count2] );
printf( "**END**\n" );
}
#endif
return( count );
}
static void ppFlush( void ) {
//***************************
while( PP_Char() != EOF );
}
#endif
static char *yytext( void ) {
//***************************
// Call this the first time you want the scanned string.
// Afterwards, you can use _yytext to get the same string.
if ( (yytextlen = cursor - tok) > maxyytextlen - 1 ) {
MemFree( _yytext );
maxyytextlen = yytextlen + 1;
_yytext = (char *) MemAlloc( maxyytextlen );
}
memcpy( _yytext, tok, yytextlen );
_yytext[yytextlen] = NULL;
return( _yytext );
}
#ifdef _STANDALONE_
static void yylexError( int res_id ) {
//************************************
// If error reporting (yyerror style) is needed within this lexer module,
// this is the right one to call. Other ones such as yyerror might get
// the line number wrong.
int saveLineno;
char *saveFname, *tmpstr;
saveLineno = CurrLineno;
saveFname = CurrFilename;
CurrLineno = asyylineno;
CurrFilename = asyyfname;
AsMsgGet( res_id, AsResBuffer );
tmpstr = AsStrdup( AsResBuffer );
asyyerror( tmpstr );
MemFree( tmpstr );
CurrLineno = saveLineno;
CurrFilename = saveFname;
}
#endif
#ifdef _STANDALONE_
static void ppError( char *str ) {
//********************************
// Similar to the above one except that it's just for #error directive.
int saveLineno;
char *saveFname;
saveLineno = CurrLineno;
saveFname = CurrFilename;
CurrLineno = asyylineno;
CurrFilename = asyyfname;
Error( GET_STRING, str );
CurrLineno = saveLineno;
CurrFilename = saveFname;
}
#endif
static char *stripBackQuotes( char *str ) {
//*****************************************
// "`foo`" => "foo"
str[strlen( str ) - 1] = '\0';
return( str + 1 );
}
extern void AsLexerFini( void ) {
//*******************************
// Cleanup and reset states for next file (if any)
#ifdef _STANDALONE_
MemFree( bot );
CurrLineno = 1;
asyylineno = 1;
ppFlush();
bot = NULL;
pos = NULL;
top = NULL;
MemFree( CurrFilename );
CurrFilename = NULL;
MemFree( asyyfname );
asyyfname = NULL;
#endif
cursor = NULL;
limit = NULL;
marker = NULL;
tok = NULL;
eofPtr = NULL;
maxyytextlen = 1;
MemFree( _yytext );
_yytext = NULL;
MemFree( dirOpStr );
dirOpStr = NULL;
MemFree( cStr );
cStr = NULL;
}
#ifdef _STANDALONE_
static void dropDblBackSlashes( char *fname ) {
//*********************************************
size_t len;
len = strlen( fname );
while( *fname ) {
if( fname[0] == '\\' && fname[1] == '\\' ) {
memmove( fname, fname + 1, len );
}
len--;
fname++;
}
}
#endif
static void fill( void ) {
//************************
#ifdef _STANDALONE_
unsigned int cnt;
if(!eofPtr) {
cnt = tok - bot;
if(cnt) { /* move partial token to the bottom */
memcpy(bot, tok, limit - tok);
tok = bot;
marker -= cnt;
cursor -= cnt;
pos -= cnt;
limit -= cnt;
}
if((top - limit) < BSIZE) { // buffer needs to be expanded
char *buf;
buf = (char *) MemAlloc( limit - bot + BSIZE ); // alloc new piece
memcpy(buf, tok, limit - tok); // copy leftover
tok = buf; // adjust all pointers
marker = &buf[marker - bot];
cursor = &buf[cursor - bot];
pos = &buf[pos - bot];
limit = &buf[limit - bot]; // limit now points to first unused spot
top = &limit[BSIZE];
MemFree( bot ); // free old chunk
bot = buf;
}
if((cnt = ppRead( limit, BSIZE )) != BSIZE) { // EOF
eofPtr = &limit[cnt];
*eofPtr++ = '\000'; // place a special EOF marker here
}
limit += cnt; // update limit after read
}
#else
int len;
if( !eofPtr ) {
len = strlen( AsmInStr );
marker = AsmInStr;
cursor = AsmInStr;
tok = AsmInStr;
limit = &AsmInStr[len];
eofPtr = limit + 1;
}
#endif
}
//#pragma warning 118 5 // This doesn't work!
#pragma disable_message( 118 );
#pragma off( unreferenced ); // To get rid of "yyaccept is unreferenced"
/*!re2c
ws = [ \t]+;
nl = "\n";
any = [\000-\377];
dot = any \ [\n];
ch = dot \ [\000];
osym = "."?[a-zA-Z_$@?.][a-zA-Z0-9_$@?.]*;
sym = osym | "`"dot+"`";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -