zoukankan      html  css  js  c++  java
  • flex中的注释

    flex 2.5.35
    论文写到此处,遇到点麻烦,随手翻了本书,说下flex中的注释问题。中文版的35页有点问题,所以纠正下。

    下面是p31示例 fb2_2.l

     1 /* 读取多个文件 */
     2 %option noyywrap
     3 
     4 %{
     5 int chars = 0;
     6 int words = 0;
     7 int lines = 0;                                                                                                             
     8 
     9 int  totchars = 0;
    10 int  totwords = 0;
    11 int  totlines = 0;
    12 %}
    13 
    14 %%
    15 //匹配字符串  ♥ 表示空格 
    16 [a-zA-Z]+ { //习惯C风格,所以写成了这样
    17     {  //原因:参见中文版 p9 倒数第9行中括号内的文字
    18         words++; chars += strlen(yytext);   
    19     }
    20     }
    21 
    22   /*匹配
    23    *换行符
    24    */
    25 
     {
    26     {
    27         chars++; lines++;   
    28     }
    29     }
    30 
    31   /* 其它 */
    32 . {
    33     {
    34         chars++;
    35     }
    36     }
    37 
    38 %%
    39 
    40 int main(int argc, char **argv)
    41 {
    42     int i;
    43     if (argc < 2)
    44     {
    45         yylex();
    46         printf("lines:  %8d
    "
    47                "words:  %8d
    "
    48                "chars:  %8d
    ",
    49                lines, words, chars);
    50         return 0;
    51     }
    52 
    53     for (i = 1; i < argc; i++)
    54     {
    55         FILE *f = fopen(argv[i], "r");                                                                                     
    56 
    57         if (!f)
    58         {
    59             perror(argv[i]);
    60             return 1;
    61         }
    62         yyrestart(f);
    63         yylex();
    64         fclose(f);
    65         printf("lines:  %8d
    "
    66                "words:  %8d
    "
    67                "chars:  %8d
    ",
    68                lines, words, chars);
    69         totchars += chars;
    70         totwords += words;
    71         totlines += lines;
    72         chars = 0;
    73         words = 0;
    74         lines = 0;
    75     }
    76     if (argc > 1)
    77     {
    78         printf("totlines:   %8d
    "
    79                "totwords:   %8d
    "
    80                "totchars:   %8d
    ",
    81                totlines, totwords, totchars);
    82     }
    83     return 0;
    84 }
  • 相关阅读:
    Linux下的搜索查找命令的详解(locate)
    Linux下的搜索查找命令的详解(whereis)
    Linux下的搜索查找命令的详解(which)
    Linux下的awk文本分析命令实例(二)
    Linux下的awk文本分析命令实例(一)
    Linux下的awk文本分析命令详解
    Linux下的at定时执行任务命令详解
    六. 元素修改与空值处理
    七. 高级方法
    八. Pandas的轴
  • 原文地址:https://www.cnblogs.com/openix/p/3511253.html
Copyright © 2011-2022 走看看