📄 scanner.cpp
字号:
#define KEYWORD_COUNT sizeof(keywords)/sizeof(keyword)
static int compare_keywords(const void *left, const void *right);
keyword keywords[] = {
{"ALL", ALL},
{"AND", AND},
{"AS", AS},
{"BREAK", BREAK},
{"CONTINUE", CONTINUE},
{"ELSE", ELSE},
{"ELSEIF", ELSEIF},
{"ELSIF", ELSEIF},
{"END", END},
{"FOR", FOR},
{"FOREACH", FOREACH},
{"FUNCTION", FUNCTION},
{"GRID", GRID},
{"IF", IF},
{"INCLUDE", INCLUDE},
{"JUMP", JUMP},
{"LOCAL", LOCAL},
{"NEW", K_NEW},
{"NOT", NOT},
{"NULL", K_NULL},
{"OR", OR},
{"PRINT", PRINT},
{"PRINTLN", PRINTLN},
{"RETURN", K_RETURN},
{"THEN", THEN},
{"TO", TO},
{"WHILE", WHILE}
};
static bool keywords_sorted = false;
#define FREE_TAG 1
#define QUESTION_TAG 2
#define PERCENT_TAG 3
#define INLINE_TAG 10
#define TAG 1
#define VTAG 2
#define QCOMM 3
#define PAST_END 4
#line 472 "src/scanner.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 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
#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
#define ECHO LexerOutput( yytext, yyleng )
#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 ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \
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) LexerError( msg )
#endif
/* Default declaration of generated scanner - a define so the user can
* easily add parameters.
*/
#ifndef YY_DECL
#define YY_DECL int yyFlexLexer::yylex()
#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 \
YY_USER_ACTION
YY_DECL
{
register yy_state_type yy_current_state;
register char *yy_cp, *yy_bp;
register int yy_act;
#line 115 "src/scanner.l"
#line 602 "src/scanner.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 = &cin;
if ( ! yyout )
yyout = &cout;
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_match:
do
{
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
if ( yy_accept[yy_current_state] )
{
yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = 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 >= 71 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_current_state != 70 );
yy_cp = yy_last_accepting_cpos;
yy_current_state = yy_last_accepting_state;
yy_find_action:
yy_act = 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 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = yy_hold_char;
yy_cp = yy_last_accepting_cpos;
yy_current_state = yy_last_accepting_state;
goto yy_find_action;
case 1:
#line 118 "src/scanner.l"
case 2:
#line 119 "src/scanner.l"
case 3:
YY_RULE_SETUP
#line 119 "src/scanner.l"
{ PPT; BEGIN TAG;
LEXER->tag = INLINE_TAG;
LEXER->escape = yytext[1];
TOKEN->str = LEXER->flush_html();
if (TOKEN->str != NULL) return HTML_AND_PRINT; }
YY_BREAK
case 4:
#line 126 "src/scanner.l"
case 5:
#line 127 "src/scanner.l"
case 6:
YY_RULE_SETUP
#line 127 "src/scanner.l"
{ PPT; BEGIN TAG;
LEXER->tag = FREE_TAG;
LEXER->escape = yytext[1];
// printf("<~: escape = %c\n", LEXER->escape);
TOKEN->str = LEXER->flush_html();
if (TOKEN->str != NULL) return BARE_HTML; }
YY_BREAK
case 7:
#line 136 "src/scanner.l"
case 8:
#line 137 "src/scanner.l"
case 9:
YY_RULE_SETUP
#line 137 "src/scanner.l"
{ PPT;
if (LEXER->escape == yytext[0]) { BEGIN 0; LEXER->tag = 0; }
//else printf("~>: escape = %c; yytext[1] = %c\n", LEXER->escape, yytext[1]);
}
YY_BREAK
case 10:
YY_RULE_SETUP
#line 144 "src/scanner.l"
{ PPT;
TOKEN->num = atoi(yytext);
return NUMBER; }
YY_BREAK
case 11:
YY_RULE_SETUP
#line 148 "src/scanner.l"
{ PPT;
TOKEN->fnum = atof(yytext);
return _FLOAT; }
YY_BREAK
case 12:
#line 154 "src/scanner.l"
case 13:
YY_RULE_SETUP
#line 154 "src/scanner.l"
{ PPT; return NE; }
YY_BREAK
case 14:
YY_RULE_SETUP
#line 155 "src/scanner.l"
{ PPT; return LE; }
YY_BREAK
case 15:
YY_RULE_SETUP
#line 156 "src/scanner.l"
{ PPT; return GE; }
YY_BREAK
case 16:
YY_RULE_SETUP
#line 157 "src/scanner.l"
{ PPT; return EQL; }
YY_BREAK
case 17:
YY_RULE_SETUP
#line 159 "src/scanner.l"
{ PPT;
static keyword key;
key.token = yytext; //uppercase_string(yytext);
keyword* kw = (keyword*)
bsearch(&key, keywords, KEYWORD_COUNT, sizeof(keyword), compare_keywords);
if (kw) return kw->value;
//TRACE((7, "unrecognized word: \"%s\"\n", yytext));
if (yy_flex_debug) printf(" \"%s\" ", yytext);
TOKEN->str = LEXER->m_scratch.strdup(yytext);
int ident_type = LEXER->override_ident_type;
if (ident_type == 0) ident_type = IDENT;
LEXER->override_ident_type = IDENT;
return ident_type;
}
YY_BREAK
case 18:
#line 179 "src/scanner.l"
case 19:
#line 180 "src/scanner.l"
case 20:
#line 181 "src/scanner.l"
case 21:
YY_RULE_SETUP
#line 181 "src/scanner.l"
{ PPT;
TOKEN->str = (char*) LEXER->m_scratch.malloc(yyleng-1);
char q = yytext[0];
register char *s = yytext+1;
register char *d = (char*) TOKEN->str;
while(*s != '\0' && *s != q)
{
if (*s == '\\')
switch(*++s)
{
case 'n': *d++ = '\n';s++; break;
case 't': *d++ = '\t';s++; break;
case 'r': *d++ = '\r';s++; break;
default: *d++ = *s++; break;
}
else *d++ = *s++;
}
*d = '\0';
//printf("quoted string: >>>>\n%s>>>\n", yytext);
return STRING; }
YY_BREAK
case 22:
#line 203 "src/scanner.l"
case 23:
YY_RULE_SETUP
#line 203 "src/scanner.l"
{
LEXER->yyline++; LEXER->yypos = 1;
//printf("single line comment: >>>>\n%s>>>\n", yytext);
return '\n'; }
YY_BREAK
case 24:
YY_RULE_SETUP
#line 210 "src/scanner.l"
{ PPT; }
YY_BREAK
case 25:
YY_RULE_SETUP
#line 212 "src/scanner.l"
/* */
YY_BREAK
case 26:
YY_RULE_SETUP
#line 214 "src/scanner.l"
{ LEXER->yyline++; LEXER->yypos=1;
//TRACE((12, "returned newline\n"));
return '\n'; }
YY_BREAK
case 27:
YY_RULE_SETUP
#line 218 "src/scanner.l"
{ PPT;
TOKEN->num = 0;
TRACE((10, "invalid character: 0x%02x\n", yytext[0] & 0xff));
//compiler->add_scan_error(10302, "礤 觐痧尻蝽
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -