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


          主站蜘蛛池模板: 巴中市| 微博| 鄂州市| 绿春县| 偃师市| 卢湾区| 耒阳市| 苍梧县| 仲巴县| 米脂县| 德阳市| 隆化县| 洮南市| 潞城市| 通州市| 江城| 山东省| 罗源县| 宁化县| 靖州| 正蓝旗| 基隆市| 彝良县| 安达市| 香港| 法库县| 晋州市| 宜州市| 琼中| 宜城市| 拉孜县| 宽城| 五华县| 永寿县| 樟树市| 上饶县| 通榆县| 永吉县| 崇义县| 于都县| 菏泽市|