亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tutor10.doc

?? 計算機編譯原理教材
?? DOC
?? 第 1 頁 / 共 5 頁
字號:


       {---------------------------------------------------------------}
       { Recognize and Translate an IF Construct }

       procedure Block; Forward;


       procedure DoIf;
       var L1, L2: string;
       begin
          Match('i');
          BoolExpression;
          L1 := NewLabel;
          L2 := L1;
          BranchFalse(L1);
          Block;
          if Look = 'l' then begin
             Match('l');
             L2 := NewLabel;
             Branch(L2);
             PostLabel(L1);
             Block;
          end;
          PostLabel(L2);
          Match('e');
       end;


       {--------------------------------------------------------------}
       { Parse and Translate a WHILE Statement }A62A6
                                    - 29 -A*2A*

PA2A





       procedure DoWhile;
       var L1, L2: string;
       begin
          Match('w');
          L1 := NewLabel;
          L2 := NewLabel;
          PostLabel(L1);
          BoolExpression;
          BranchFalse(L2);
          Block;
          Match('e');
          Branch(L1);
          PostLabel(L2);
       end;
       {--------------------------------------------------------------}


       To tie everything  together,  we need only modify procedure Block
       to recognize the "keywords" for the  IF  and WHILE.  As usual, we
       expand the definition of a block like so:


            <block> ::= ( <statement> )*


       where


            <statement> ::= <if> | <while> | <assignment>


       The corresponding code is:


       {--------------------------------------------------------------}
       { Parse and Translate a Block of Statements }

       procedure Block;
       begin
          while not(Look in ['e', 'l']) do begin
             case Look of
              'i': DoIf;
              'w': DoWhile;
             else Assignment;
             end;
          end;
       end;
       {--------------------------------------------------------------}


       OK,  add the routines I've given, compile and  test  them.    You
       should be able to parse the single-character versions  of  any of
       the control constructs.  It's looking pretty good!A62A6
                                    - 30 -A*2A*

PA2A





       As a matter  of  fact, except for the single-character limitation
       we've got a virtually complete version of TINY.  I call  it, with
       tongue planted firmly in cheek, TINY Version 0.1.


       LEXICAL SCANNING

       Of course, you know what's next:  We have to convert  the program
       so that  it can deal with multi-character keywords, newlines, and
       whitespace.   We have just gone through all  that  in  Part  VII.
       We'll use the distributed scanner  technique that I showed you in
       that  installment.    The  actual  implementation  is   a  little
       different because the way I'm handling newlines is different.

       To begin with, let's simply  allow for whitespace.  This involves
       only adding calls to SkipWhite at the end of the  three routines,
       GetName, GetNum, and Match.    A call to SkipWhite in Init primes
       the pump in case there are leading spaces.

       Next, we need to deal with  newlines.   This is really a two-step
       process,  since  the  treatment  of  the  newlines  with  single-
       character tokens is different from that for multi-character ones.
       We can eliminate some work by doing both  steps  at  once,  but I
       feel safer taking things one step at a time.

       Insert the new procedure:


       {--------------------------------------------------------------}
       { Skip Over an End-of-Line }

       procedure NewLine;
       begin
          while Look = CR do begin
             GetChar;
             if Look = LF then GetChar;
             SkipWhite;
          end;
       end;
       {--------------------------------------------------------------}


       Note that  we  have  seen  this  procedure  before in the form of
       Procedure Fin.  I've changed the name since this  new  one  seems
       more descriptive of the actual function.  I've  also  changed the
       code  to  allow  for multiple newlines and lines with nothing but
       white space.

       The next step is to insert calls to NewLine wherever we  decide a
       newline is permissible.  As I've pointed out before, this  can be
       very different in different languages.   In TINY, I've decided to
       allow them virtually anywhere.  This means that we need  calls to
       NewLine at the BEGINNING (not the end, as with SkipWhite)  of the
       procedures GetName, GetNum, and Match.A*2A*
                                    - 31 -

PA2A





       For procedures that have while loops, such as TopDecl, we  need a
       call  to NewLine at the beginning of the  procedure  AND  at  the
       bottom  of  each  loop.  That way, we can be assured that NewLine
       has just been called at the beginning of each  pass  through  the
       loop.

       If you've got all this done, try the program out and  verify that
       it will indeed handle white space and newlines.

       If it does, then we're  ready to deal with multi-character tokens
       and keywords.   To begin, add the additional declarations (copied
       almost verbatim from Part VII):


       {--------------------------------------------------------------}
       { Type Declarations }

       type Symbol = string[8];

            SymTab = array[1..1000] of Symbol;

            TabPtr = ^SymTab;


       {--------------------------------------------------------------}
       { Variable Declarations }

       var Look : char;             { Lookahead Character }
           Token: char;             { Encoded Token       }
           Value: string[16];       { Unencoded Token     }

           ST: Array['A'..'Z'] of char;

       {--------------------------------------------------------------}
       { Definition of Keywords and Token Types }

       const NKW =   9;
             NKW1 = 10;

       const KWlist: array[1..NKW] of Symbol =
                     ('IF', 'ELSE', 'ENDIF', 'WHILE', 'ENDWHILE',
                      'VAR', 'BEGIN', 'END', 'PROGRAM');

       const KWcode: string[NKW1] = 'xilewevbep';
       {--------------------------------------------------------------}


       Next, add the three procedures, also from Part VII:


       {--------------------------------------------------------------}
       { Table Lookup }

       function Lookup(T: TabPtr; s: string; n: integer): integer;A*2A*
                                    - 32 -

PA2A





       var i: integer;
           found: Boolean;
       begin
          found := false;
          i := n;
          while (i > 0) and not found do
             if s = T^[i] then
                found := true
             else
                dec(i);
          Lookup := i;
       end;
       {--------------------------------------------------------------}
       .
       .
       {--------------------------------------------------------------}
       { Get an Identifier and Scan it for Keywords }

       procedure Scan;
       begin
          GetName;
          Token := KWcode[Lookup(Addr(KWlist), Value, NKW) + 1];
       end;
       {--------------------------------------------------------------}
       .
       .
       {--------------------------------------------------------------}
       { Match a Specific Input String }

       procedure MatchString(x: string);
       begin
          if Value <> x then Expected('''' + x + '''');
       end;
       {--------------------------------------------------------------}


       Now, we have to make a  fairly  large number of subtle changes to
       the remaining procedures.  First,  we  must  change  the function
       GetName to a procedure, again as we did in Part VII:


       {--------------------------------------------------------------}
       { Get an Identifier }

       procedure GetName;
       begin
          NewLine;
          if not IsAlpha(Look) then Expected('Name');
          Value := '';
          while IsAlNum(Look) do begin
             Value := Value + UpCase(Look);
             GetChar;
          end;
          SkipWhite;A*2A*
                                    - 33 -

PA2A





       end;
       {--------------------------------------------------------------}


       Note that this procedure leaves its result in  the  global string
       Value.

       Next, we have to change every reference to GetName to reflect its
       new form. These occur in Factor, Assignment, and Decl:


       {---------------------------------------------------------------}
       { Parse and Translate a Math Factor }

       procedure BoolExpression; Forward;

       procedure Factor;
       begin
          if Look = '(' then begin
             Match('(');
             BoolExpression;
             Match(')');
             end
          else if IsAlpha(Look) then begin
             GetName;
             LoadVar(Value[1]);
             end
          else
             LoadConst(GetNum);
       end;
       {--------------------------------------------------------------}
       .
       .
       {--------------------------------------------------------------}
       { Parse and Translate an Assignment Statement }

       procedure Assignment;
       var Name: char;
       begin
          Name := Value[1];
          Match('=');
          BoolExpression;
          Store(Name);
       end;
       {---------------------------------------------------------------}
       .
       .
       {--------------------------------------------------------------}
       { Parse and Translate a Data Declaration }

       procedure Decl;
       begin
          GetName;
          Alloc(Value[1]);A*2A*
                                    - 34 -

PA2A





          while Look = ',' do begin
             Match(',');
             GetName;
             Alloc(Value[1]);
          end;
       end;
       {--------------------------------------------------------------}


       (Note that we're still  only  allowing  single-character variable
       names,  so we take the easy way out here and simply use the first
       character of the string.)

       Finally, we must make the changes to use Token instead of Look as
       the  test  character  and to call Scan at the appropriate places.
       Mostly, this  involves  deleting  calls  to  Match,  occasionally
       replacing calls to  Match  by calls to MatchString, and Replacing
       calls  to  NewLine  by  calls  to  Scan.    Here are the affected
       routines:

       {---------------------------------------------------------------}
       { Recognize and Translate an IF Construct }

       procedure Block; Forward;


       procedure DoIf;
       var L1, L2: string;
       begin
          BoolExpression;
          L1 := NewLabel;
          L2 := L1;
          BranchFalse(L1);
          Block;
          if Token = 'l' then begin
             L2 := NewLabel;
             Branch(L2);
             PostLabel(L1);
             Block;
          end;
          PostLabel(L2);
          MatchString('ENDIF');
       end;


       {--------------------------------------------------------------}
       { Parse and Translate a WHILE Statement }

       procedure DoWhile;
       var L1, L2: string;
       begin
          L1 := NewLabel;
          L2 := NewLabel;
          PostLabel(L1);A*2A*
                                    - 35 -

PA2A





          BoolExpression;
          BranchFalse(L2);
          Block;
          MatchString('ENDWHILE');
          Branch(L1);
          PostLabel(L2);
       end;


       {--------------------------------------------------------------}
       { Parse and Translate a Block of Statements }

       procedure Block;
       begin
          Scan;
          while not(Token in ['e', 'l']) do begin
             case Token of
              'i': DoIf;
              'w': DoWhile;
             else Assignment;
             end;
             Scan;
          end;
       end;


       {--------------------------------------------------------------}
       { Parse and Translate Global Decl

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
综合在线观看色| 日韩欧美高清在线| 亚洲线精品一区二区三区八戒| 91亚洲大成网污www| 亚洲精品中文字幕乱码三区| 91亚洲大成网污www| 亚洲午夜国产一区99re久久| 91麻豆精品国产综合久久久久久| 久久精品免费看| 久久久精品黄色| av在线一区二区| 香蕉久久一区二区不卡无毒影院 | 亚洲午夜久久久| 欧美精品 国产精品| 麻豆精品一二三| 国产午夜亚洲精品羞羞网站| 91免费国产在线观看| 亚洲成人免费看| 久久久不卡网国产精品一区| 成人av中文字幕| 亚洲1区2区3区视频| 精品日韩成人av| 成人网在线免费视频| 亚洲一区二区欧美日韩| 日韩免费视频一区二区| av在线不卡电影| 日韩高清在线不卡| 久久精品视频一区| 欧美影院精品一区| 精品制服美女久久| 亚洲欧美日韩一区二区| 制服丝袜激情欧洲亚洲| 成人黄色av电影| 日韩激情av在线| 中文字幕亚洲综合久久菠萝蜜| 欧美日韩国产一二三| 丁香婷婷综合色啪| 免费精品视频最新在线| 国内精品免费**视频| 自拍偷拍国产精品| 欧美成人精品福利| 欧美吞精做爰啪啪高潮| 成人一区二区视频| 久久99久久精品| 亚洲午夜久久久久久久久电影网 | 26uuu精品一区二区| 色噜噜狠狠色综合欧洲selulu| 激情亚洲综合在线| 亚洲国产一区二区三区| 国产精品你懂的在线| 精品奇米国产一区二区三区| 欧洲精品一区二区| av电影在线观看一区| 国模大尺度一区二区三区| 五月天丁香久久| 亚洲靠逼com| 国产精品女人毛片| 国产三级精品在线| 欧美tickling挠脚心丨vk| 欧美日韩精品一区二区天天拍小说| 国产精品一区久久久久| 捆绑调教一区二区三区| 午夜精品在线看| 一区av在线播放| 综合分类小说区另类春色亚洲小说欧美 | 性做久久久久久免费观看| 中文字幕字幕中文在线中不卡视频| 日韩欧美国产一区二区在线播放 | 中文字幕中文字幕一区| 精品国产精品一区二区夜夜嗨| 欧美丝袜丝nylons| 日本精品裸体写真集在线观看| 91免费版在线| 99国产精品国产精品毛片| av午夜精品一区二区三区| 风间由美一区二区三区在线观看 | 欧美成人福利视频| 日韩视频一区二区三区在线播放| 91国产成人在线| 日本高清不卡在线观看| 一本大道av伊人久久综合| 91美女片黄在线观看| 色www精品视频在线观看| 色偷偷久久一区二区三区| 色偷偷久久一区二区三区| 91福利精品第一导航| 欧美三级在线播放| 9191国产精品| 日韩一区二区在线观看视频播放| 欧美一级片免费看| 2024国产精品视频| 日本一区二区三区在线观看| 亚洲视频每日更新| 午夜精品福利一区二区三区av| 91美女片黄在线观看91美女| 日本道免费精品一区二区三区| 欧美性生活大片视频| 在线播放中文字幕一区| 精品国产一区二区三区忘忧草| 国产欧美一区二区在线| 亚洲天堂av老司机| 日韩电影在线免费观看| 国产米奇在线777精品观看| 成人黄色a**站在线观看| 91激情五月电影| 日韩亚洲欧美综合| 国产精品欧美综合在线| 亚洲国产精品久久人人爱| 美国十次综合导航| av中文一区二区三区| 正在播放亚洲一区| 国产色产综合色产在线视频| 亚洲制服丝袜av| 精品在线免费观看| 91免费视频观看| 欧美一级二级三级蜜桃| 中文字幕第一页久久| 五月激情综合色| 成人国产精品免费观看视频| 欧美日韩国产一二三| 欧美国产一区二区在线观看| 亚洲综合久久久久| 国产成人高清在线| 欧美日韩在线三区| 日本一区二区综合亚洲| 亚洲电影视频在线| 久久99在线观看| 丰满亚洲少妇av| 欧美午夜一区二区| 日韩精品一区二区在线观看| 亚洲精品在线免费观看视频| 亚洲国产综合色| 国产成人午夜高潮毛片| 欧美三级日韩在线| 国产精品视频第一区| 青青青伊人色综合久久| 色偷偷88欧美精品久久久| 久久综合色8888| 日本不卡不码高清免费观看| 97精品视频在线观看自产线路二| 精品美女一区二区三区| 亚洲一区在线观看网站| 99re热视频精品| 久久嫩草精品久久久精品一| 爽爽淫人综合网网站| 色综合久久久网| 欧美激情在线一区二区| 麻豆精品国产91久久久久久| 91久久精品一区二区三区| 国产精品福利影院| 韩国欧美一区二区| 欧美一区二区三区不卡| 亚洲综合另类小说| 99在线精品观看| 国产视频一区二区三区在线观看| 久久福利视频一区二区| 欧美片网站yy| 亚洲成人自拍偷拍| 欧美日韩亚洲综合| 亚洲一区二区在线视频| 91免费观看在线| 亚洲人成亚洲人成在线观看图片| 成人激情开心网| 欧美国产精品专区| 国产成人精品免费视频网站| 久久综合五月天婷婷伊人| 久色婷婷小香蕉久久| 精品人伦一区二区色婷婷| 美女在线观看视频一区二区| 欧美一区二区在线观看| 日韩黄色一级片| 日韩欧美123| 精品国产免费人成电影在线观看四季 | 一区二区三区在线观看动漫| 波多野结衣中文一区| 国产精品丝袜黑色高跟| 成人免费高清在线观看| ...xxx性欧美| 欧美综合天天夜夜久久| 一区二区三区91| 精品视频在线免费| 日韩电影免费一区| 欧美xxxx老人做受| 国产在线精品免费| 国产精品毛片无遮挡高清| 91亚洲精品乱码久久久久久蜜桃| 亚洲免费资源在线播放| 欧美视频中文字幕| 蜜臀99久久精品久久久久久软件| 日韩免费视频一区| 国产suv一区二区三区88区| 亚洲三级电影网站| 欧美午夜影院一区| 久久精品国产色蜜蜜麻豆| 国产偷国产偷亚洲高清人白洁 | 亚洲图片激情小说| 欧美日韩国产欧美日美国产精品| 爽爽淫人综合网网站| 久久精品亚洲精品国产欧美| 色婷婷综合久久久久中文一区二区 |