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

📄 scan-gram.c

📁 GNU的词法/语法分析器bison源码
💻 C
📖 第 1 页 / 共 5 页
字号:
#include <get-errno.h>#include <quote.h>#include "complain.h"#include "files.h"#include "getargs.h"#include "gram.h"#include "quotearg.h"#include "reader.h"#include "uniqstr.h"#define YY_USER_INIT					\  do							\    {							\      scanner_cursor.file = current_file;		\      scanner_cursor.line = 1;				\      scanner_cursor.column = 1;			\      code_start = scanner_cursor;			\    }							\  while (0)/* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used.  */int gram_get_lineno (void);FILE *gram_get_in (void);FILE *gram_get_out (void);int gram_get_leng (void);char *gram_get_text (void);void gram_set_lineno (int);void gram_set_in (FILE *);void gram_set_out (FILE *);int gram_get_debug (void);void gram_set_debug (int);int gram_lex_destroy (void);/* Location of scanner cursor.  */boundary scanner_cursor;static void adjust_location (location *, char const *, size_t);#define YY_USER_ACTION  adjust_location (loc, gram_text, gram_leng);static size_t no_cr_read (FILE *, char *, size_t);#define YY_INPUT(buf, result, size) ((result) = no_cr_read (gram_in, buf, size))/* OBSTACK_FOR_STRING -- Used to store all the characters that we need to   keep (to construct ID, STRINGS etc.).  Use the following macros to   use it.   Use STRING_GROW to append what has just been matched, and   STRING_FINISH to end the string (it puts the ending 0).   STRING_FINISH also stores this string in LAST_STRING, which can be   used, and which is used by STRING_FREE to free the last string.  */static struct obstack obstack_for_string;/* A string representing the most recently saved token.  */static char *last_string;#define STRING_GROW   \  obstack_grow (&obstack_for_string, gram_text, gram_leng)#define STRING_FINISH					\  do {							\    obstack_1grow (&obstack_for_string, '\0');		\    last_string = obstack_finish (&obstack_for_string);	\  } while (0)#define STRING_FREE \  obstack_free (&obstack_for_string, last_string)voidscanner_last_string_free (void){  STRING_FREE;}/* Within well-formed rules, RULE_LENGTH is the number of values in   the current rule so far, which says where to find `$0' with respect   to the top of the stack.  It is not the same as the rule->length in   the case of mid rule actions.   Outside of well-formed rules, RULE_LENGTH has an undefined value.  */static int rule_length;static void handle_dollar (int token_type, char *cp, location loc);static void handle_at (int token_type, char *cp, location loc);static void handle_syncline (char *args);static unsigned long int scan_integer (char const *p, int base, location loc);static int convert_ucn_to_byte (char const *hex_text);static void unexpected_eof (boundary, char const *);static void unexpected_newline (boundary, char const *);/* POSIX says that a tag must be both an id and a C union member, but   historically almost any character is allowed in a tag.  We disallow   NUL and newline, as this simplifies our implementation.  *//* Zero or more instances of backslash-newline.  Following GCC, allow   white space between the backslash and the newline.  */#line 989 "scan-gram.c"#define INITIAL 0#define SC_COMMENT 1#define SC_LINE_COMMENT 2#define SC_YACC_COMMENT 3#define SC_STRING 4#define SC_CHARACTER 5#define SC_AFTER_IDENTIFIER 6#define SC_ESCAPED_STRING 7#define SC_ESCAPED_CHARACTER 8#define SC_PRE_CODE 9#define SC_BRACED_CODE 10#define SC_PROLOGUE 11#define SC_EPILOGUE 12#ifndef YY_NO_UNISTD_H/* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. *//* %if-c-only */#include <unistd.h>/* %endif *//* %if-c++-only *//* %endif */#endif#ifndef YY_EXTRA_TYPE#define YY_EXTRA_TYPE void *#endif/* %if-c-only Reentrant structure and macros (non-C++). *//* %if-reentrant *//* %if-reentrant *//* %endif *//* %if-bison-bridge *//* %endif *//* %endif End reentrant structures and macros. *//* Macros after this point can all be overridden by user definitions in * section 1. */#ifndef YY_SKIP_YYWRAP#ifdef __cplusplusextern "C" int gram_wrap (void );#elseextern int gram_wrap (void );#endif#endif/* %not-for-header *//* %ok-for-header *//* %endif */#ifndef yytext_ptrstatic void yy_flex_strncpy (char *,yyconst char *,int );#endif#ifdef YY_NEED_STRLENstatic int yy_flex_strlen (yyconst char * );#endif#ifndef YY_NO_INPUT/* %if-c-only Standard (non-C++) definition *//* %not-for-header */#ifdef __cplusplusstatic int yyinput (void );#elsestatic int input (void );#endif/* %ok-for-header *//* %endif */#endif/* %if-c-only *//* %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/* %if-c-only Standard (non-C++) definition *//* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */#define ECHO (void) fwrite( gram_text, gram_leng, 1, gram_out )/* %endif *//* %if-c++-only C++ definition *//* %endif */#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) \/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \		{ \		int c = '*'; \		size_t n; \		for ( n = 0; n < max_size && \			     (c = getc( gram_in )) != EOF && c != '\n'; ++n ) \			buf[n] = (char) c; \		if ( c == '\n' ) \			buf[n++] = (char) c; \		if ( c == EOF && ferror( gram_in ) ) \			YY_FATAL_ERROR( "input in flex scanner failed" ); \		result = n; \		} \	else \		{ \		errno=0; \		while ( (result = fread(buf, 1, max_size, gram_in))==0 && ferror(gram_in)) \			{ \			if( errno != EINTR) \				{ \				YY_FATAL_ERROR( "input in flex scanner failed" ); \				break; \				} \			errno=0; \			clearerr(gram_in); \			} \		}\\/* %if-c++-only C++ definition \ */\/* %endif */#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/* %if-c-only */#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )/* %endif *//* %if-c++-only *//* %endif */#endif/* %if-tables-serialization structures and prototypes *//* %not-for-header *//* %ok-for-header *//* %not-for-header *//* %tables-yydmap generated elements *//* %endif *//* end tables serialization structures and prototypes *//* %ok-for-header *//* Default declaration of generated scanner - a define so the user can * easily add parameters. */#ifndef YY_DECL#define YY_DECL_IS_OURS 1/* %if-c-only Standard (non-C++) definition */extern int gram_lex (void);#define YY_DECL int gram_lex (void)/* %endif *//* %if-c++-only C++ definition *//* %endif */#endif /* !YY_DECL *//* Code executed at the beginning of each rule, after gram_text and gram_leng * 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/* %% [6.0] YY_RULE_SETUP definition goes here */#define YY_RULE_SETUP \	if ( gram_leng > 0 ) \		YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \				(gram_text[gram_leng - 1] == '\n'); \	YY_USER_ACTION/* %not-for-header *//** The main scanner function which does all the work. */YY_DECL{	register yy_state_type yy_current_state;	register char *yy_cp, *yy_bp;	register int yy_act;    /* %% [7.0] user's declarations go here */#line 144 "scan-gram.l"  /* Nesting level of the current code in braces.  */  int braces_level IF_LINT (= 0);  /* Parent context state, when applicable.  */  int context_state IF_LINT (= 0);  /* Token type to return, when applicable.  */  int token_type IF_LINT (= 0);  /* Location of most recent identifier, when applicable.  */  location id_loc IF_LINT (= empty_location);  /* Where containing code started, when applicable.  Its initial     value is relevant only when gram_lex is invoked in the SC_EPILOGUE     start condition.  */  boundary code_start = scanner_cursor;  /* Where containing comment or string or character literal started,     when applicable.  */  boundary token_start IF_LINT (= scanner_cursor);  /*-----------------------.  | Scanning white space.  |  `-----------------------*/#line 1239 "scan-gram.c"	if ( (yy_init) )		{		(yy_init) = 0;#ifdef YY_USER_INIT		YY_USER_INIT;#endif		if ( ! (yy_start) )			(yy_start) = 1;	/* first start state */		if ( ! gram_in )/* %if-c-only */			gram_in = stdin;/* %endif *//* %if-c++-only *//* %endif */		if ( ! gram_out )/* %if-c-only */			gram_out = stdout;/* %endif *//* %if-c++-only *//* %endif */		if ( ! YY_CURRENT_BUFFER ) {			gram_ensure_buffer_stack ();			YY_CURRENT_BUFFER_LVALUE =				gram__create_buffer(gram_in,YY_BUF_SIZE );		}		gram__load_buffer_state( );		}	while ( 1 )		/* loops until end-of-file is reached */		{/* %% [8.0] yymore()-related code goes here */		yy_cp = (yy_c_buf_p);		/* Support of gram_text. */		*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;/* %% [9.0] code to set up and find next match goes here */		yy_current_state = (yy_start);		yy_current_state += YY_AT_BOL();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 >= 455 )					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 != 454 );		yy_cp = (yy_last_accepting_cpos);		yy_current_state = (yy_last_accepting_state);yy_find_action:/* %% [10.0] code to find the action number goes here */		yy_act = yy_accept[yy_current_state];		YY_DO_BEFORE_ACTION;/* %% [11.0] code for gram_lineno update goes here */do_action:	/* This label is used only to access EOF actions. *//* %% [12.0] debug code goes here */		if ( gram__flex_debug )			{			if ( yy_act == 0 )				fprintf( stderr, "--scanner backing up\n" );

⌨️ 快捷键说明

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