Jump to content

Talk:Interpreter pattern

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 78.105.136.120 (talk) at 20:37, 15 April 2012 (Errors in diagram). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconJava Stub‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StubThis article has been rated as Stub-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.
Note icon
This article has been automatically rated by a bot or other tool as Stub-class because it uses a stub template. Please ensure the assessment is correct before removing the |auto= parameter.
WikiProject iconComputing Stub‑class
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StubThis article has been rated as Stub-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
Note icon
This article has been automatically rated by a bot or other tool as Stub-class because it uses a stub template. Please ensure the assessment is correct before removing the |auto= parameter.

What does the link "Block (Java programming language)" mean? It points to nowhere. Lathspell 18:12, 18 February 2006 (UTC)[reply]

I doubt that the interpreter patter is described correctly since this page describes it very differently. http://www.exciton.cs.rice.edu/JAvaResources/DesignPatterns/intepreter.htm80.141.90.99 13:35, 8 June 2007 (UTC) see also http://home.earthlink.net/~huston2/dp/interpreter.html 80.141.90.99 13:37, 8 June 2007 (UTC)[reply]

I dont know what you mean, the operation() method is replaced by the execute() method, the concept is exactly the same.

--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 [reply]

                       IExpression r = stack.Pop();
                       IExpression l = stack.Pop();
                       stack.Push(new Plus(l, r));

instead of

                       stack.Push(new Plus(stack.Pop(), stack.Pop()));

Corrected code:

           public Evaluator(string expression)
           {
               Stack<IExpression> stack = new Stack<IExpression>();
               foreach (string token in expression.Split(' '))
               {
                   if (token.Equals("+"))
                   {
                       IExpression r = stack.Pop();
                       IExpression l = stack.Pop();
                       stack.Push(new Plus(l, r));
                   }
                   else if (token.Equals("-"))
                   {
                       IExpression r = stack.Pop();
                       IExpression l = stack.Pop();
                       stack.Push(new Minus(l, r));
                   }
                   else
                       stack.Push(new Variable(token));
               }
               syntaxTree = stack.Pop();
           }


Go language

If we ever wanted to supply an example of this pattern in the Go language , this may be a good starting point. Bovlb (talk) 20:06, 15 January 2010 (UTC)[reply]

Errors in diagram

The "Interpret(Context)" methods in TerminalExpression and NonTerminalExpression are in italics, which indicates they are abstract. Clearly they are meant to be concrete implementations of the abstract method "Interpret(Context)" in AbstractExpression. The "Interpret(Context)" should have italics removed in the *subclasses*. 14:41, 15 April 2012 (UTC) — Preceding unsigned comment added by 78.105.136.120 (talk) It has come to my attention that if this is a GoF diagram then it is probably in OMT and not UML. My reasoning above is for the UML diagram, I am not aware of correctness for OMT. I'll leave the comment above just in case some other unassuming developer comes across here and expects to be seeing UML. :)