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

          總算成功的運行了個詞法解析程序

          Posted on 2007-07-20 15:46 ZelluX 閱讀(397) 評論(0)  編輯  收藏 所屬分類: Courses
          書上的例子,計算行號的,但是書中對行的定義是
          line *.\n
          貌似不正確,flex無法解析,改成line (.)*\n就可以了。
          書上的樣例也沒有yywrap,寫了個空函數。
          %{
          /* 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


          主站蜘蛛池模板: 大英县| 务川| 县级市| 沾化县| 克拉玛依市| 兰溪市| 洛宁县| 太湖县| 商都县| 阳高县| 平陆县| 清水县| 新野县| 焦作市| 宽甸| 江西省| 眉山市| 阜城县| 靖安县| 鹤庆县| 漳平市| 平远县| 古蔺县| 文成县| 绥江县| 武邑县| 阿鲁科尔沁旗| 肥东县| 林口县| 海门市| 蛟河市| 漾濞| 明水县| 张家口市| 将乐县| 杨浦区| 绥中县| 昌宁县| 荔浦县| 盘山县| 紫阳县|