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

📄 scan.l

📁 这是一个C程序分析工具
💻 L
📖 第 1 页 / 共 3 页
字号:
                           temp_file_name = extract_file_name(yytext);                           if (temp_file_name != NULL)                              input_file_orig_name = temp_file_name;                        }"auto"                  {  /*                              For this and the following keywords, do                              some lexical accounting, fire the keyword                              trigger in case a rule uses a keyword as a                              trigger, then return token to parser.                           */                           count(); return(TK_AUTO); }"break"                 { count(); return(TK_BREAK); }"case"                  { count(); return(TK_CASE); }"char"                  { count(); return(TK_CHAR); }"const"                 { count(); return(TK_CONST); }"continue"              { count(); return(TK_CONTINUE); }"default"               { count(); return(TK_DEFAULT); }"do"                    { count(); return(TK_DO); }"double"                { count(); return(TK_DOUBLE); }"else"                  { count(); return(TK_ELSE); }"enum"                  { count(); return(TK_ENUM); }"extern"                { count(); return(TK_EXTERN); }"float"                 { count(); return(TK_FLOAT); }"for"                   { count(); return(TK_FOR); }"goto"                  { count(); return(TK_GOTO); }"if"                    { count(); return(TK_IF); }"int"                   { count(); return(TK_INT); }"long"                  { count(); return(TK_LONG); }"register"              { count(); return(TK_REGISTER); }"return"                { count(); return(TK_RETURN); }"short"                 { count(); return(TK_SHORT); }"signed"                { count(); return(TK_SIGNED); }"sizeof"                { count(); return(TK_SIZEOF); }"static"                { count(); return(TK_STATIC); }"struct"                { count(); return(TK_STRUCT); }"switch"                { count(); return(TK_SWITCH); }"typedef"               { count(); return(TK_TYPEDEF); }"union"                 { count(); return(TK_UNION); }"unsigned"              { count(); return(TK_UNSIGNED); }"void"                  { count(); return(TK_VOID); }"volatile"              { count(); return(TK_VOLATILE); }"while"                 { count(); return(TK_WHILE); }{L}({L}|{D})*           {                           /*                              If a replacement was provided on the                              command line for this identifier, rescan                              input which will now have the replacement                              characters. Otherwise, do some lexical                              accounting and return token to parser                              (this is either an identifier or a typedef                              type name).                           */                           if (!identifier_defined(yytext))                           {                              count();                              return(check_type());                           }                        }0[xX]{H}+{IS}?          {  /*                              For this and the following constants and                              string literals, do some lexical                              accounting and return token to parser.                           */                           count(); return(TK_CONSTANT); }0{D}+{IS}?              { count(); return(TK_CONSTANT); }{D}+{IS}?               { count(); return(TK_CONSTANT); }'(\\.|[^\\'])+'         { count(); return(TK_CONSTANT); }{D}+{E}{FS}?            { count(); return(TK_CONSTANT); }{D}*"."{D}+({E})?{FS}?  { count(); return(TK_CONSTANT); }{D}+"."{D}*({E})?{FS}?  { count(); return(TK_CONSTANT); }\"(\\.|[^\\"])*\"       { count(); return(TK_STRING_LITERAL); }"\.\.\."                {  /*                              For this and the following operators, do                              some lexical accounting and return token                              to parser.                           */                           count(); return(TK_ELIPSIS); }">>="                   { count(); return(TK_RIGHT_ASSIGN); }"<<="                   { count(); return(TK_LEFT_ASSIGN); }"+="                    { count(); return(TK_ADD_ASSIGN); }"-="                    { count(); return(TK_SUB_ASSIGN); }"*="                    { count(); return(TK_MUL_ASSIGN); }"/="                    { count(); return(TK_DIV_ASSIGN); }"%="                    { count(); return(TK_MOD_ASSIGN); }"&="                    { count(); return(TK_AND_ASSIGN); }"^="                    { count(); return(TK_XOR_ASSIGN); }"|="                    { count(); return(TK_OR_ASSIGN); }">>"                    { count(); return(TK_RIGHT_OP); }"<<"                    { count(); return(TK_LEFT_OP); }"++"                    { count(); return(TK_INC_OP); }"--"                    { count(); return(TK_DEC_OP); }"->"                    { count(); return(TK_PTR_OP); }"&&"                    { count(); return(TK_AND_OP); }"||"                    { count(); return(TK_OR_OP); }"<="                    { count(); return(TK_LE_OP); }">="                    { count(); return(TK_GE_OP); }"=="                    { count(); return(TK_EQ_OP); }"!="                    { count(); return(TK_NE_OP); }";"                     { count(); return(';'); }"{"                     { count(); return('{'); }"}"                     { count(); return('}'); }","                     { count(); return(','); }":"                     { count(); return(':'); }"="                     { count(); return('='); }"("                     { count(); return('('); }")"                     { count(); return(')'); }"["                     { count(); return('['); }"]"                     { count(); return(']'); }"."                     { count(); return('.'); }"&"                     { count(); return('&'); }"!"                     { count(); return('!'); }"~"                     { count(); return('~'); }"-"                     { count(); return('-'); }"+"                     { count(); return('+'); }"*"                     { count(); return('*'); }"/"                     { count(); return('/'); }"%"                     { count(); return('%'); }"<"                     { count(); return('<'); }">"                     { count(); return('>'); }"^"                     { count(); return('^'); }"|"                     { count(); return('|'); }"?"                     { count(); return('?'); }{LWSC}                  {  /* Absorb whitespace character. */                           count(); }\n                      { INCR_YYLINENO; count(); }^{LWSC}*#.*             {  /*                              Count but otherwise ignore preprocessor                              directives.                           */                           ++mod_pp;                           count(); }.                       {  /* Trap any non-standard characters. */                           count(); found_nonstandard(); }%%/*   If a replacement string was specified on command line, substitute for   this lexeme. Return whether this identifier had a replacement string.*/static BOOLEAN identifier_defined(char *id){   unsigned i;   /*      Look through command-line arguments for the define option character.      (Skip argument 0 because that is the command itself.)   */   for (i = 1; i < cmd_line_argc; ++i)      if (strchr(OPT_INTRO_CHARS, cmd_line_argv[i][0]) != NULL &&            cmd_line_argv[i][OPTION_START] == DEFINE_OPT_CHAR)      {         char *repl_str;         unsigned repl_len;         /* Look for equal sign after identifier. */         repl_str = (char *)strchr(&cmd_line_argv[i][OPTION_STRING_START],               EQUAL);         /*            If equal sign found and this is a define for this            identifier, substitute replacement string for this lexeme.         */         if (repl_str != NULL &&               strncmp(&cmd_line_argv[i][OPTION_STRING_START], id,               (repl_len = repl_str - &cmd_line_argv[i][OPTION_STRING_START]))               == 0 && id[repl_len] == '\0')         {            unsigned len;            char *p;            /*               unput replacement string so that lex will scan it in as               if it occurred in the input stream instead of the               original identifier. NOTE: If empty replacement string,               the affect is that the identifier is ignored.            */            for (len = strlen(&repl_str[EQUAL_SIZE]), p = &repl_str[len];                  len > 0; --len, --p)               unput(*p);            /*               Leave outer loop because define option character found               and processed.            */            break;         }      }   return i < cmd_line_argc;}/* Initialize lexer. */void init_lex(void){   /*      Restart lex itself. Note: I don't believe that this is absolutely      necessary for this lexer. The lexer is not left in an unusual      state after each file, e.g., characters left in the push-back      buffer or the lexer being in a state other than INITIAL. It is      explicitly restarted here just because "it's the right thing to      do."  If this macro reference expands to something that is not      compatible with your lexer, although I tried to make it portable,      just remove it.   */   if (yyin != NULL)      MTR_YY_INIT;   /* Reset line_type for first line. Start off assuming blank line. */   line_type = BLANK_LINE;   yylineno = 1;   found_tab = FALSE;   found_space = FALSE;   mod_pp = 0;}#ifdef ATT_SCANNER/* Function that restarts AT&T lexers. */static void yy_init(void){   extern int yyprevious;   NLSTATE;   yysptr = yysbuf;   BEGIN INITIAL;/* I don't think these absolutely need to be reset. */#if 0   extern int *yyfnd;   yyleng = 0;   yytchar = 0;   yymorfg = 0;   yyestate = 0;   yyfnd = 0;#endif}#endif#if READ_LINE#if defined(ATT_SCANNER) || defined(MKS_SCANNER)/* Pointer to next character in input_line[]. */static char *next_char_p;/*   Replacement for the out-of-the-box yygetc(). This function provides   access to the entire input line, even the characters that have not   yet been scanned in.*/static int yygetc(void){   static int last_char = EOF;      /* Force subsequent getting of first line.*/   int next_char;   int characters_read;   switch (last_char)   {   case MTR_NEWLINE:                /* Time to get another line of input? */   case EOF:      YY_INPUT(input_line, characters_read, INPUT_LINE_MAX_LEN);      if (characters_read == 0)      {         next_char = EOF;           /* Indicate that couldn't get another line*/         next_char_p = input_line;  /* Set to something. */      }      else      {         next_char_p = input_line;         next_char = *next_char_p++;   /* Get first character from input line. */      }      break;   default:                         /* Get next character from input line. */      /*         If going to get the character that is immediately _after_ the         input buffer, something's wrong, so report a fatal error and         terminate. Either the source line is too big for the buffer, in         which case increasing the size of the buffer (input_line[])         might help, or your C compiler's idea of what constitutes a         "newline" doesn't agree with the newlines in the source file         that you are processing.      */      if (next_char_p >= input_line + sizeof input_line)      {         /*            Terminate input buffer with newline and string terminator in            case they are missing.         */         input_line[sizeof input_line - 2] = '\n';         input_line[sizeof input_line - 1] = '\0';         int_fatal(E_OVERRAN_INPUT_BUFFER);      }      next_char = *next_char_p++;   }/*   If the C compiler uses a different value for the internal   representation of newline than what the lexer uses to build its   tables, substitute the lexer's newline for the compiler's newline.   This should be a rare thing, however, such as when the lexer included   in the distribution, which was generated for a newline of 10, is used   on a system such as the Mac where newlines may be represented   internally by 13. Also see the explanation near the #define of   MTR_NEWLINE.*/#if MTR_NEWLINE != '\n'   if (next_char == '\n')      next_char = MTR_NEWLINE;#endif   last_char = next_char;   return next_char;}#endif      /* #if defined(ATT_SCANNER) || defined(MKS_SCANNER) *//* Read next line from input file, returning number of characters read. */static int my_yyinput(char *buf, int max_size){   if (fgets(buf, max_size, yyin) == NULL)      buf[0] = '\0';   else      /* This is where the input line is printed if display_print is TRUE. */      if (display_input)         fputs(buf, out_fp);   return strlen(buf);}#endif      /* #if READ_LINE *//*   Called by yacc at the end of a source file. If there are more files   to process, open them and continue, else stop.*/int yywrap()

⌨️ 快捷键说明

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