Talk:Interpreter pattern: Difference between revisions

Content deleted Content added
syntaxhighlight & fix lint
 
(6 intermediate revisions by 4 users not shown)
Line 1:
{{WikiProject Javabanner shell|class=StubStart|importance=low|auto=yes}}
{{WikiProject Computing|class=StubJava|importance=low|auto=yes}}
{{WikiProject Computing|importance=|auto=yes}}
}}
What does the link "Block (Java programming language)" mean? It points to nowhere. [[User:Lathspell|Lathspell]] 18:12, 18 February 2006 (UTC)
 
Line 10 ⟶ 12:
 
--[[Special:Contributions/98.225.38.255|98.225.38.255]] ([[User talk:98.225.38.255|talk]]) 23:25, 13 February 2010 (UTC) I think the C# (and probably Java version is wrong). The problem is in Evaluator function, the left and right operands are switched. If you compute 6 - 4 or 6 4 - , the result that you get is 4 - 6. The solution is
<syntaxhighlight lang="text">
<code>
IExpression r = stack.Pop();
IExpression l = stack.Pop();
stack.Push(new Plus(l, r));
</syntaxhighlight>
</code>
 
instead of
 
<syntaxhighlight lang="text">
<code>
stack.Push(new Plus(stack.Pop(), stack.Pop()));
</syntaxhighlight>
</code>
Corrected code:
<syntaxhighlight lang="text">
<code>
public Evaluator(string expression)
{
Line 45 ⟶ 47:
syntaxTree = stack.Pop();
}
</syntaxhighlight>
</code>
 
 
Line 59 ⟶ 61:
== Not confined to language processing ==
 
The point of design patterns is to recognize general patterns so that they can be applied anywhere. Unfortunately, the description of this pattern seems to be unnecessarily tied to a specific example both in the GOF book and in this article. A good counter-example would be to use aan class hierarchy (or tree of interface implementations) of functional objectsinterpreter to determine the taxonomic classification of a specimen such as an animal, each level of the tree delegating the identification to the proper child branch until the specimen is identified. That identification could use image processing, chemical analysis, and other techniques which are not tied to any language. There is no grammar to interpret, yet this is the same pattern of code.
 
A more general and useful definition might be a "Rules Engine" as [http://www.oodesign.com/interpreter-pattern.html OODesign.com] suggests. Really, it's a tree data structure of functional objects (each implementing the same single method). The functional objects "rules" delegate to one another until a terminal object (rule) is reached. The objects could be related through an interface and through the logic in their single implemented method instead of through an object-oriented inheritance hierarchy. If no-one finds somewhere that this has already been stated clearly, I can add it to my blog and someone who doesn't know me can come along some day and use that as a source to improve this article.
 
Hmm... I'm partly talking myself out of this. Interpreter is what it is. It would have been nice if GOF named it RuleDelegator because it would be more applicable to more problems and be a more useful pattern.
 
--[[User:GlenPeterson|GlenPeterson]] ([[User talk:GlenPeterson|talk]]) 15:14, 23 October 2013 (UTC)