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


          主站蜘蛛池模板: 宝山区| 连城县| 库尔勒市| 洮南市| 会同县| 资溪县| 安新县| 琼海市| 达州市| 红安县| 游戏| 蓬莱市| 道真| 磐安县| 蚌埠市| 沙坪坝区| 枝江市| 雅安市| 昆明市| 道孚县| 浦县| 五大连池市| 江北区| 梧州市| 奉贤区| 乌什县| 昌平区| 凤山市| 夏河县| 万宁市| 江西省| 称多县| 遵义县| 武城县| 逊克县| 广州市| 宁德市| 平舆县| 延边| 博客| 阿图什市|