posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          總算成功的運(yùn)行了個詞法解析程序

          Posted on 2007-07-20 15:46 ZelluX 閱讀(397) 評論(0)  編輯  收藏 所屬分類: Courses
          書上的例子,計算行號的,但是書中對行的定義是
          line *.\n
          貌似不正確,flex無法解析,改成line (.)*\n就可以了。
          書上的樣例也沒有yywrap,寫了個空函數(shù)。
          %{
          /* a Lex program that adds line numbers
             to lines of text, printing the new text
             to the standard output
          */
          #include 
          <stdio.h>
          int lineno = 1;
          %}
          line (.)
          *\n 
          %%
          {line} { printf (
          "%5d %s", lineno++, yytext); }
          %%
          main()
          {
              yylex();
              
          return 0;
          }
          int yywrap()
          {
              
          return 0;
          }
          生成flex程序:flex linecount.lex
          編譯:gcc lex.yy.c
          利用管道輸入剛才的程序:cat linecount.lex | ./a.out


          主站蜘蛛池模板: 红安县| 剑河县| 嘉义县| 雅江县| 惠州市| 西丰县| 紫云| 汶上县| 棋牌| 丰镇市| 郯城县| 田林县| 玛沁县| 武定县| 乌什县| 宣威市| 同仁县| 平塘县| 梁山县| 建昌县| 彭阳县| 冀州市| 遵化市| 丹棱县| 桂林市| 海城市| 阿城市| 新龙县| 白山市| 油尖旺区| 吉首市| 乌兰察布市| 沧州市| 丹江口市| 武清区| 桂阳县| 中江县| 南木林县| 开原市| 宜春市| 遵义县|