亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
精品卡一卡二卡三卡四在线| 另类欧美日韩国产在线| 蜜臀久久99精品久久久久久9| 高清免费成人av| 91精品国产综合久久精品性色| 国产精品入口麻豆九色| 麻豆精品在线看| 欧美综合一区二区| 国产精品久久久久一区二区三区共| 日韩中文欧美在线| 在线视频观看一区| 最新国产精品久久精品| 国内精品国产三级国产a久久| 欧美精品777| 亚洲午夜激情网站| 色综合久久中文综合久久97| 中文字幕精品一区二区精品绿巨人| 亚洲综合精品久久| av在线播放成人| 国产精品视频一二三区| 国产成人亚洲综合a∨婷婷图片| 日韩一级黄色大片| 日韩不卡一区二区| 91精品国产综合久久精品麻豆| 亚欧色一区w666天堂| 欧美影院精品一区| 一区二区三区**美女毛片| 色综合中文综合网| 欧美videos中文字幕| 久久国产免费看| 欧美大尺度电影在线| 蜜桃视频一区二区| 精品少妇一区二区三区在线播放| 美女国产一区二区三区| 精品国产91亚洲一区二区三区婷婷| 免费高清在线视频一区·| 日韩精品影音先锋| 免费成人在线视频观看| 欧美一区二区黄色| 久久99深爱久久99精品| 久久婷婷久久一区二区三区| 国产乱人伦偷精品视频不卡| 欧美激情在线观看视频免费| 成人深夜在线观看| 亚洲欧美日韩久久| 精品视频在线视频| 免费成人美女在线观看.| 欧美成人精品二区三区99精品| 国产尤物一区二区在线| 国产精品国产馆在线真实露脸 | 成人免费小视频| 色综合天天综合网国产成人综合天| 伊人夜夜躁av伊人久久| 欧美疯狂性受xxxxx喷水图片| 美女mm1313爽爽久久久蜜臀| 国产日韩欧美不卡在线| 色综合久久久久久久久| 日韩福利视频网| 亚洲国产精品精华液2区45| 91小视频免费看| 日韩精品乱码av一区二区| 久久综合五月天婷婷伊人| 成人国产精品免费观看动漫| 亚洲小说欧美激情另类| 精品福利一二区| 一本久久综合亚洲鲁鲁五月天| 婷婷丁香久久五月婷婷| 国产欧美日韩在线| 51午夜精品国产| 99视频国产精品| 美女诱惑一区二区| 成人免费在线视频观看| 精品日韩一区二区三区免费视频| 99国产精品久久久久| 久久精品国产99| 一区二区三国产精华液| 久久精品人人做人人爽97| 在线看国产一区二区| 国产成人精品三级| 午夜久久久影院| 中文字幕在线不卡一区二区三区| 这里只有精品电影| 91蝌蚪porny| 国产伦精品一区二区三区免费迷| 亚洲一区二区三区四区在线观看 | 在线区一区二视频| 成人一区在线观看| 麻豆一区二区三区| 亚洲一区欧美一区| 最新国产成人在线观看| 国产人妖乱国产精品人妖| 日韩亚洲欧美成人一区| 欧美亚洲丝袜传媒另类| www.成人在线| 成人免费观看视频| 国产在线播放一区二区三区| 五月开心婷婷久久| 一区二区在线看| 国产精品成人免费| 国产清纯白嫩初高生在线观看91 | 色狠狠综合天天综合综合| 懂色av一区二区在线播放| 精品午夜一区二区三区在线观看| 图片区小说区区亚洲影院| 亚洲一区二区视频| 亚洲精品成人少妇| 自拍视频在线观看一区二区| 国产精品婷婷午夜在线观看| 久久久美女艺术照精彩视频福利播放 | 精品美女一区二区| 日韩视频在线观看一区二区| 欧美欧美欧美欧美| 欧美久久高跟鞋激| 制服丝袜中文字幕一区| 正在播放亚洲一区| 精品国产乱码久久久久久闺蜜 | 国产一区二区三区免费| 国内精品免费**视频| 国产精品2024| 国产不卡视频在线观看| 国产69精品久久99不卡| 99热精品国产| 一本大道综合伊人精品热热 | 亚洲久草在线视频| 亚洲人xxxx| 亚洲国产aⅴ成人精品无吗| 亚洲国产日韩一区二区| 日韩高清不卡在线| 国产精品资源在线看| 成人妖精视频yjsp地址| 成人久久18免费网站麻豆| 99久久精品一区| 精品婷婷伊人一区三区三| 日韩欧美国产午夜精品| 久久精品无码一区二区三区| 国产精品超碰97尤物18| 五月激情综合网| 国产一区亚洲一区| 91美女在线观看| 日韩欧美国产精品| 中文字幕高清不卡| 亚瑟在线精品视频| 国产精一区二区三区| 色综合久久中文综合久久97| 91麻豆精品国产91久久久久久 | 久久久久久久久蜜桃| 亚洲视频 欧洲视频| 日韩vs国产vs欧美| 成人av网站在线观看| 欧美色图一区二区三区| 精品国产乱码久久久久久夜甘婷婷| 中文字幕在线观看一区| 日本美女一区二区| 91在线一区二区| 欧美不卡一区二区三区| 亚洲精品久久久蜜桃| 精品一区二区av| 欧美三级韩国三级日本一级| 久久久av毛片精品| 性感美女久久精品| 成人的网站免费观看| 欧美一区二区免费视频| 日韩一区在线看| 国产一区不卡在线| 欧美色网一区二区| 亚洲三级在线观看| 国产精品888| 日韩亚洲国产中文字幕欧美| 亚洲精品欧美激情| 国产精品 欧美精品| 日韩女优电影在线观看| 亚洲小少妇裸体bbw| av不卡在线播放| 久久久另类综合| 久久国产尿小便嘘嘘| 欧美日韩精品一区二区在线播放| 亚洲私人黄色宅男| 国产精品一级在线| 欧美一区二区三区免费| 亚洲一区二区在线免费观看视频| av激情综合网| 国产精品视频在线看| 国产福利电影一区二区三区| 日韩写真欧美这视频| 日韩精品三区四区| 欧美精品久久天天躁| 亚洲aⅴ怡春院| 欧美日韩一区三区| 午夜精品久久久久久久久久| 色哟哟一区二区| 亚洲女与黑人做爰| 99久久er热在这里只有精品15 | 国产精品黄色在线观看| 国内精品免费**视频| 久久伊99综合婷婷久久伊| 精品午夜一区二区三区在线观看| 亚洲精品在线免费观看视频| 精品一区二区国语对白| 久久新电视剧免费观看| 国产精品影视在线|