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

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

?? pat5c.htm

?? java設計范式.rar
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
<A NAME="auto1055"></A><LI><EM>Complex grammars are hard to maintain.</EM>The Interpreter pattern defines at least one class for every rulein the grammar (grammar rules defined using BNF may require multipleclasses).  Hence grammars containing many rules can be hard tomanage and maintain.  Other design patterns can be applied tomitigate the problem (see <A HREF="#implementation">Implementation</A>).But when the grammar is very complex, other techniques such asparser or compiler generators are more appropriate.</LI><A NAME="auto1056"></A><P></P><A NAME="auto1057"></A><LI><EM>Adding new ways to interpret expressions.</EM>The Interpreter pattern makes it easier to evaluate an expression in anew way.  For example, you can support pretty printing ortype-checking an expression by defining a new operation on theexpression classes.  If you keep creating new ways of interpreting anexpression, then consider using the <A HREF="pat5kfs.htm" TARGET="_mainDisplayFrame">Visitor (331)</A>pattern to avoid changing the grammar classes.</LI></OL><A NAME="implementation"></A><H2><A HREF="#samplecode"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Sample Code"></A> Implementation</H2> <A NAME="auto1058"></A><P>The Interpreter and <A HREF="pat4cfs.htm" TARGET="_mainDisplayFrame">Composite (163)</A>patterns share many implementation issues. The following issuesare specific to Interpreter:</P><OL><A NAME="auto1059"></A><LI><EM>Creating the abstract syntax tree.</EM>The Interpreter pattern doesn't explain how to <EM>create</EM> anabstract syntax tree.  In other words, it doesn't address parsing.The abstract syntax tree can be created by a table-driven parser, by ahand-crafted (usually recursive descent) parser, or directly by theclient.</LI><A NAME="auto1060"></A><P></P><A NAME="variable-w-interp"></A><LI><EM>Defining the Interpret operation.</EM>You don't have to define the Interpret operation in the expressionclasses.  If it's common to create a new interpreter, then it's betterto use the <A HREF="pat5kfs.htm" TARGET="_mainDisplayFrame">Visitor (331)</A> pattern to put Interpret in aseparate "visitor" object.  For example, a grammar for a programminglanguage will have many operations on abstract syntax trees, such asas type-checking, optimization, code generation, and so on. It will bemore likely to use a visitor to avoid defining these operations onevery grammar class.</LI><A NAME="auto1061"></A><P></P><A NAME="flywt-w-interp"></A><A NAME="term-symb-w-flywt"></A><LI><EM>Sharing terminal symbols with the Flyweight pattern.</EM>Grammars whose sentences contain many occurrences of a terminal symbolmight benefit from sharing a single copy of that symbol.  Grammars forcomputer programs are good examples&#151;each program variable willappear in many places throughout the code. In the Motivation example,a sentence can have the terminal symbol <CODE>dog</CODE> (modeled by theLiteralExpression class) appearing many times.<A NAME="auto1062"></A><P>Terminal nodes generally don't store information about their positionin the abstract syntax tree.  Parent nodes pass them whatever contextthey need during interpretation.  Hence there is a distinction betweenshared (intrinsic) state and passed-in (extrinsic) state, and the<A HREF="pat4ffs.htm" TARGET="_mainDisplayFrame">Flyweight (195</A>) pattern applies.</P><A NAME="auto1063"></A><P>For example, each instance of LiteralExpression for <CODE>dog</CODE>receives a context containing the substring matched so far.  And everysuch LiteralExpression does the same thing in its Interpretoperation&#151;it checks whether the next part of the input contains a<CODE>dog</CODE>&#151;no matter where the instance appears in the tree.</P></LI></OL><A NAME="samplecode"><A><H2><A HREF="#knownuses"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Known Uses"></A> Sample Code</H2> <A NAME="auto1064"></A><P>Here are two examples.  The first is a complete example in Smalltalkfor checking whether a sequence matches a regular expression.  Thesecond is a C++ program for evaluating Boolean expressions.</P><A NAME="Smalltalk_example_in_Interpreter"></A><P>The regular expression matcher tests whether a string is in thelanguage defined by the regular expression. The regular expression isdefined by the following grammar:</P><A NAME="auto1065"></A><PRE>    expression ::= literal | alternation | sequence | repetition |                   '(' expression ')'    alternation ::= expression  '|' expression    sequence ::= expression '&amp;' expression    repetition ::= expression 'repeat'    literal ::= 'a' | 'b' | 'c' | ... { 'a' | 'b' | 'c' | ... }*</PRE><A NAME="auto1066"></A><P>This grammar is a slight modification of the Motivation example.  Wechanged the concrete syntax of regular expressions a little, becausesymbol "<CODE>*</CODE>" can't be a postfix operation in Smalltalk.  Sowe use <CODE>repeat</CODE> instead.  For example, the regular expression</P><A NAME="auto1067"></A><PRE>    (('dog ' | 'cat ') repeat &amp; 'weather')</PRE><A NAME="auto1068"></A><P>matches the input string "<CODE>dog dog cat weather</CODE>".</P><A NAME="auto1069"></A><P>To implement the matcher, we define the five classes described on<A HREF="#auto1006">page 243</A>.  The class<CODE>SequenceExpression</CODE> has instance variables<CODE>expression1</CODE> and <CODE>expression2</CODE> for its childrenin the abstract syntax tree.  <CODE>AlternationExpression</CODE>stores its alternatives in the instance variables<CODE>alternative1</CODE> and <CODE>alternative2</CODE>, while<CODE>RepetitionExpression</CODE> holds the expression it repeats in its<CODE>repetition</CODE> instance variable.LiteralExpression has a <CODE>components</CODE> instance variable thatholds a list of objects (probably characters).  These represent the literalstring that must match the input sequence.</P><A NAME="auto1070"></A><P>The <CODE>match:</CODE> operation implements an interpreter for theregular expression.  Each of the classes defining the abstract syntaxtree implements this operation.  It takes<CODE>inputState</CODE> as an argument representing the current stateof the matching process, having read part of the input string.</P><A NAME="auto1071"></A><P>This current state is characterized by a set of input streamsrepresenting the set of inputs that the regular expression could haveaccepted so far.  (This is roughly equivalent to recording all statesthat the equivalent finite state automata would be in, havingrecognized the input stream to this point).</P><A NAME="auto1072"></A><P>The current state is most important to the <CODE>repeat</CODE> operation.For example, if the regular expression were</P><A NAME="auto1073"></A><PRE>    'a' repeat</PRE><A NAME="auto1074"></A><P>then the interpreter could match "<CODE>a</CODE>", "<CODE>aa</CODE>","<CODE>aaa</CODE>", and so on.  If it were</P><A NAME="auto1075"></A><PRE>    'a' repeat &amp; 'bc'</PRE><A NAME="auto1076"></A><P>then it could match "<CODE>abc</CODE>", "<CODE>aabc</CODE>","<CODE>aaabc</CODE>", and so on.  But if the regular expression were</P><A NAME="auto1077"></A><PRE>    'a' repeat &amp; 'abc'</PRE><A NAME="auto1078"></A><P>then matching the input "<CODE>aabc</CODE>" against the subexpression"<CODE>'a' repeat</CODE>" would yield two input streams, one having matchedone character of the input, and the other having matched twocharacters.  Only the stream that has accepted one character willmatch the remaining "<CODE>abc</CODE>".</P><A NAME="seqexp-smalltk"></A><P>Now we consider the definitions of <CODE>match:</CODE> for each classdefining the regular expression. The definition for<CODE>SequenceExpression</CODE> matches each of its subexpressions insequence.  Usually it will eliminate input streams from its<CODE>inputState</CODE>.</P><A NAME="auto1079"></A><PRE>    match: inputState        ^ expression2 match: (expression1 match: inputState).</PRE><A NAME="smallaltexp"></A><P>An <CODE>AlternationExpression</CODE> will return a state that consistsof the union of states from either alternative.  The definition of<CODE>match:</CODE> for <CODE>AlternationExpression</CODE> is</P><A NAME="auto1080"></A><PRE>    match: inputState        | finalState |        finalState := alternative1 match: inputState.        finalState addAll: (alternative2 match: inputState).        ^ finalState</PRE><A NAME="repeatexp-smalltk"></A><P>The <CODE>match:</CODE> operation for <CODE>RepetitionExpression</CODE>tries to find as many states that could match as possible:</P><A NAME="auto1081"></A><PRE>    match: inputState        | aState finalState |        aState := inputState.        finalState := inputState copy.        [aState isEmpty]            whileFalse:                [aState := repetition match: aState.                finalState addAll: aState].            ^ finalState</PRE><A NAME="auto1082"></A><P>Its output state usually contains more states than its input state,because a <CODE>RepetitionExpression</CODE> can match one, two, or manyoccurrences of <CODE>repetition</CODE> on the input state. The outputstates represent all these possibilities, allowing subsequent elementsof the regular expression to decide which state is the correct one.</P><A NAME="literal-small"></A><P>Finally, the definition of <CODE>match:</CODE> for<CODE>LiteralExpression</CODE> tries to match its components against eachpossible input stream.  It keeps only those input streams that have amatch:</P><A NAME="auto1083"></A><PRE>    match: inputState        | finalState tStream |        finalState := Set new.        inputState            do:                [:stream | tStream := stream copy.                    (tStream nextAvailable:                         components size                    ) = components                        ifTrue: [finalState add: tStream]                ].            ^ finalState</PRE><A NAME="auto1084"></A><P>The <CODE>nextAvailable:</CODE> message advances the input stream.  Thisis the only <CODE>match:</CODE> operation that advances the stream.Notice how the state that's returned contains a copy of the inputstream, thereby ensuring that matching a literal never changes theinput stream.  This is important because each alternative of an<CODE>AlternationExpression</CODE> should see identical copies ofthe input stream.</P><A NAME="abssyntree2"></A><P>Now that we've defined the classes that make up an abstract syntaxtree, we can describe how to build it.Rather than write a parser for regular expressions, we'll definesome operations on the <CODE>RegularExpression</CODE> classes so thatevaluating a Smalltalk expression will produce an abstract syntax treefor the corresponding regular expression.  That lets us use thebuilt-in Smalltalk compiler as if it were a parser for regularexpressions.</P><A NAME="buildabssyn"></A><P>To build the abstract syntax tree, we'll need to define"<CODE>|</CODE>", "<CODE>repeat</CODE>", and "<CODE>&amp;</CODE>" asoperations on <CODE>RegularExpression</CODE>. These operations aredefined in class <CODE>RegularExpression</CODE> like this:</P><A NAME="auto1085"></A><PRE>    &amp; aNode        ^ SequenceExpression new            expression1: self expression2: aNode asRExp        repeat        ^ RepetitionExpression new repetition: self        | aNode        ^ AlternationExpression new        alternative1: self alternative2: aNode asRExp        asRExp         ^ self</PRE><A NAME="auto1086"></A><P>The <CODE>asRExp</CODE> operation will convert literals into<CODE>RegularExpressions</CODE>.   These operations are defined in class<CODE>String</CODE>:</P><A NAME="auto1087"></A><PRE>    &amp; aNode        ^ SequenceExpression new            expression1: self asRExp expression2: aNode asRExp        repeat        ^ RepetitionExpression new repetition: self        | aNode        ^ AlternationExpression new            alternative1: self asRExp alternative2: aNode asRExp        asRExp        ^ LiteralExpression new components: self</PRE><A NAME="smalltkv-use-interp"></A><P>If we defined these operations higher up in the class hierarchy(<CODE>SequenceableCollection</CODE> in Smalltalk-80,<CODE>IndexedCollection</CODE> in Smalltalk/V), then they wouldalso be defined for classes such as <CODE>Array</CODE> and<CODE>OrderedCollection</CODE>.  This would letregular expressions match sequences of any kind of object.</P><A NAME="auto1088"></A><P>The second example is a system for manipulating and evaluatingBoolean expressions implemented in C++.  The terminal symbols in thislanguage are Boolean variables, that is, the constants

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久99精品国产.久久久久| 久久精品人人爽人人爽| 国产高清在线观看免费不卡| 美美哒免费高清在线观看视频一区二区 | 日韩 欧美一区二区三区| 亚洲一线二线三线视频| 亚洲一区二区三区在线看| 亚洲午夜久久久| 日韩中文字幕一区二区三区| 久久伊99综合婷婷久久伊| 亚洲成人自拍网| 亚洲香肠在线观看| 五月激情综合婷婷| 日韩综合小视频| 奇米色一区二区| 久久精品久久久精品美女| 国产精品一线二线三线精华| 日本免费在线视频不卡一不卡二 | 亚洲v日本v欧美v久久精品| 亚洲精品久久7777| 人人爽香蕉精品| 国产黄色精品网站| 欧美日韩一区二区在线观看视频 | 欧美日韩卡一卡二| 日韩一区二区三区av| 亚洲国产成人一区二区三区| 亚洲日本成人在线观看| 日韩—二三区免费观看av| 国产一区二区三区在线观看精品 | 综合久久久久久久| 日韩和欧美一区二区三区| 国内精品久久久久影院色| 成a人片亚洲日本久久| 欧美最猛性xxxxx直播| 久久久久久免费| 亚洲国产综合色| 国产一区二区0| 日本韩国欧美在线| 久久女同精品一区二区| 亚洲一区二区精品久久av| 韩国中文字幕2020精品| 欧洲视频一区二区| 蜜乳av一区二区三区| 欧美高清激情brazzers| 久久综合久久鬼色| 亚洲色图一区二区三区| 久久不见久久见免费视频7| 成人午夜视频在线| 欧美三级电影网站| 国产精品嫩草影院av蜜臀| 捆绑紧缚一区二区三区视频 | 国产精品免费丝袜| 热久久免费视频| 日本高清不卡视频| 国产精品久99| 国产一区二区三区电影在线观看 | 自拍偷自拍亚洲精品播放| 久草热8精品视频在线观看| 在线中文字幕一区二区| 国产精品久久久久久妇女6080| 秋霞电影网一区二区| 91同城在线观看| 国产精品久久久99| 国产精品亚洲视频| 久久久久久久久久久黄色| 免费观看在线综合色| 91.麻豆视频| 亚洲h在线观看| 色94色欧美sute亚洲线路一ni| 一区二区三区成人| 另类小说综合欧美亚洲| 欧美精品乱码久久久久久按摩| ●精品国产综合乱码久久久久| 大胆亚洲人体视频| 久久噜噜亚洲综合| 国产成人精品亚洲777人妖| 欧美精品一区二区三区久久久| 另类欧美日韩国产在线| 精品久久久网站| 国产精品白丝jk白祙喷水网站| 精品久久久三级丝袜| 国产精品一区专区| 日本一区二区三区在线不卡| 成人av手机在线观看| 亚洲视频一二三区| 欧美精品精品一区| 日韩av高清在线观看| 精品国产制服丝袜高跟| 国产成人综合网| 国产精品乱人伦一区二区| 色系网站成人免费| 午夜精品爽啪视频| 精品日韩在线一区| 成人黄色在线视频| 一区二区高清在线| 日韩视频中午一区| 丁香天五香天堂综合| 亚洲一区国产视频| 日韩三级av在线播放| 丁香六月综合激情| 一区二区三区丝袜| 日韩一级视频免费观看在线| 国产酒店精品激情| 亚洲影院理伦片| 欧美精品一区二区高清在线观看 | 欧美综合久久久| 蜜桃av噜噜一区| 中文字幕一区视频| 日韩午夜激情av| av在线一区二区| 丝袜亚洲精品中文字幕一区| 久久久精品人体av艺术| 在线观看日韩一区| 国内精品伊人久久久久av一坑| 日韩理论片一区二区| 欧美sm美女调教| 色综合久久88色综合天天| 精品一区二区精品| 艳妇臀荡乳欲伦亚洲一区| 精品国精品国产尤物美女| 色94色欧美sute亚洲13| 国产精品1区2区| 日本午夜一区二区| 亚洲精品网站在线观看| 久久九九国产精品| 91麻豆精品91久久久久同性| 99国产精品久久| 国产精品一二三四五| 三级在线观看一区二区| 综合在线观看色| 日本一区二区三区免费乱视频| 欧美一区二区在线不卡| 欧美亚洲国产一卡| 成人精品视频一区| 国产精品一品二品| 蜜桃av一区二区在线观看| 亚洲第一成年网| 亚洲一区二区黄色| 亚洲卡通欧美制服中文| 国产精品高潮呻吟| 精品国产精品网麻豆系列| 欧美一区二区三区人| 欧美福利一区二区| 欧美裸体一区二区三区| 91久久国产最好的精华液| 99r精品视频| 成人动漫一区二区| 成人福利视频在线| 成人av中文字幕| 福利一区在线观看| 成人美女在线观看| 高清不卡一二三区| 97成人超碰视| 色噜噜狠狠一区二区三区果冻| av在线这里只有精品| 色乱码一区二区三区88| 3d动漫精品啪啪一区二区竹菊| 91精品福利在线| 欧美四级电影在线观看| 欧美日韩另类国产亚洲欧美一级| 欧美日韩一级二级三级| 欧美精品日韩一区| 精品国产一区二区三区不卡 | 亚洲精品国产高清久久伦理二区| 亚洲欧美日本在线| 一区二区三区蜜桃| 午夜国产精品影院在线观看| 天堂va蜜桃一区二区三区漫画版| 日韩国产欧美在线视频| 精品亚洲porn| 波多野结衣在线aⅴ中文字幕不卡| 大白屁股一区二区视频| 色综合网色综合| 欧美四级电影网| 久久香蕉国产线看观看99| 中文字幕一区二区不卡| 午夜av电影一区| 国产黑丝在线一区二区三区| 91麻豆国产福利在线观看| 欧美精品久久一区| 国产日产欧美一区| 亚洲资源中文字幕| 国产一区二区三区日韩| 日本乱人伦aⅴ精品| 精品伦理精品一区| 亚洲品质自拍视频网站| 久久精品国产一区二区三| 不卡av在线免费观看| 日韩一区和二区| |精品福利一区二区三区| 人人超碰91尤物精品国产| 成人午夜免费视频| 欧美一级二级三级蜜桃| 国产精品美日韩| 欧美综合久久久| 麻豆精品在线视频| 97精品久久久久中文字幕| 欧美二区在线观看| 亚洲国产精品一区二区久久恐怖片 | 日韩欧美专区在线|