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

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

          Posted on 2007-07-20 15:46 ZelluX 閱讀(395) 評論(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


          主站蜘蛛池模板: 涟水县| 仙桃市| 辽中县| 华安县| 大港区| 理塘县| 平凉市| 锦州市| 鹤峰县| 安顺市| 台南县| 专栏| 来安县| 郴州市| 惠州市| 武宁县| 福清市| 曲沃县| 巴林左旗| 襄汾县| 措美县| 齐河县| 长岭县| 汉阴县| 偃师市| 乐东| 宁乡县| 奉新县| 九寨沟县| 仁化县| 石楼县| 丰都县| 太谷县| 宁阳县| 泾川县| 晋州市| 隆尧县| 乐安县| 威海市| 孝感市| 巨野县|