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

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

?? tutor10.doc

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



























                            LET'S BUILD A COMPILER!

                                       By

                            Jack W. Crenshaw, Ph.D.

                                  21 May 1989


                           Part X: INTRODUCING "TINY"





























PA2A





       *****************************************************************
       *                                                               *
       *                        COPYRIGHT NOTICE                       *
       *                                                               *
       *   Copyright (C) 1989 Jack W. Crenshaw. All rights reserved.   *
       *                                                               *
       *****************************************************************


       INTRODUCTION

       In the last installment, I showed you the general  idea  for  the
       top-down development of  a  compiler.    I gave you the first few
       steps  of  the process for compilers for  Pascal  and  C,  but  I
       stopped  far  short  of  pushing  it through to completion.   The
       reason was simple: if we're going to produce  a  real, functional
       compiler  for  any  language, I'd rather  do  it  for  KISS,  the
       language that I've been defining in this tutorial series.

       In this installment, we're going to do just that, for a subset of
       KISS which I've chosen to call TINY.

       The process  will be essentially that outlined in Installment IX,
       except  for  one  notable  difference.   In that  installment,  I
       suggested  that  you  begin  with  a full BNF description of  the
       language.  That's fine for something like Pascal or C,  for which
       the language definition is  firm.   In the case of TINY, however,
       we don't yet have a full  description  ... we seem to be defining
       the language as we go.  That's OK.    In  fact,  it's preferable,
       since we can tailor the language  slightly  as we go, to keep the
       parsing easy.

       So in the development  that  follows,  we'll  actually be doing a
       top-down development of BOTH the  language and its compiler.  The
       BNF description will grow along with the compiler.

       In this process, there will be a number of decisions to  be made,
       each of which will influence the BNF and therefore the  nature of
       the language.   At  each  decision  point I'll try to remember to
       explain  the  decision  and the rationale behind my choice.  That
       way, if you happen to hold a different opinion and would prefer a
       different option, you can choose it instead.  You  now  have  the
       background  to  do  that.  I guess the important thing to note is
       that  nothing  we  do  here  is  cast  in  concrete.  When YOU'RE
       designing YOUR language, you should feel free to do it YOUR way.

       Many of you may be asking at this point: Why bother starting over
       from  scratch?  We had a working subset of KISS as the outcome of
       Installment  VII  (lexical  scanning).  Why not just extend it as
       needed?  The  answer  is  threefold.    First of all, I have been
       making  a  number  of changes to further simplify the program ...
       changes  like  encapsulating  the  code generation procedures, so
       that  we  can  convert to a different target machine more easily.
       Second, I want you to see how the development can indeed  be doneA*2A*
                                     - 2 -

PA2A





       from the top down as outlined in the last installment.   Finally,
       we both need the practice.  Each time I go through this exercise,
       I get a little better at it, and you will, also.


       GETTING STARTED

       Many  years  ago  there were languages called  Tiny  BASIC,  Tiny
       Pascal, and Tiny C, each of which was a subset of its parent full
       language.  Tiny BASIC,  for  example,  had  only single-character
       variable names and global variables.   It supported only a single
       data type.  Sound familiar?  At this point we have almost all the
       tools we need to build a compiler like that.

       Yet a language called Tiny-anything  still  carries  some baggage
       inherited from its parent language.   I've often wondered if this
       is a  good  idea.    Granted,  a  language based upon some parent
       language will have the  advantage  of  familiarity, but there may
       also  be  some  peculiar syntax carried over from the parent that
       may tend  to add unnecessary complexity to the compiler. (Nowhere
       is this more true than in Small C.)

       I've wondered just how small and simple a compiler could  be made
       and  still  be  useful, if it were designed from the outset to be
       both easy to use and to  parse.    Let's find out.  This language
       will just be called "TINY," period.  It's a subset of KISS, which
       I  also  haven't  fully  defined,  so  that  at  least  makes  us
       consistent (!).  I suppose you could call it TINY KISS.  But that
       opens  up a whole can of worms involving  cuter  and  cuter  (and
       perhaps more risque) names, so let's just stick with TINY.

       The main limitations  of  TINY  will  be because of the things we
       haven't yet covered, such as data types.  Like its cousins Tiny C
       and Tiny BASIC,  TINY  will  have  only one data type, the 16-bit
       integer.    The  first  version  we  develop  will also  have  no
       procedure  calls  and  will  use single-character variable names,
       although as you will see we can remove these restrictions without
       much effort.

       The language I have in mind will share some of the  good features
       of  Pascal,  C,  and Ada.  Taking a lesson from the comparison of
       the Pascal and  C  compilers in the previous installment, though,
       TINY will have a decided Pascal flavor.  Wherever  feasible,    a
       language structure will  be  bracketed by keywords or symbols, so
       that  the parser will know where it's  going  without  having  to
       guess.

       One other ground rule:  As we go, I'd like  to  keep the compiler
       producing real, executable code.  Even though it may not  DO much
       at the beginning, it will at least do it correctly.

       Finally,  I'll  use  a couple of Pascal  restrictions  that  make
       sense:  All data and procedures must be declared before  they are
       used.  That makes good sense,  even  though for now the only dataA*2A*
                                     - 3 -

PA2A





       type we'll use  is a word.  This rule in turn means that the only
       reasonable place to put the  executable code for the main program
       is at the end of the listing.

       The top-level definition will be similar to Pascal:


            <program> ::= PROGRAM <top-level decl> <main> '.'


       Already, we've reached a decision point.  My first thought was to
       make the main block optional.   It  doesn't seem to make sense to
       write a "program" with no main program, but it does make sense if
       we're  allowing  for  multiple modules, linked together.    As  a
       matter of fact,  I intend to allow for this in KISS.  But then we
       begin  to open up a can of worms that I'd rather leave closed for
       now.  For example, the  term "PROGRAM" really becomes a misnomer.
       The MODULE of Modula-2 or the Unit of Turbo Pascal would  be more
       appropriate.  Second,  what  about  scope  rules?    We'd  need a
       convention for  dealing  with  name  visibility  across  modules.
       Better  for  now  to  just  keep  it  simple  and ignore the idea
       altogether.

       There's also a decision in choosing to require  the  main program
       to  be  last.    I  toyed  with  the idea of making its  position
       optional,  as  in  C.  The nature of SK*DOS, the OS I'm compiling
       for, make this very easy to do.   But  this  doesn't  really make
       much sense in view of the Pascal-like requirement  that  all data
       and procedures  be declared before they're referenced.  Since the
       main  program can only call procedures  that  have  already  been
       declared, the only position that makes sense is at the end,  a la
       Pascal.

       Given  the  BNF  above, let's write a parser that just recognizes
       the brackets:


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

       procedure Prog;
       begin
          Match('p');
          Header;
          Prolog;
          Match('.');
          Epilog;
       end;
       {--------------------------------------------------------------}


       The procedure Header just emits  the startup code required by the
       assembler:A62A6
                                     - 4 -A*2A*

PA2A





       {--------------------------------------------------------------}
       { Write Header Info }

       procedure Header;
       begin
          WriteLn('WARMST', TAB, 'EQU $A01E');
       end;
       {--------------------------------------------------------------}


       The procedures Prolog and  Epilog  emit  the code for identifying
       the main program, and for returning to the OS:


       {--------------------------------------------------------------}
       { Write the Prolog }

       procedure Prolog;
       begin
          PostLabel('MAIN');
       end;


       {--------------------------------------------------------------}
       { Write the Epilog }

       procedure Epilog;
       begin
          EmitLn('DC WARMST');
          EmitLn('END MAIN');
       end;
       {--------------------------------------------------------------}


       The  main program just calls Prog, and then  looks  for  a  clean
       ending:


       {--------------------------------------------------------------}
       { Main Program }

       begin
          Init;
          Prog;
          if Look <> CR then Abort('Unexpected data after ''.''');
       end.
       {--------------------------------------------------------------}


       At this point, TINY  will  accept  only  one input "program," the
       null program:


            PROGRAM .   (or 'p.' in our shorthand.)A*2A*
                                     - 5 -

PA2A





       Note, though, that the  compiler  DOES  generate correct code for
       this program.  It will run, and do  what  you'd  expect  the null
       program to do, that is, nothing but return gracefully to the OS.

       As a matter of interest, one of my  favorite  compiler benchmarks
       is to compile, link,  and  execute  the  null program in whatever
       language   is   involved.     You  can  learn  a  lot  about  the
       implementation by measuring  the  overhead  in  time  required to
       compile what should be a trivial case.  It's also  interesting to
       measure the amount of code produced.  In many compilers, the code
       can be fairly large, because they always include  the  whole run-
       time  library whether they need it or not.    Early  versions  of
       Turbo Pascal produced a 12K object file for  this  case.    VAX C
       generates 50K!

       The  smallest  null  programs  I've  seen are those  produced  by
       Modula-2 compilers, and they run about 200-800 bytes.

       In the case of TINY, we HAVE no run-time library  as  yet, so the
       object code is indeed tiny:  two  bytes.    That's  got  to  be a
       record, and it's  likely  to  remain  one since it is the minimum
       size required by the OS.

       The  next step is to process the code for the main program.  I'll
       use the Pascal BEGIN-block:


            <main> ::= BEGIN <block> END


       Here,  again,  we  have made a decision.  We could have chosen to
       require a "PROCEDURE MAIN" sort of declaration, similar to C.   I
       must  admit  that  this  is  not  a bad idea at all ...  I  don't
       particularly  like  the  Pascal  approach  since I tend  to  have
       trouble locating the main  program  in a Pascal listing.  But the
       alternative is a little awkward, too, since you have to deal with
       the  error condition where the user omits  the  main  program  or
       misspells its name.  Here I'm taking the easy way out.

       Another solution to the "where is the main program" problem might
       be to require a name for  the  program, and then bracket the main
       by


            BEGIN <name>
            END <name>


       similar to the convention of  Modula  2.    This  adds  a  bit of
       "syntactic sugar" to the language.  Things like this are  easy to
       add or change to your liking, if the language is your own design.

       To parse this definition of a main block,  change  procedure Prog
       to read:A*2A*
                                     - 6 -

PA2A





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

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


       and add the new procedure:


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

       procedure Main;
       begin
          Match('b');
          Prolog;
          Match('e');
          Epilog;
       end;
       {--------------------------------------------------------------}


       Now, the only legal program is:


            PROGRAM BEGIN END . (or 'pbe.')


       Aren't we making progress???  Well, as usual it gets better.  You
       might try some deliberate errors here, like omitting  the  'b' or
       the 'e', and see what happens.  As always,  the  compiler  should
       flag all illegal inputs.


       DECLARATIONS

       The obvious next step is to decide what we mean by a declaration.
       My  intent  here  is to have two kinds of declarations: variables
       and  procedures/functions.    At  the  top  level,   only  global
       declarations are allowed, just as in C.

       For now, there  can  only be variable declarations, identified by
       the keyword VAR (abbreviated 'v'):


            <top-level decls> ::= ( <data declaration> )*A62A6
                                     - 7 -A*2A*

PA2A

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
制服丝袜在线91| 国产在线播放一区三区四| 91丨porny丨首页| 综合久久一区二区三区| 91在线高清观看| 亚洲高清在线精品| 欧美片网站yy| 欧美美女一区二区三区| 激情av综合网| 国产亚洲精品7777| 99精品视频一区二区三区| 夜夜嗨av一区二区三区四季av| 在线免费观看视频一区| 五月天丁香久久| 精品国产乱码久久久久久牛牛| 国产麻豆欧美日韩一区| 亚洲欧洲精品一区二区精品久久久| 日本高清成人免费播放| 日本女人一区二区三区| 久久久国产精品不卡| 色综合天天视频在线观看| 日本成人中文字幕| 国产精品少妇自拍| 狠狠色丁香久久婷婷综合_中| 国产精品日韩成人| 51久久夜色精品国产麻豆| 国产精品亚洲专一区二区三区| 亚洲色图丝袜美腿| 777午夜精品视频在线播放| 国产精品自拍av| 亚洲欧美aⅴ...| 欧美va日韩va| 日韩欧美电影一区| 狠狠狠色丁香婷婷综合激情| 国产精品不卡一区| 日韩一区二区三区四区五区六区| 国产91精品精华液一区二区三区| 一区二区三区视频在线看| 久久综合狠狠综合久久综合88| 欧美亚洲一区二区在线| 中文字幕一区二区在线观看| 日韩精品一区二区三区四区视频 | 国产女同互慰高潮91漫画| 91成人免费在线| 国产一区不卡精品| 精品国免费一区二区三区| 色激情天天射综合网| 国产精品伊人色| 日韩精品每日更新| 亚洲一区在线观看免费| 欧美国产成人在线| 精品国精品国产| 91精品在线一区二区| 国产精品网站在线| 成人综合婷婷国产精品久久蜜臀| 亚洲一二三四在线| 亚洲日本免费电影| 国产欧美精品一区| 国产日韩欧美在线一区| 欧美电影免费提供在线观看| 欧美日韩在线免费视频| 色综合天天视频在线观看| 成人av电影在线网| 国产一区二区三区蝌蚪| 久久成人久久爱| 青青草成人在线观看| 午夜激情综合网| 亚洲国产中文字幕在线视频综合| 中文字幕佐山爱一区二区免费| 国产欧美日韩在线观看| 精品毛片乱码1区2区3区| 蜜臀av性久久久久蜜臀aⅴ流畅| 亚洲午夜久久久久久久久久久| 亚洲色图另类专区| 亚洲欧美激情视频在线观看一区二区三区| 国产精品色哟哟| 国产精品久久久久久久久动漫| 国产欧美视频在线观看| 婷婷丁香久久五月婷婷| wwwwww.欧美系列| 久久综合九色综合97婷婷| 精品国产91亚洲一区二区三区婷婷| 日韩你懂的在线播放| 日韩视频在线观看一区二区| 日韩美女在线视频| 久久亚洲一区二区三区四区| 久久久久综合网| 国产午夜亚洲精品羞羞网站| 中文字幕va一区二区三区| 国产精品网友自拍| 亚洲伦在线观看| 午夜视频一区二区三区| 青青国产91久久久久久| 国产精品91xxx| a在线欧美一区| 欧美色爱综合网| 紧缚奴在线一区二区三区| 国产精品亚洲视频| 97久久久精品综合88久久| 91久久精品国产91性色tv| 欧美剧在线免费观看网站| 欧美成人vps| 国产精品福利电影一区二区三区四区| 亚洲图片你懂的| 99久久国产免费看| 国产一区二区免费看| 亚洲午夜精品一区二区三区他趣| 亚洲资源在线观看| 美女视频黄频大全不卡视频在线播放| 国产揄拍国内精品对白| 成人黄色a**站在线观看| 欧美性一二三区| 日韩午夜激情视频| 国产精品热久久久久夜色精品三区| 亚洲激情欧美激情| 精品在线观看视频| 国产91在线|亚洲| 欧美日韩国产高清一区二区三区 | 正在播放一区二区| 成人福利在线看| 91精品免费观看| 亚洲视频一二区| 蜜桃精品视频在线观看| 91美女在线观看| 日韩你懂的电影在线观看| 国产区在线观看成人精品| 五月激情六月综合| 成人av电影在线| ...av二区三区久久精品| 最新中文字幕一区二区三区| 日韩av一二三| 91免费看片在线观看| 久久久激情视频| 午夜欧美视频在线观看| 99久久精品免费| 久久亚洲精精品中文字幕早川悠里 | 亚洲国产中文字幕在线视频综合| 国产在线精品视频| 欧美日韩免费视频| 综合久久久久综合| 丁香桃色午夜亚洲一区二区三区| 久久99精品久久久| 精品视频一区二区三区免费| 国产午夜精品福利| 老司机精品视频导航| 欧美日韩精品一区视频| 亚洲日本丝袜连裤袜办公室| 国产大片一区二区| 精品欧美乱码久久久久久 | 亚洲国产精品麻豆| 日本高清成人免费播放| 中文字幕国产一区| 国内国产精品久久| 欧美成人a视频| 秋霞影院一区二区| 欧美精品久久久久久久多人混战 | 亚洲综合一二区| 91原创在线视频| 亚洲色图制服诱惑| 成人18视频在线播放| 国产欧美综合在线观看第十页| 久久精品国产99| 精品免费国产一区二区三区四区| 蜜桃视频第一区免费观看| 欧美一区二区精品在线| 日韩成人av影视| 日韩无一区二区| 看片的网站亚洲| 精品久久国产97色综合| 精品系列免费在线观看| 粉嫩av一区二区三区在线播放| 日本一区二区免费在线观看视频| 国产精品亚洲第一| 亚洲高清视频在线| 免费人成在线不卡| 日韩欧美一级二级三级| 六月丁香婷婷久久| 久久亚洲综合av| 99久久精品免费看| 一区二区在线观看免费视频播放| www久久久久| 日韩高清在线观看| 久久综合色综合88| 成人小视频免费在线观看| 亚洲视频一区二区免费在线观看| 在线观看中文字幕不卡| 日韩va亚洲va欧美va久久| www久久精品| 成人黄色大片在线观看| 亚洲一区欧美一区| 日韩一级片在线播放| 国产精品一区免费视频| 亚洲欧美aⅴ...| 欧美一区二区三区四区在线观看| 韩国理伦片一区二区三区在线播放| 欧美国产欧美综合| 在线免费观看视频一区| 精品一区二区三区免费播放| 国产精品久久精品日日| 欧美三区免费完整视频在线观看|