📄 lex.c_shipped
字号:
{ if ( yy_start_stack_ptr >= yy_start_stack_depth ) { yy_size_t new_size; yy_start_stack_depth += YY_START_STACK_INCR; new_size = yy_start_stack_depth * sizeof( int ); if ( ! yy_start_stack ) yy_start_stack = (int *) yy_flex_alloc( new_size ); else yy_start_stack = (int *) yy_flex_realloc( (void *) yy_start_stack, new_size ); if ( ! yy_start_stack ) YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); } yy_start_stack[yy_start_stack_ptr++] = YY_START; BEGIN(new_state); }#endif#ifndef YY_NO_POP_STATEstatic void yy_pop_state() { if ( --yy_start_stack_ptr < 0 ) YY_FATAL_ERROR( "start-condition stack underflow" ); BEGIN(yy_start_stack[yy_start_stack_ptr]); }#endif#ifndef YY_NO_TOP_STATEstatic int yy_top_state() { return yy_start_stack[yy_start_stack_ptr - 1]; }#endif#ifndef YY_EXIT_FAILURE#define YY_EXIT_FAILURE 2#endif#ifdef YY_USE_PROTOSstatic void yy_fatal_error( yyconst char msg[] )#elsestatic void yy_fatal_error( msg )char msg[];#endif { (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); }/* Redefine yyless() so it works in section 3 code. */#undef yyless#define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ yytext[yyleng] = yy_hold_char; \ yy_c_buf_p = yytext + n; \ yy_hold_char = *yy_c_buf_p; \ *yy_c_buf_p = '\0'; \ yyleng = n; \ } \ while ( 0 )/* Internal utility routines. */#ifndef yytext_ptr#ifdef YY_USE_PROTOSstatic void yy_flex_strncpy( char *s1, yyconst char *s2, int n )#elsestatic void yy_flex_strncpy( s1, s2, n )char *s1;yyconst char *s2;int n;#endif { register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; }#endif#ifdef YY_NEED_STRLEN#ifdef YY_USE_PROTOSstatic int yy_flex_strlen( yyconst char *s )#elsestatic int yy_flex_strlen( s )yyconst char *s;#endif { register int n; for ( n = 0; s[n]; ++n ) ; return n; }#endif#ifdef YY_USE_PROTOSstatic void *yy_flex_alloc( yy_size_t size )#elsestatic void *yy_flex_alloc( size )yy_size_t size;#endif { return (void *) malloc( size ); }#ifdef YY_USE_PROTOSstatic void *yy_flex_realloc( void *ptr, yy_size_t size )#elsestatic void *yy_flex_realloc( ptr, size )void *ptr;yy_size_t size;#endif { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size ); }#ifdef YY_USE_PROTOSstatic void yy_flex_free( void *ptr )#elsestatic void yy_flex_free( ptr )void *ptr;#endif { free( ptr ); }#if YY_MAINint main() { yylex(); return 0; }#endif#line 95 "scripts/genksyms/lex.l"/* Bring in the keyword recognizer. */#include "keywords.c"/* Macros to append to our phrase collection list. */#define _APP(T,L) do { \ cur_node = next_node; \ next_node = xmalloc(sizeof(*next_node)); \ next_node->next = cur_node; \ cur_node->string = memcpy(xmalloc(L+1), T, L+1); \ cur_node->tag = SYM_NORMAL; \ } while (0)#define APP _APP(yytext, yyleng)/* The second stage lexer. Here we incorporate knowledge of the state of the parser to tailor the tokens that are returned. */intyylex(void){ static enum { ST_NOTSTARTED, ST_NORMAL, ST_ATTRIBUTE, ST_ASM, ST_BRACKET, ST_BRACE, ST_EXPRESSION, ST_TABLE_1, ST_TABLE_2, ST_TABLE_3, ST_TABLE_4, ST_TABLE_5, ST_TABLE_6 } lexstate = ST_NOTSTARTED; static int suppress_type_lookup, dont_want_brace_phrase; static struct string_list *next_node; int token, count = 0; struct string_list *cur_node; if (lexstate == ST_NOTSTARTED) { BEGIN(V2_TOKENS); next_node = xmalloc(sizeof(*next_node)); next_node->next = NULL; lexstate = ST_NORMAL; }repeat: token = yylex1(); if (token == 0) return 0; else if (token == FILENAME) { char *file, *e; /* Save the filename and line number for later error messages. */ if (cur_filename) free(cur_filename); file = strchr(yytext, '\"')+1; e = strchr(file, '\"'); *e = '\0'; cur_filename = memcpy(xmalloc(e-file+1), file, e-file+1); cur_line = atoi(yytext+2); goto repeat; } switch (lexstate) { case ST_NORMAL: switch (token) { case IDENT: APP; { const struct resword *r = is_reserved_word(yytext, yyleng); if (r) { switch (token = r->token) { case ATTRIBUTE_KEYW: lexstate = ST_ATTRIBUTE; count = 0; goto repeat; case ASM_KEYW: lexstate = ST_ASM; count = 0; goto repeat; case STRUCT_KEYW: case UNION_KEYW: dont_want_brace_phrase = 3; case ENUM_KEYW: suppress_type_lookup = 2; goto fini; case EXPORT_SYMBOL_KEYW: goto fini; } } if (!suppress_type_lookup) { struct symbol *sym = find_symbol(yytext, SYM_TYPEDEF); if (sym && sym->type == SYM_TYPEDEF) token = TYPE; } } break; case '[': APP; lexstate = ST_BRACKET; count = 1; goto repeat; case '{': APP; if (dont_want_brace_phrase) break; lexstate = ST_BRACE; count = 1; goto repeat; case '=': case ':': APP; lexstate = ST_EXPRESSION; break; case DOTS: default: APP; break; } break; case ST_ATTRIBUTE: APP; switch (token) { case '(': ++count; goto repeat; case ')': if (--count == 0) { lexstate = ST_NORMAL; token = ATTRIBUTE_PHRASE; break; } goto repeat; default: goto repeat; } break; case ST_ASM: APP; switch (token) { case '(': ++count; goto repeat; case ')': if (--count == 0) { lexstate = ST_NORMAL; token = ASM_PHRASE; break; } goto repeat; default: goto repeat; } break; case ST_BRACKET: APP; switch (token) { case '[': ++count; goto repeat; case ']': if (--count == 0) { lexstate = ST_NORMAL; token = BRACKET_PHRASE; break; } goto repeat; default: goto repeat; } break; case ST_BRACE: APP; switch (token) { case '{': ++count; goto repeat; case '}': if (--count == 0) { lexstate = ST_NORMAL; token = BRACE_PHRASE; break; } goto repeat; default: goto repeat; } break; case ST_EXPRESSION: switch (token) { case '(': case '[': case '{': ++count; APP; goto repeat; case ')': case ']': case '}': --count; APP; goto repeat; case ',': case ';': if (count == 0) { /* Put back the token we just read so's we can find it again after registering the expression. */ unput(token); lexstate = ST_NORMAL; token = EXPRESSION_PHRASE; break; } APP; goto repeat; default: APP; goto repeat; } break; case ST_TABLE_1: goto repeat; case ST_TABLE_2: if (token == IDENT && yyleng == 1 && yytext[0] == 'X') { token = EXPORT_SYMBOL_KEYW; lexstate = ST_TABLE_5; APP; break; } lexstate = ST_TABLE_6; /* FALLTHRU */ case ST_TABLE_6: switch (token) { case '{': case '[': case '(': ++count; break; case '}': case ']': case ')': --count; break; case ',': if (count == 0) lexstate = ST_TABLE_2; break; }; goto repeat; case ST_TABLE_3: goto repeat; case ST_TABLE_4: if (token == ';') lexstate = ST_NORMAL; goto repeat; case ST_TABLE_5: switch (token) { case ',': token = ';'; lexstate = ST_TABLE_2; APP; break; default: APP; break; } break; default: abort(); }fini: if (suppress_type_lookup > 0) --suppress_type_lookup; if (dont_want_brace_phrase > 0) --dont_want_brace_phrase; yylval = &next_node->next; return token;}#ifndef YYSTYPE#define YYSTYPE int#endif#define ASM_KEYW 257#define ATTRIBUTE_KEYW 258#define AUTO_KEYW 259#define BOOL_KEYW 260#define CHAR_KEYW 261#define CONST_KEYW 262#define DOUBLE_KEYW 263#define ENUM_KEYW 264#define EXTERN_KEYW 265#define FLOAT_KEYW 266#define INLINE_KEYW 267#define INT_KEYW 268#define LONG_KEYW 269#define REGISTER_KEYW 270#define RESTRICT_KEYW 271#define SHORT_KEYW 272#define SIGNED_KEYW 273#define STATIC_KEYW 274#define STRUCT_KEYW 275#define TYPEDEF_KEYW 276#define UNION_KEYW 277#define UNSIGNED_KEYW 278#define VOID_KEYW 279#define VOLATILE_KEYW 280#define TYPEOF_KEYW 281#define EXPORT_SYMBOL_KEYW 282#define ASM_PHRASE 283#define ATTRIBUTE_PHRASE 284#define BRACE_PHRASE 285#define BRACKET_PHRASE 286#define EXPRESSION_PHRASE 287#define CHAR 288#define DOTS 289#define IDENT 290#define INT 291#define REAL 292#define STRING 293#define TYPE 294#define OTHER 295#define FILENAME 296extern YYSTYPE yylval;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -