Talk:Interpreter pattern
![]() | Java Stub‑class ![]() | ||||||||||||
|
![]() | Computing Stub‑class ![]() | ||||||||||||
|
What does the link "Block (Java programming language)" mean? It points to nowhere. Lathspell 18:12, 18 February 2006 (UTC)
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)
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
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)