⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lex.c_shipped

📁 linux 内核源代码
💻 C_SHIPPED
📖 第 1 页 / 共 5 页
字号:
/* %if-c-only */static int yy_init_globals (void){        /* Initialization is the same as for the non-reentrant scanner.     * This function is called from yylex_destroy(), so don't allocate here.     */    (yy_buffer_stack) = 0;    (yy_buffer_stack_top) = 0;    (yy_buffer_stack_max) = 0;    (yy_c_buf_p) = (char *) 0;    (yy_init) = 0;    (yy_start) = 0;/* Defined in main.c */#ifdef YY_STDINIT    yyin = stdin;    yyout = stdout;#else    yyin = (FILE *) 0;    yyout = (FILE *) 0;#endif    /* For future reference: Set errno on error, since we are called by     * yylex_init()     */    return 0;}/* %endif *//* %if-c-or-c++ *//* %if-c-only *//* yylex_destroy is for both reentrant and non-reentrant scanners. */int yylex_destroy  (void)/* %endif *//* %if-c++-only *//* %endif */{        /* Pop the buffer stack, destroying each element. */	while(YY_CURRENT_BUFFER){		yy_delete_buffer(YY_CURRENT_BUFFER  );		YY_CURRENT_BUFFER_LVALUE = NULL;		yypop_buffer_state();	}	/* Destroy the stack itself. */	yyfree((yy_buffer_stack) );	(yy_buffer_stack) = NULL;/* %if-c++-only *//* %endif *//* %if-c-only */    /* Reset the globals. This is important in a non-reentrant scanner so the next time     * yylex() is called, initialization will occur. */    yy_init_globals( );/* %if-reentrant *//* %endif */    return 0;/* %endif */}/* %endif *//* * Internal utility routines. */#ifndef yytext_ptrstatic void yy_flex_strncpy (char* s1, yyconst char * s2, int n ){	register int i;	for ( i = 0; i < n; ++i )		s1[i] = s2[i];}#endif#ifdef YY_NEED_STRLENstatic int yy_flex_strlen (yyconst char * s ){	register int n;	for ( n = 0; s[n]; ++n )		;	return n;}#endifvoid *yyalloc (yy_size_t  size ){	return (void *) malloc( size );}void *yyrealloc  (void * ptr, yy_size_t  size ){	/* 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 );}void yyfree (void * ptr ){	free( (char *) ptr );	/* see yyrealloc() for (char *) cast */}/* %if-tables-serialization definitions *//* %define-yytables   The name for this specific scanner's tables. */#define YYTABLES_NAME "yytables"/* %endif *//* %ok-for-header */#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:      exit(1);    }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;}/* A Bison parser, made by GNU Bison 2.3.  *//* Skeleton interface for Bison's Yacc-like parsers in C   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006   Free Software Foundation, Inc.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2, or (at your option)   any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 51 Franklin Street, Fifth Floor,   Boston, MA 02110-1301, USA.  *//* As a special exception, you may create a larger work that contains   part or all of the Bison parser skeleton and distribute that work   under terms of your choice, so long as that work isn't itself a   parser generator using the skeleton or a modified version thereof   as a parser skeleton.  Alternatively, if you modify or redistribute   the parser skeleton itself, you may (at your option) remove this   special exception, which will cause the skeleton and the resulting   Bison output files to be licensed under the GNU General Public   License without this special exception.   This special exception was added by the Free Software Foundation in   version 2.2 of Bison.  *//* Tokens.  */#ifndef YYTOKENTYPE# define YYTOKENTYPE   /* Put the tokens into the symbol table, so that GDB and other debuggers      know about them.  */   enum yytokentype {     ASM_KEYW = 258,     ATTRIBUTE_KEYW = 259,     AUTO_KEYW = 260,     BOOL_KEYW = 261,     CHAR_KEYW = 262,     CONST_KEYW = 263,     DOUBLE_KEYW = 264,     ENUM_KEYW = 265,     EXTERN_KEYW = 266,     EXTENSION_KEYW = 267,     FLOAT_KEYW = 268,     INLINE_KEYW = 269,     INT_KEYW = 270,     LONG_KEYW = 271,     REGISTER_KEYW = 272,     RESTRICT_KEYW = 273,     SHORT_KEYW = 274,     SIGNED_KEYW = 275,     STATIC_KEYW = 276,     STRUCT_KEYW = 277,     TYPEDEF_KEYW = 278,     UNION_KEYW = 279,     UNSIGNED_KEYW = 280,     VOID_KEYW = 281,     VOLATILE_KEYW = 282,     TYPEOF_KEYW = 283,     EXPORT_SYMBOL_KEYW = 284,     ASM_PHRASE = 285,     ATTRIBUTE_PHRASE = 286,     BRACE_PHRASE = 287,     BRACKET_PHRASE = 288,     EXPRESSION_PHRASE = 289,     CHAR = 290,     DOTS = 291,     IDENT = 292,     INT = 293,     REAL = 294,     STRING = 295,     TYPE = 296,     OTHER = 297,     FILENAME = 298   };#endif/* Tokens.  */#define ASM_KEYW 258#define ATTRIBUTE_KEYW 259#define AUTO_KEYW 260#define BOOL_KEYW 261#define CHAR_KEYW 2

⌨️ 快捷键说明

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