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

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

?? interpreterpattern.htm

?? 程式設計是思維具體化的一種方式
?? 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>

對于一個具有層次節點關系的問題來說,如果您要剖析每一個節點,您可以使用Interpreter模式,直譯器模式有些類似演算法中的個別擊破方式,對每一個父節點我們剖析出其子節點組合,然而交給子節點剖析物件繼續剖析,直到剖析至終端節點為止。<br>
<br>
舉個例子來說明好了,先說明的是,這個例子是改寫自 <a href="http://www.drmaster.com.tw/info.asp?NO=PG20214">Design Patterns于Java語言之實習應用</a> 第23章的范例,我將之更簡化了,以讓大家將焦點能集中在如何使用Interpreter模式,以及如何實用。<br>
<br>
假設您要實作一個Interpreter,這個Interpreter可以直譯您文字檔中的程式,并依您自訂的程式文法來執行程式,幾個簡單的程式如下:<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>
這個程式中的幾個關鍵字是PROGRAM、PRINT、SPACE、BREAK、LINEBREAK、REPEAT、END,
PROGRAM是表示程式開始,以END作結,PRINT可以印出一個無空白的字串,SPACE印出一個空白,BREAK是換行,而LINEBREAK是
畫一個直線并換行,REPEAT是回圈指令,可以指定回圈次數,以END作結。<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節點由primitive或repeat兩個節點任意組
合,一個command list節點則是零個以上的command節點組合而成,其中repeat還可以組合command
list節點,這是組合模式的應用,可以在程式中組合巢狀回圈。<br>
<br>
在直譯程式時,以讀到PROGRAM作為開始節點,接下來我們剖析程式為command list 節點,并將它們丟給專門剖析command
list的物件繼續剖析,這個物件將之分析,看是不是有repeat command或primitive
command節點,如果有就再往下交由專屬物件進行剖析,如此層層剝開,并由專屬物件負責剖析工作。<br>
<br>
Interpreter模式的基本觀念就如上所示,先來看看如何以程式實現剖析的過程,下面這個程式會剖析您的程式,并將程式加上對應的括號來將同一個區塊組合起來,以表示它完成剖析之后的結果:<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>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区激情在线| 午夜精品在线视频一区| 久久99精品网久久| 1区2区3区国产精品| 色哟哟欧美精品| 亚洲成人综合在线| 26uuu亚洲婷婷狠狠天堂| 国产91高潮流白浆在线麻豆| 中文字幕一区二区三区不卡 | 精品乱人伦一区二区三区| 青青草国产成人av片免费| 国产欧美久久久精品影院| 欧美性猛交xxxxxxxx| 国内久久婷婷综合| 亚洲欧洲色图综合| 欧美一级日韩不卡播放免费| av电影天堂一区二区在线观看| 国产精品久久久久久久裸模| 亚洲精品国产一区二区三区四区在线| 国产精品天干天干在观线| 国产成人啪午夜精品网站男同| 亚洲男人天堂一区| 国产日韩亚洲欧美综合| 欧美一区二区久久久| av午夜一区麻豆| 国内精品伊人久久久久影院对白| 一区二区在线观看免费| 中文字幕日本不卡| 日本一区二区久久| 国产精品理论片| 国产精品久久久一区麻豆最新章节| 精品久久久久久综合日本欧美| 在线播放欧美女士性生活| 欧美日韩日本视频| 日韩视频中午一区| 中文字幕在线不卡国产视频| 久久成人羞羞网站| 蜜桃视频第一区免费观看| 激情久久五月天| av电影在线观看完整版一区二区| 99国产一区二区三精品乱码| 在线观看不卡一区| 欧美大黄免费观看| 亚洲国产精品激情在线观看| 最新中文字幕一区二区三区| 亚洲午夜一二三区视频| 精品在线视频一区| 91一区二区在线| 日韩欧美成人激情| 国产精品乱码一区二区三区软件| 亚洲欧美成aⅴ人在线观看| 亚洲午夜免费福利视频| 国产精品亚洲人在线观看| 色偷偷一区二区三区| 久久综合久久鬼色中文字| 亚洲精品精品亚洲| 国产91丝袜在线18| 精品国产乱码久久久久久蜜臀| 亚洲精品高清在线| 国产 日韩 欧美大片| 777亚洲妇女| 欧美私模裸体表演在线观看| 日韩欧美三级在线| 午夜电影一区二区三区| 91影院在线观看| 亚洲国产精品一区二区www在线| 国产不卡视频在线播放| 欧美影视一区二区三区| 亚洲另类一区二区| 成人精品电影在线观看| 国产欧美日韩在线看| 国产综合一区二区| 欧美一级片免费看| 久久99精品国产| 久久婷婷综合激情| 国产成人精品亚洲777人妖| 久久久久久久一区| 成人不卡免费av| 最近日韩中文字幕| 欧美视频完全免费看| 日韩av在线发布| 精品福利在线导航| 成人动漫精品一区二区| 亚洲一区二区三区自拍| 日韩一级高清毛片| 国产乱人伦偷精品视频免下载| 欧美韩国日本一区| 加勒比av一区二区| 日本一区二区高清| 在线观看免费成人| 国产一区亚洲一区| 亚洲黄一区二区三区| 日韩精品一区二区三区视频在线观看 | 蜜臀av一区二区| 欧美一级夜夜爽| 色综合久久中文字幕综合网| 丝袜美腿高跟呻吟高潮一区| 精品卡一卡二卡三卡四在线| 不卡的电影网站| 青青草原综合久久大伊人精品 | 免费看日韩精品| 亚洲手机成人高清视频| 欧美精品一区二区三| 7878成人国产在线观看| 91高清在线观看| 97久久超碰国产精品电影| 国产精品99久久久久久似苏梦涵| 欧美三级蜜桃2在线观看| 成人中文字幕电影| 国产一区二区三区综合| 美女一区二区视频| 免费看欧美美女黄的网站| 亚洲在线中文字幕| 国产精品九色蝌蚪自拍| 日本一区二区三区视频视频| 久久蜜桃一区二区| 久久久久久久久久电影| 精品国产91亚洲一区二区三区婷婷| 欧美日韩国产乱码电影| 欧美午夜精品一区二区三区| 在线观看91视频| 欧美日韩一级片网站| 欧美一区二区三区视频免费| 欧美日韩国产高清一区| 欧美成人一区二区三区片免费| 日韩视频免费观看高清完整版在线观看 | 欧美三级资源在线| 一区二区三区四区高清精品免费观看| 国产校园另类小说区| 中文成人av在线| 亚洲影视资源网| 狠狠色丁香久久婷婷综合丁香| 高清不卡一区二区| 欧美日韩一级大片网址| 日韩一区二区三区在线| 国产精品网站在线观看| 午夜一区二区三区视频| 免费看日韩精品| www.亚洲国产| 高清av一区二区| 欧美午夜精品久久久久久超碰| 日韩亚洲欧美一区| 中文字幕在线一区二区三区| 亚洲国产精品久久久久秋霞影院| 中文字幕一区在线观看| 久久国产精品第一页| 91麻豆swag| 久久久国产一区二区三区四区小说| 亚洲一区二区在线观看视频| 国产专区欧美精品| 欧美日本国产视频| 无码av免费一区二区三区试看 | 美女一区二区在线观看| 欧美色男人天堂| 亚洲欧美激情在线| 风间由美中文字幕在线看视频国产欧美| 亚洲图片欧美视频| 欧美性猛交一区二区三区精品| 国产91高潮流白浆在线麻豆| 久久在线免费观看| 蜜臀99久久精品久久久久久软件| 972aa.com艺术欧美| 日韩欧美国产一区二区三区| 免费的国产精品| 日韩欧美成人激情| 亚洲午夜免费福利视频| 91亚洲精品一区二区乱码| 国产精品不卡在线观看| 粉嫩aⅴ一区二区三区四区五区| 久久久久久久久久久黄色| 韩国精品免费视频| 中文天堂在线一区| 91国偷自产一区二区三区成为亚洲经典 | 99精品视频在线播放观看| 国产精品久久久久aaaa樱花| heyzo一本久久综合| 午夜视频一区二区三区| 91精品中文字幕一区二区三区| 亚洲男人的天堂av| 精品奇米国产一区二区三区| 蜜桃av一区二区三区| 精品国产乱码久久久久久闺蜜| 久久99最新地址| 亚洲综合色成人| 日韩一区二区三区在线| 欧美又粗又大又爽| 亚洲国产精品一区二区久久| 久久久久久99精品| www.亚洲色图| 国产99久久久国产精品免费看| 免费日韩伦理电影| 亚洲成国产人片在线观看| 国产精品毛片a∨一区二区三区| 精品免费99久久| 欧美电影一区二区三区| 在线观看亚洲精品视频| 99精品欧美一区二区蜜桃免费| 激情久久五月天| 日韩专区一卡二卡| 天堂久久久久va久久久久|