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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? interpreterpattern.htm

?? 程式設(shè)計是思維具體化的一種方式
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>





  
  
  
  
  
  <link rel="stylesheet" href="css/stdlayout.css" type="text/css">





  
  
  
  
  
  <link rel="stylesheet" href="css/print.css" type="text/css">





  
  
  
  
  
  <meta content="text/html; charset=gb2312" http-equiv="content-type">





  
  
  
  
  
  <title>Interpreter 模式</title>
</head>


<body>





<h3><a href="http://caterpillar.onlyfun.net/GossipCN/index.html">From
Gossip@caterpillar</a></h3>





<h1><a href="CppGossip.html">Design Pattern:&nbsp;Interpreter 模式</a></h1>

對于一個具有層次節(jié)點關(guān)系的問題來說,如果您要剖析每一個節(jié)點,您可以使用Interpreter模式,直譯器模式有些類似演算法中的個別擊破方式,對每一個父節(jié)點我們剖析出其子節(jié)點組合,然而交給子節(jié)點剖析物件繼續(xù)剖析,直到剖析至終端節(jié)點為止。<br>
<br>
舉個例子來說明好了,先說明的是,這個例子是改寫自 <a href="http://www.drmaster.com.tw/info.asp?NO=PG20214">Design Patterns于Java語言之實習(xí)應(yīng)用</a> 第23章的范例,我將之更簡化了,以讓大家將焦點能集中在如何使用Interpreter模式,以及如何實用。<br>
<br>
假設(shè)您要實作一個Interpreter,這個Interpreter可以直譯您文字檔中的程式,并依您自訂的程式文法來執(zhí)行程式,幾個簡單的程式如下:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">PROGRAM </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; PRINT dog SPACE </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; PRINT is SPACE </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; PRINT an SPACE </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; PRINT animai </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">END </span><br>
</div>
&nbsp;<br>
您的這式程個會印出"dog is an animal"的文字,再來一個例子是:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">PROGRAM </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; REPEAT 2 </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LINEBREAK </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRINT dog </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BREAK </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; END </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">END</span><br>
</div>
&nbsp;<br>
<br>
這個程式要印出:<br>
<table style="text-align: left; background-color: rgb(0, 0, 0); width: 963px; height: 32px; font-family: Times New Roman,Times,serif; color: rgb(255, 255, 255);" border="0" cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
      <td><small>------------------------------ <br style="font-weight: bold;">
&nbsp;dog <br style="font-weight: bold;">
------------------------------ <br style="font-weight: bold;">
&nbsp;dog</small></td>
    </tr>
  </tbody>
</table>
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;"></span><span style="font-weight: bold; font-family: Courier New,Courier,monospace;"></span><br>
您也可以任意的組合程式,例如:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">PROGRAM </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; PRINT begin </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; BREAK </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; REPEAT 3 </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; REPEAT 2 </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRINT dog SPACE </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRINT is SPACE </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRINT a SPACE </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRINT animal </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BREAK </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; END </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">END</span><br>
</div>
&nbsp;<br>
<br>
這個程式中的幾個關(guān)鍵字是PROGRAM、PRINT、SPACE、BREAK、LINEBREAK、REPEAT、END,
PROGRAM是表示程式開始,以END作結(jié),PRINT可以印出一個無空白的字串,SPACE印出一個空白,BREAK是換行,而LINEBREAK是
畫一個直線并換行,REPEAT是回圈指令,可以指定回圈次數(shù),以END作結(jié)。<br>
<br>
觀察程式,可以制定出以下的文法,如下:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&lt;program&gt; ::= PROGRAM &lt;command list&gt; </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&lt;command list&gt; ::= &lt;command&gt;* END </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&lt;command&gt; ::= &lt;repeat command&gt; | &lt;primitive command&gt; </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&lt;repeat command&gt; ::= REPEAT &lt;number&gt; &lt;command list&gt; </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&lt;primitive command&gt; ::= PRINT &lt;string&gt; </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
| BREAK | SPACE | LINEBREAK</span><br>
</div>
&nbsp;<br>
<br>
程式文法制定需要對程式進行語句分析與定義,在這邊并不討論這個課題,在程式中,command節(jié)點由primitive或repeat兩個節(jié)點任意組
合,一個command list節(jié)點則是零個以上的command節(jié)點組合而成,其中repeat還可以組合command
list節(jié)點,這是組合模式的應(yīng)用,可以在程式中組合巢狀回圈。<br>
<br>
在直譯程式時,以讀到PROGRAM作為開始節(jié)點,接下來我們剖析程式為command list 節(jié)點,并將它們丟給專門剖析command
list的物件繼續(xù)剖析,這個物件將之分析,看是不是有repeat command或primitive
command節(jié)點,如果有就再往下交由專屬物件進行剖析,如此層層剝開,并由專屬物件負責(zé)剖析工作。<br>
<br>
Interpreter模式的基本觀念就如上所示,先來看看如何以程式實現(xiàn)剖析的過程,下面這個程式會剖析您的程式,并將程式加上對應(yīng)的括號來將同一個區(qū)塊組合起來,以表示它完成剖析之后的結(jié)果:<br>
<ul>
  <li> INode.java
  </li>
</ul>

<pre>public interface INode { <br>    public void parse(Context context); <br>} <br></pre>

<br>

<ul>
  <li> ProgramNode.java
  </li>
</ul>

<pre>// &lt;program&gt; ::= PROGRAM &lt;command list&gt; <br>public class ProgramNode implements INode { <br>    private INode commandListNode; <br>    public void parse(Context context) { <br>        context.skipToken("PROGRAM"); <br>        commandListNode = new CommandListNode(); <br>        commandListNode.parse(context); <br>    } <br><br>    public String toString() { <br>        return "[PROGRAM " + commandListNode + "]"; <br>    } <br>}  <br></pre>

<br>

<ul>
  <li> CommandListNode.java
  </li>
</ul>

<pre>import java.util.Vector; <br><br>// &lt;command list&gt; ::= &lt;command&gt;* END <br>public class CommandListNode implements INode { <br>    private Vector list = new Vector();<br><br>    public void parse(Context context) { <br>        while (true) { <br>            if (context.currentToken() == null) { <br>                System.err.println("Missing 'END'"); <br>                 break; <br>            } else if (<br>                    context.currentToken().equals("END")) { <br>                context.skipToken("END"); <br>                break; <br>            } else { <br>                INode commandNode = new CommandNode(); <br>                commandNode.parse(context); <br>                list.add(commandNode); <br>            } <br>        } <br>    }<br><br>    public String toString() { <br>        return "" + list; <br>    } <br>}  <br></pre>

<br>

<ul>
  <li> CommandNode.java
  </li>
</ul>

<pre>// &lt;command&gt; ::= &lt;repeat command&gt; | &lt;primitive command&gt; <br>public class CommandNode implements INode { <br>    private INode node;<br><br>    public void parse(Context context) { <br>        if (context.currentToken().equals("REPEAT")) { <br>            node = new RepeatCommandNode(); <br>            node.parse(context); <br>        } else { <br>            node = new PrimitiveCommandNode(); <br>            node.parse(context); <br>        } <br>    }<br><br>    public String toString() { <br>        return node.toString(); <br>    } <br>}  <br></pre>

<br>

<ul>
  <li> RepeatCommandNode.java
  </li>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人综合婷婷国产精品久久 | 午夜精品福利在线| jlzzjlzz亚洲女人18| 中文字幕乱码亚洲精品一区 | 国产精品美女久久久久久久久| 国内精品国产成人国产三级粉色| 日韩精品中文字幕在线不卡尤物| 国产综合色视频| 国产精品乱子久久久久| 97久久精品人人澡人人爽| 一区二区三区四区激情| 91精品国产色综合久久ai换脸 | 欧美激情在线看| 色系网站成人免费| 性欧美大战久久久久久久久| 日韩视频一区二区三区| 国产精品1区2区3区在线观看| 久久久久亚洲蜜桃| 色999日韩国产欧美一区二区| 亚洲成人先锋电影| 久久理论电影网| 99re成人精品视频| 亚洲777理论| 久久久久久免费| 91搞黄在线观看| 经典三级在线一区| 亚洲欧洲韩国日本视频| 欧美二区在线观看| 国产aⅴ综合色| 五月综合激情日本mⅴ| 欧美精品一区二区在线播放| av中文一区二区三区| 亚洲va欧美va人人爽| 久久久久成人黄色影片| 欧美日韩小视频| 成人免费电影视频| 日韩高清国产一区在线| 亚洲国产精品国自产拍av| 欧美高清性hdvideosex| 福利一区在线观看| 日韩成人伦理电影在线观看| 国产精品麻豆欧美日韩ww| 日韩一区二区中文字幕| 99久久er热在这里只有精品15| 免费一区二区视频| 亚洲激情五月婷婷| 国产日本欧洲亚洲| 欧美一区二区观看视频| 在线免费亚洲电影| 国产精品一区二区男女羞羞无遮挡| 亚洲一区二区精品久久av| 国产欧美在线观看一区| 666欧美在线视频| 91麻豆精东视频| 丁香激情综合五月| 精品一区二区日韩| 午夜精品福利久久久| 亚洲精品亚洲人成人网| 国产精品无圣光一区二区| 久久免费的精品国产v∧| 在线成人小视频| 欧美性xxxxxx少妇| 91影院在线免费观看| 粉嫩一区二区三区在线看| 国产精品主播直播| 国产在线精品一区二区| 毛片av一区二区| 青青青伊人色综合久久| 天堂在线一区二区| 亚洲电影在线免费观看| 一区二区三区小说| 一级精品视频在线观看宜春院| 国产精品成人午夜| 国产精品国产三级国产| 欧美激情一区二区三区蜜桃视频| 久久久久久久免费视频了| 精品美女一区二区三区| 欧美变态口味重另类| 日韩欧美自拍偷拍| 欧美zozozo| 久久亚洲捆绑美女| 日本一区二区三区在线观看| 国产亚洲精久久久久久| 久久夜色精品一区| 中文在线资源观看网站视频免费不卡| 久久日韩精品一区二区五区| 久久精品欧美一区二区三区麻豆| 精品美女被调教视频大全网站| 精品国产乱子伦一区| 精品久久久三级丝袜| 欧美国产一区二区在线观看| 国产精品你懂的在线欣赏| 亚洲欧美日韩一区二区 | 亚洲午夜三级在线| 亚洲成人一区二区| 男女性色大片免费观看一区二区| 男人的天堂亚洲一区| 国产成人在线免费| 91麻豆swag| 制服.丝袜.亚洲.另类.中文| 精品日韩在线观看| 亚洲欧洲成人自拍| 视频一区在线播放| 久久av老司机精品网站导航| 大胆亚洲人体视频| 欧美婷婷六月丁香综合色| 8x8x8国产精品| 久久久久久久av麻豆果冻| 亚洲情趣在线观看| 蜜臀va亚洲va欧美va天堂| 国产福利一区在线| 欧美色图在线观看| 久久综合久久99| 一区二区三区在线免费视频| 蜜桃一区二区三区在线观看| 夫妻av一区二区| 欧美精品乱码久久久久久按摩| 久久影视一区二区| 夜夜爽夜夜爽精品视频| 激情综合色播五月| 色播五月激情综合网| 久久先锋影音av鲁色资源网| 中文字幕综合网| 奇米影视一区二区三区| 色婷婷av一区二区三区之一色屋| 日韩写真欧美这视频| 亚洲人123区| 国产精品白丝av| 欧美日韩成人综合天天影院| 国产精品亲子伦对白| 青青草原综合久久大伊人精品 | 国内成人精品2018免费看| 色综合中文字幕| 国产日韩欧美一区二区三区乱码| 亚洲国产视频网站| 成人白浆超碰人人人人| 欧美一级欧美三级| 亚洲一区二区偷拍精品| 国产suv一区二区三区88区| 欧美日韩亚州综合| 亚洲黄色性网站| 国产成人综合精品三级| 日韩欧美一级二级三级| 亚洲一区免费视频| 成人黄色电影在线 | 成人av在线影院| 欧美tk—视频vk| 日韩av不卡在线观看| 91视频在线观看| 国产精品久久久久影院色老大| 久久精品噜噜噜成人av农村| 欧美日韩一区在线观看| 成人免费一区二区三区视频 | 亚洲一区二区在线观看视频| 成人a级免费电影| 久久久久久久久岛国免费| 日韩专区一卡二卡| 欧美色视频一区| 亚洲一区二区成人在线观看| 99精品视频一区| 中文字幕在线观看不卡| 国产夫妻精品视频| 久久先锋影音av鲁色资源网| 久久99在线观看| 日韩亚洲国产中文字幕欧美| 奇米一区二区三区av| 日韩欧美一区电影| 麻豆一区二区在线| 欧美一级日韩免费不卡| 日韩av中文字幕一区二区三区| 欧美精品三级在线观看| 午夜国产精品一区| 日韩一级大片在线观看| 久热成人在线视频| 久久老女人爱爱| 成人免费视频一区| 亚洲欧洲美洲综合色网| 色综合久久天天| 亚洲国产精品嫩草影院| 欧美日韩国产首页| 奇米影视一区二区三区小说| 久久夜色精品国产噜噜av| 成人爽a毛片一区二区免费| 亚洲卡通欧美制服中文| 欧美图片一区二区三区| 日韩制服丝袜av| www精品美女久久久tv| 成人午夜av影视| 亚洲一区免费视频| 日韩色视频在线观看| 国产一区欧美一区| 国产精品五月天| 欧美视频第二页| 久久综合综合久久综合| 国产精品免费aⅴ片在线观看| 91黄色免费版| 美女在线视频一区| 亚洲人成网站精品片在线观看| 欧美日韩国产123区| 激情小说亚洲一区|