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

📄 lex_yy.c

📁 这是一个C程序分析工具
💻 C
📖 第 1 页 / 共 5 页
字号:
#define	YY_INTERACTIVE	1		/* save micro-seconds if 0 */#define	YYLMAX		100		/* token and pushback buffer size *//* * the following must not be redefined. */#define	yy_tbuf	yytext		/* token string */#define	BEGIN		yy_start =#define	REJECT		goto yy_reject#define	NLSTATE		(yy_lastc = YYNEWLINE)#define	YY_INIT		(yy_start = 0, yyleng = yy_end = 0, yy_lastc = YYNEWLINE)#define	yymore()	goto yy_more#define	yyless(n)	if ((n) < 0 || (n) > yy_end) ; \			else { YY_SCANNER; yyleng = (n); YY_USER; }YY_DECL	int	input	YY_ARGS((void));YY_DECL	int	unput	YY_ARGS((int c));/* functions defined in libl.lib */extern	int	yywrap	YY_ARGS((void));extern	void	yyerror	YY_ARGS((char *fmt, ...));extern	void	yycomment	YY_ARGS((char *term));extern	int	yymapch	YY_ARGS((int delim, int escape));#line 8 "scan.l"/*************************************************************   Copyright (c) 1993-1995 by Paul Long  All rights reserved.**************************************************************//*************************************************************   scan.l - This source file contains the lex specification            for Metre's Standard C lexer. It also contains            lexical functions that can be called from the            rules() function and replacement functions for            lex's yywrap() and MKS lex's yygetc().**************************************************************/#include <stdio.h>#include <ctype.h>#include "ytab.h"#include "metreint.h"/*   This determines whether the input is buffered by reading in a line at   a time. Set it to either TRUE or FALSE (1 or 0). You can either do it   here or on the compilation command line, e.g., -DREAD_LINE=0. The   command line takes precedence over whatever is specified here.   There are two reasons why you might want to turn off input buffering.   1. It may not work properly with the version of lex you are using. 2.   If input buffering is enabled, Metre displays the input line along   with many error messages. If this is a preprocessed file, the line   may be misleading because it may look nothing like the original   source line after macro replacement has taken place. It, therefore,   may be better to just never display the input line. You decide.   NOTE: If you are using the parser files that are included in the   distribution in an environment, such as the Mac, that uses an   internal value other then 10 for newline, do not set READ_LINE to 0.   The code that is used when READ_LINE is 1 handles the translation   between the different newline values. Otherwise, the lexer will not   recognize your newlines.*/#ifndef READ_LINE#define READ_LINE TRUE#endif/*   Decide which lex is being used. Flex provides a manifest constant for   this; the others must be inferred based on whether YY_INIT and   YY_INPUT are defined. It is my belief that the combinations of   whether these two manifest constants are defined coincidentally   indicate which lex is being used. I know that this method works with   MKS and AT&T lex; from reading John Levine's book, "lex & yacc," I   also believe that it works with pclex. Note: Berkeley lex is not   considered a distinct lex. At times, it has been AT&T lex and Vern   Paxson's flex. Posix is not considered at all.*/#ifndef FLEX_SCANNER#ifdef YY_INIT#ifdef YY_INPUT#define ABRAXAS_SCANNER#else#define MKS_SCANNER#endif#else#ifdef YY_INPUT/* Implies pre-public flex before flex defined FLEX_SCANNER. Spooky. */#define FLEX_SCANNER#else#define ATT_SCANNER#endif#endif#endif/*   Redefine size of miniscule yytext[]. Should have no affect on other lex's.*/#define MTR_YYTEXT_SIZE 500/*   Redefine for MKS and AT&T lex. I don't explicitly test for   MKS_SCANNER or ATT_SCANNER because YYLMAX should only be defined for   them.*/#ifdef YYLMAX#if YYLMAX < MTR_YYTEXT_SIZE#undef YYLMAX#define YYLMAX MTR_YYTEXT_SIZE#endif#endif/*   Redefine for pclex. I don't explicitly test for ABRAXAS_SCANNER   because F_BUFSIZ should only be defined for it.*/#ifdef F_BUFSIZ#if F_BUFSIZ < MTR_YYTEXT_SIZE#undef F_BUFSIZ#define F_BUFSIZ MTR_YYTEXT_SIZE#endif#endif/*   Prior to version 2.4, flex defined a yywrap() macro. Undefine it just   in case, because I define a yywrap() function. This shouldn't affect   the other lex's.*/#ifdef yywrap#undef yywrap#endif#if READ_LINE/*   I provide a function to replace MKS' yygetc() macro, so undefine the   macro. Should have no affect on other lex's. That's why I don't   explicitly test for MKS_SCANNER.*/#ifdef yygetc#undef yygetc#endif/*   AT&T lex uses stdio.h's getc() to read in characters in its input()   macro. Assuming that getc() is a macro in stdio.h, redefine it to   call my yygetc() macro.*/#ifdef ATT_SCANNER#ifdef getc#undef getc#endif#define getc(x)   yygetc()#endif/*   I know that the following directives make Metre portable across AT&T   lex, MKS lex, and flex. I hope that it also makes Metre portable to   Abraxas' pclex. I don't have pclex, so I can't test this. From   reading John Levine's book, "lex & yacc," flex/pclex expects the   YY_INPUT() macro to read a block of data. If flex/pclex is used, it   will use my definition. If flex/pclex is not used, MKS and AT&T lex   will use it indirectly because yygetc() and getc(), respectively,   also use the macro.   This diagram shows the dependencies and how Metre achieves   compatibility with the four lex's.      getc()                     <-- AT&T lex uses         yygetc()                <-- MKS lex uses            YY_INPUT()           <-- flex/pclex uses               my_yyinput()*/#ifdef YY_INPUT#undef YY_INPUT#endif#define YY_INPUT(b, r, ms) (r = my_yyinput(b, ms))/*   Size of input buffer. Must be as large as the largest expected line,   including newline. Can be overridden on the compilation command line,   e.g., -DINPUT_LINE_MAX_LEN=10000.*/#ifndef INPUT_LINE_MAX_LEN#define INPUT_LINE_MAX_LEN    2048#endif#endif      /* #if READ_LINE *//* Define how to restart lexer based on which lex is being used. */#if defined(MKS_SCANNER) || defined(ABRAXAS_SCANNER)#define MTR_YY_INIT  YY_INIT#elif defined(FLEX_SCANNER)#define MTR_YY_INIT  yyrestart(yyin)#else    /* defined(ATT_SCANNER) should be true */#define MTR_YY_INIT  yy_init()#endif/*   Manifest constants for the equal-sign character in the -D   command-line option.*/#define EQUAL        '='#define EQUAL_SIZE   1/* External variables. *//*   Whether to interleave the input with the output. Set according to the   copy-input option character from the command line.*/BOOLEAN display_input;#if defined(MKS_SCANNER) || defined(ATT_SCANNER)/* Do nothing--the lex takes care of it. */#define INCR_YYLINENO#else/*   I know that MKS and AT&T lex support yylineno. Don't know about the   others. Here's one for them. I use the technique described in John   Levine's book, "lex & yacc," of simply incrementing a line counter   whenever a newline is encountered in the input stream. However, this   is not as accurate as how MKS and AT&T lex do it. They increment the   line counter when the input() macro encounters a newline and   decrement it when it is pushed back via the unput() macro. This   overcomes the problem of incrementing the line counter prematurely   during look-ahead. I took the easy way out for lex's other than MKS   or AT&T--I didn't want to provide my own input() and output() macros   for them. You could modify them, though.*/int yylineno;#define INCR_YYLINENO   (++yylineno)#endif/* Function prototypes for static functions. */#if READ_LINE#if defined(ATT_SCANNER) || defined(MKS_SCANNER)static int yygetc(void);#endifstatic int my_yyinput(char *, int);#endif/*   If using the lexer that I include in the distribution, the internal   value of newline is assumed by the lexer to always be 10 (line feed),   and its tables are constructed accordingly. MS-DOS and UNIX C   compilers also make this assumption. However, some compilers for   other environments use a different value. For example, on the Mac,   the external value and sometimes the internal value of newline is 13.   This would not work with the MKS lexer that I include because the   tables were constructed assuming that newline is 10.   The work-around for this problem is to use an internal representation   for newlines that are read in that is consistent with whatever lexer   we are using. (The environment's normal value is used for the   newlines that are written out.) This is accomplished by substituting   the environment's newlines with newlines that are compatible with the   lexer as they are read in, and then whenever we need to compare a   read-in character to newline, we use the lexer's newline.   I assume that if this is not an MKS lexer with YYNEWLINE defined, it   must be a lexer that you generated. Therefore, it must have built its   tables correctly and so I just use the normal value for newline.   Otherwise, I use the value that the lexer is using for newline,   presumably 10, although I do not make an explicit assumption of that   value here.*/#if defined(MKS_SCANNER) && defined(YYNEWLINE)#define MTR_NEWLINE  YYNEWLINE#else#define MTR_NEWLINE  '\n'#endifstatic void count(void);static void comment(void);static void found_nonstandard(void);static BOOLEAN identifier_defined(char *);static int check_type(void);static unsigned extract_line_number(char *);static char *extract_file_name(char *);#ifdef MKS_SCANNERstatic void *my_memmove(void *, const void *, size_t);/*   The MKS lexer that I provide calls memmove(). However, I could not   find that function in any library accompanying my copy of the Gnu C   compiler (2.6.0, for SunOS), and another user had the same problem   until he linked in the g++ library, which I do not have or could not   find. Therefore, for MKS lexers (I have not noticed other lexers   making calls to memmove()), I always have it call my version of the   function, my_memmove(). Problem solved.*/#define memmove my_memmove#endif#ifdef ATT_SCANNERstatic void yy_init(void);#endif/* Static variables. */#if READ_LINE && (defined(ATT_SCANNER) || defined(MKS_SCANNER))/*   I read the input line into here then feed the lexer one character at   a time from that. This is so that I have the entire line available in   case I need to print the line along with an error message.*/static char input_line[INPUT_LINE_MAX_LEN];#endif/* An input line is one of these three types. */static enum { BLANK_LINE, COMMENT_LINE, CODE_LINE } line_type = BLANK_LINE;/* Whether a tab or space character was found at the beginning of a line. */static BOOLEAN found_tab;static BOOLEAN found_space;/* Number of preprocessor statements in a module. */static unsigned mod_pp;#line 79 "c:/mks/etc/yylex.c"#ifdef	YY_DEBUG#undef	YY_DEBUG#define	YY_DEBUG(fmt, a1, a2)	fprintf(stderr, fmt, a1, a2)#else#define	YY_DEBUG(fmt, a1, a2)#endif/* * The declaration for the lex scanner can be changed by * redefining YYLEX or YYDECL. This must be done if you have * more than one scanner in a program. */#ifndef	YYLEX#define	YYLEX yylex			/* name of lex scanner */#endif#ifndef YYDECL#define	YYDECL	int YYLEX YY_ARGS((void))	/* declaration for lex scanner */#endif/* stdin and stdout may not neccessarily be constants */YY_DECL	FILE   *yyin = NULL;YY_DECL	FILE   *yyout = NULL;YY_DECL	int	yylineno = 1;		/* line number */YY_DECL	int	yyleng = 0;		/* yytext token length *//* * yy_tbuf is an alias for yytext. * yy_sbuf[0:yyleng-1] contains the states corresponding to yy_tbuf. * yy_tbuf[0:yyleng-1] contains the current token. * yy_tbuf[yyleng:yy_end-1] contains pushed-back characters. * When the user action routine is active, * yy_save contains yy_tbuf[yyleng], which is set to '\0'. * Things are different when YY_PRESERVE is defined.  */YY_DECL	unsigned char yy_tbuf [YYLMAX+1]; /* text buffer (really yytext) */static	yy_state_t yy_sbuf [YYLMAX+1];	/* state buffer */static	int	yy_end = 0;		/* end of pushback */static	int	yy_start = 0;		/* start state */static	int	yy_lastc = YYNEWLINE;	/* previous char */

⌨️ 快捷键说明

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