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

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

?? tutor10.doc

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





            <data declaration> ::= VAR <var-list>


       Note that since there is only one variable type, there is no need
       to  declare the type.  Later on, for full KISS, we can easily add
       a type description.

       The procedure Prog becomes:


       {--------------------------------------------------------------}
       {  Parse and Translate a Program }

       procedure Prog;
       begin
          Match('p');
          Header;
          TopDecls;
          Main;
          Match('.');
       end;
       {--------------------------------------------------------------}


       Now, add the two new procedures:


       {--------------------------------------------------------------}
       { Process a Data Declaration }

       procedure Decl;
       begin
          Match('v');
          GetChar;
       end;


       {--------------------------------------------------------------}
       { Parse and Translate Global Declarations }

       procedure TopDecls;
       begin
          while Look <> 'b' do
             case Look of
               'v': Decl;
             else Abort('Unrecognized Keyword ''' + Look + '''');
             end;
       end;
       {--------------------------------------------------------------}


       Note that at this point, Decl  is  just  a stub.  It generates no
       code, and it doesn't process a list ... every variable must occur
       in a separate VAR statement.A*2A*
                                     - 8 -

PA2A





       OK,  now  we  can have any  number  of  data  declarations,  each
       starting with a 'v' for VAR,  before  the BEGIN-block.  Try a few
       cases and see what happens.


       DECLARATIONS AND SYMBOLS

       That looks pretty good, but  we're still only generating the null
       program  for  output.    A  real compiler would  issue  assembler
       directives to allocate storage for  the  variables.    It's about
       time we actually produced some code.

       With  a  little  extra  code,  that's  an  easy  thing to do from
       procedure Decl.  Modify it as follows:


       {--------------------------------------------------------------}
       { Parse and Translate a Data Declaration }

       procedure Decl;
       var Name: char;
       begin
          Match('v');
          Alloc(GetName);
       end;
       {--------------------------------------------------------------}


       The procedure Alloc just  issues  a  command  to the assembler to
       allocate storage:


       {--------------------------------------------------------------}
       { Allocate Storage for a Variable }

       procedure Alloc(N: char);
       begin
          WriteLn(N, ':', TAB, 'DC 0');
       end;
       {--------------------------------------------------------------}


       Give  this  one  a  whirl.    Try  an  input  that declares  some
       variables, such as:

            pvxvyvzbe.

       See how the storage is allocated?    Simple, huh?  Note also that
       the entry point, "MAIN," comes out in the right place.

       For the record, a "real" compiler would also have a  symbol table
       to record the variables being used.  Normally,  the  symbol table
       is necessary to record the type  of  each variable.  But since in
       this case  all  variables  have  the  same  type, we don't need aA*2A*
                                     - 9 -

PA2A





       symbol  table  for  that reason.  As it turns out, we're going to
       find a symbol  necessary  even without different types, but let's
       postpone that need until it arises.

       Of course, we haven't really parsed the correct syntax for a data
       declaration, since it involves a variable list.  Our version only
       permits a single variable.  That's easy to fix, too.

       The BNF for <var-list> is


            <var-list> ::= <ident> (, <ident>)*


       Adding this syntax to Decl gives this new version:


       {--------------------------------------------------------------}
       { Parse and Translate a Data Declaration }

       procedure Decl;
       var Name: char;
       begin
          Match('v');
          Alloc(GetName);
          while Look = ',' do begin
             GetChar;
             Alloc(GetName);
          end;
       end;
       {--------------------------------------------------------------}


       OK, now compile this code and give it  a  try.    Try a number of
       lines of VAR declarations, try a list of several variables on one
       line, and try combinations of the two.  Does it work?


       INITIALIZERS

       As long as we're dealing with data declarations, one thing that's
       always  bothered  me  about  Pascal  is  that  it  doesn't  allow
       initializing  data items in the declaration.    That  feature  is
       admittedly sort of a frill, and it  may  be  out  of  place  in a
       language that purports to  be  a minimal language.  But it's also
       SO easy to add that it seems a shame not  to  do  so.    The  BNF
       becomes:


            <var-list> ::= <var> ( <var> )*

            <var> ::= <ident> [ = <integer> ]AB2AB
                                    - 10 -A*2A*

PA2A





       Change Alloc as follows:


       {--------------------------------------------------------------}
       { Allocate Storage for a Variable }

       procedure Alloc(N: char);
       begin
          Write(N, ':', TAB, 'DC ');
          if Look = '=' then begin
             Match('=');
             WriteLn(GetNum);
             end
          else
             WriteLn('0');
       end;
       {--------------------------------------------------------------}


       There you are: an initializer with six added lines of Pascal.

       OK, try this  version  of  TINY  and verify that you can, indeed,
       give the variables initial values.

       By golly, this thing is starting to look  real!    Of  course, it
       still doesn't DO anything, but it looks good, doesn't it?

       Before leaving this section, I should point out  that  we've used
       two versions of function GetNum.  One, the earlier one, returns a
       character value, a single digit.  The other accepts a multi-digit
       integer and returns an integer value.  Either one will work here,
       since WriteLn will handle either type.  But there's no  reason to
       limit ourselves  to  single-digit  values  here,  so  the correct
       version to use is the one that returns an integer.  Here it is:


       {--------------------------------------------------------------}
       { Get a Number }

       function GetNum: integer;
       var Val: integer;
       begin
          Val := 0;
          if not IsDigit(Look) then Expected('Integer');
          while IsDigit(Look) do begin
             Val := 10 * Val + Ord(Look) - Ord('0');
             GetChar;
          end;
          GetNum := Val;
       end;
       {--------------------------------------------------------------}AN2AN
                                    - 11 -A*2A*

PA2A





       As a matter  of  fact,  strictly  speaking  we  should  allow for
       expressions in the data field of the initializer, or at  the very
       least  for  negative  values.  For  now,  let's  just  allow  for
       negative values by changing the code for Alloc as follows:


       {--------------------------------------------------------------}
       { Allocate Storage for a Variable }

       procedure Alloc(N: char);
       begin
          if InTable(N) then Abort('Duplicate Variable Name ' + N);
          ST[N] := 'v';
          Write(N, ':', TAB, 'DC ');
          if Look = '=' then begin
             Match('=');
             If Look = '-' then begin
                Write(Look);
                Match('-');
             end;
             WriteLn(GetNum);
             end
          else
             WriteLn('0');
       end;
       {--------------------------------------------------------------}


       Now  you should be able to  initialize  variables  with  negative
       and/or multi-digit values.


       THE SYMBOL TABLE

       There's one problem  with  the  compiler  as it stands so far: it
       doesn't do anything to record a variable when we declare it.   So
       the compiler is perfectly content to allocate storage for several
       variables with the same name.  You can easily verify this with an
       input like


            pvavavabe.


       Here we've declared the variable A three times.  As you  can see,
       the compiler will  cheerfully  accept  that,  and  generate three
       identical labels.  Not good.

       Later on,  when we start referencing variables, the compiler will
       also let us reference variables  that don't exist.  The assembler
       will  catch  both  of these error conditions, but it doesn't seem
       friendly at all to pass such errors along to the assembler.   The
       compiler should catch such things at the source language level.A62A6
                                    - 12 -A*2A*

PA2A





       So even though we don't need a symbol table to record data types,
       we ought to install  one  just to check for these two conditions.
       Since at this  point  we are still restricted to single-character
       variable names, the symbol table can be trivial.  To  provide for
       it, first add the following  declaration at the beginning of your
       program:


            var ST: array['A'..'Z'] of char;


       and insert the following function:


       {--------------------------------------------------------------}
       { Look for Symbol in Table }

       function InTable(n: char): Boolean;
       begin
          InTable := ST[n] <> ' ';
       end;
       {--------------------------------------------------------------}


       We  also  need  to initialize the  table  to  all  blanks.    The
       following lines in Init will do the job:


       var i: char;
       begin
          for i := 'A' to 'Z' do
             ST[i] := ' ';
          ...


       Finally,  insert  the  following two lines at  the  beginning  of
       Alloc:


          if InTable(N) then Abort('Duplicate Variable Name ' + N);
          ST[N] := 'v';


       That  should  do  it.  The  compiler  will  now  catch  duplicate
       declarations.  Later, we can  also  use  InTable  when generating
       references to the variables.


       EXECUTABLE STATEMENTS

       At this point, we can generate a null program that has  some data
       variables  declared  and  possibly initialized.  But  so  far  we
       haven't arranged to generate the first line of executable code.A62A6
                                    - 13 -A*2A*

PA2A





       Believe  it or not, though, we almost  have  a  usable  language!
       What's missing is the executable code that must go into  the main
       program.  But that code is just assignment statements and control
       statements ... all stuff we have done before.   So  it  shouldn't
       take us long to provide for them, as well.

       The BNF definition given earlier  for the main program included a
       statement block, which we have so far ignored:


            <main> ::= BEGIN <block> END


       For now,  we  can  just  consider  a  block  to  be  a  series of
       assignment statements:


            <block> ::= (Assignment)*


       Let's start things off by adding  a  parser for the block.  We'll
       begin with a stub for the assignment statement:


       {--------------------------------------------------------------}
       { Parse and Translate an Assignment Statement }

       procedure Assignment;
       begin
          GetChar;
       end;


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

       procedure Block;
       begin
          while Look <> 'e' do
             Assignment;
       end;
       {--------------------------------------------------------------}


       Modify procedure Main to call Block as shown below:


       {--------------------------------------------------------------}
       { Parse and Translate a Main Program }

       procedure Main;
       begin
          Match('b');
          Prolog;A*2A*
                                    - 14 -

PA2A





          Block;
          Match('e');
          Epilog;
       end;
       {--------------------------------------------------------------}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产免费成人在线视频| 日本sm残虐另类| 91麻豆精品国产91久久久更新时间| 狠狠色丁香婷婷综合| 亚洲美女视频在线| 国产亚洲自拍一区| 日韩一本二本av| 在线精品视频小说1| 国产成人综合视频| 日韩av一区二区在线影视| 国产精品久久久久婷婷二区次| 日韩一区二区不卡| 欧美日韩一区小说| 色天使久久综合网天天| 国产精品一区二区在线看| 麻豆精品国产传媒mv男同| 亚洲一区二区三区免费视频| 国产精品久久久久影院老司| 久久丝袜美腿综合| 精品国产免费人成电影在线观看四季 | 欧美精品免费视频| 色综合一个色综合亚洲| 国产高清精品久久久久| 久久黄色级2电影| 青青草国产精品97视觉盛宴| 亚洲一区二区欧美日韩| 亚洲乱码日产精品bd| 一区视频在线播放| 日本一区二区三区四区| 久久九九国产精品| 久久色视频免费观看| 26uuu亚洲婷婷狠狠天堂| 日韩亚洲欧美综合| 精品人伦一区二区色婷婷| 亚洲成人自拍一区| 亚洲国产成人av好男人在线观看| 亚洲精品久久久蜜桃| 亚洲色图欧洲色图| 亚洲丝袜自拍清纯另类| 成人免费在线观看入口| 亚洲人123区| 一区二区三区欧美日韩| 亚洲精品免费在线| 亚洲午夜免费电影| 偷拍日韩校园综合在线| 日韩不卡一区二区| 日本欧美在线观看| 久久精品国产99| 国产精品1区2区3区在线观看| 国产黄色精品网站| 99久免费精品视频在线观看| 99免费精品在线| 欧美视频在线不卡| 欧美一卡在线观看| 久久女同精品一区二区| 中文字幕一区二区三区在线观看| 亚洲欧美自拍偷拍色图| 一区二区三区毛片| 蜜臀久久久久久久| 国产在线播放一区| 成人av影院在线| 欧美午夜免费电影| 蜜臀av一区二区在线观看| 激情综合色丁香一区二区| 懂色av中文一区二区三区 | 91精品办公室少妇高潮对白| 欧美视频精品在线| 日韩欧美激情一区| 欧美国产日韩一二三区| 亚洲美女屁股眼交3| 视频在线观看国产精品| 国产福利一区二区三区| 色吧成人激情小说| 日韩精品一区二区三区蜜臀| 国产亚洲va综合人人澡精品| 一区二区三区在线观看网站| 奇米色一区二区| 懂色av一区二区在线播放| 欧美日韩在线免费视频| 久久视频一区二区| 亚洲一区二区av电影| 国产自产v一区二区三区c| 色综合久久久久久久久| 欧美大胆人体bbbb| 亚洲伦理在线免费看| 国产在线乱码一区二区三区| 97成人超碰视| 精品国产青草久久久久福利| 亚洲美女电影在线| 国产一区二区精品久久| 欧美视频你懂的| 国产精品亲子伦对白| 美腿丝袜亚洲色图| 日本电影亚洲天堂一区| 337p日本欧洲亚洲大胆色噜噜| 亚洲精品ww久久久久久p站| 韩国毛片一区二区三区| 欧美日韩中文精品| 国产精品久久久久影视| 麻豆精品国产传媒mv男同| 在线观看免费成人| 国产精品对白交换视频| 久久精品国产在热久久| 欧美三级电影一区| 亚洲日本一区二区| 国产精品18久久久久久久久 | 日本女优在线视频一区二区| 成人av动漫网站| 精品福利在线导航| 五月天中文字幕一区二区| 色综合天天做天天爱| 国产色婷婷亚洲99精品小说| 美女视频免费一区| 91麻豆精品国产91久久久使用方法 | 欧美色大人视频| 亚洲人午夜精品天堂一二香蕉| 国产成人精品1024| 久久老女人爱爱| 另类人妖一区二区av| 欧美夫妻性生活| 日韩精品一级二级| 欧美福利视频一区| 天堂久久久久va久久久久| 欧美日韩在线免费视频| 亚洲综合色自拍一区| 91极品美女在线| 一区二区视频在线| 91毛片在线观看| 最新欧美精品一区二区三区| 成人免费视频免费观看| 中日韩免费视频中文字幕| 国产一区二区三区四区五区美女 | 亚洲综合在线五月| 色偷偷久久人人79超碰人人澡| 国产精品久久久久久户外露出| 国产91丝袜在线播放0| 久久嫩草精品久久久久| 国产二区国产一区在线观看| 久久女同互慰一区二区三区| 国产成人午夜视频| 亚洲国产精品av| 99这里只有精品| 亚洲三级在线观看| 欧美日韩在线不卡| 日本不卡视频一二三区| 欧美大黄免费观看| 国产91精品在线观看| 亚洲摸摸操操av| 精品视频1区2区| 蜜桃一区二区三区在线| 久久久久久久久久美女| 成人av在线资源网| 亚洲综合自拍偷拍| 日韩欧美卡一卡二| 成人性生交大片免费| 亚洲最色的网站| 日韩一区二区麻豆国产| 国产黑丝在线一区二区三区| 国产欧美一区二区三区在线看蜜臀| www.亚洲人| 亚洲第一激情av| 26uuu精品一区二区在线观看| 国产91精品露脸国语对白| 亚洲嫩草精品久久| 日韩午夜小视频| 成人免费视频网站在线观看| 一区二区在线观看视频在线观看| 51精品视频一区二区三区| 国产麻豆欧美日韩一区| 丁香亚洲综合激情啪啪综合| 亚洲精品成a人| 欧美岛国在线观看| 91麻豆免费在线观看| 日本中文字幕一区二区有限公司| 欧美激情在线一区二区| 精品视频在线视频| 丁香天五香天堂综合| 亚洲不卡一区二区三区| 久久婷婷国产综合精品青草| 91福利在线观看| 狠狠色2019综合网| 一区二区三区在线视频播放| 欧美精品一区二区久久久| 91亚洲国产成人精品一区二三| 日韩成人一级片| 亚洲欧洲精品一区二区三区 | 日韩精品自拍偷拍| 一本一本大道香蕉久在线精品| 日本美女视频一区二区| 亚洲日本va在线观看| 日韩视频在线你懂得| 91国偷自产一区二区三区成为亚洲经典 | 亚洲在线一区二区三区| 久久综合九色综合97_久久久 | 欧美酷刑日本凌虐凌虐| 成人视屏免费看| 日韩专区欧美专区| 一级日本不卡的影视| 国产亲近乱来精品视频| 欧美videos中文字幕|