<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Interpreter_pattern</id>
	<title>Interpreter pattern - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Interpreter_pattern"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;action=history"/>
	<updated>2026-10-26T02:28:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;diff=4500967&amp;oldid=prev</id>
		<title>imported&gt;SchlurcherBot: Bot: http → https</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;diff=4500967&amp;oldid=prev"/>
		<updated>2025-11-26T00:38:32Z</updated>

		<summary type="html">&lt;p&gt;Bot: http → https&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Previous revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:38, 26 November 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l218&quot;&gt;Line 218:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 218:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== External links ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== External links ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{wikibooks|Computer Science Design Patterns|Interpreter}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{wikibooks|Computer Science Design Patterns|Interpreter}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;http&lt;/del&gt;://lukaszwrobel.pl/blog/interpreter-design-pattern Interpreter implementation] in [[Ruby (programming language)|Ruby]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https&lt;/ins&gt;://lukaszwrobel.pl/blog/interpreter-design-pattern Interpreter implementation] in [[Ruby (programming language)|Ruby]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://github.com/jamesdhutton/Interpreter Interpreter implementation] in [[C++]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://github.com/jamesdhutton/Interpreter Interpreter implementation] in [[C++]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;http&lt;/del&gt;://sourcemaking.com/design_patterns/interpreter SourceMaking tutorial]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https&lt;/ins&gt;://sourcemaking.com/design_patterns/interpreter SourceMaking tutorial]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [http://c2.com/cgi/wiki?InterpreterPattern Interpreter pattern description from the Portland Pattern Repository]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [http://c2.com/cgi/wiki?InterpreterPattern Interpreter pattern description from the Portland Pattern Repository]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;SchlurcherBot</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;diff=3425657&amp;oldid=prev</id>
		<title>~2025-30963-97: Not vandalism, go harass someone else with this nonsense</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;diff=3425657&amp;oldid=prev"/>
		<updated>2025-11-04T20:08:26Z</updated>

		<summary type="html">&lt;p&gt;Not vandalism, go harass someone else with this nonsense&lt;/p&gt;
&lt;a href=&quot;http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;amp;diff=3425657&amp;amp;oldid=119285&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>~2025-30963-97</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;diff=119285&amp;oldid=prev</id>
		<title>imported&gt;RJFJR: /* What problems can the Interpreter design pattern solve?{{cite web|title=The Interpreter design pattern - Problem, Solution, and Applicability|url=http://w3sdesign.com/?gr=b03&amp;ugr=proble|website=w3sDesign.com|access-date=2017-08-12}} */ move ref out of heading</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Interpreter_pattern&amp;diff=119285&amp;oldid=prev"/>
		<updated>2024-03-28T00:16:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;What problems can the Interpreter design pattern solve?{{cite web|title=The Interpreter design pattern - Problem, Solution, and Applicability|url=http://w3sdesign.com/?gr=b03&amp;amp;ugr=proble|website=w3sDesign.com|access-date=2017-08-12}}: &lt;/span&gt; move ref out of heading&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Approach in computer programming}}&lt;br /&gt;
{{Refimprove|date=November 2008}}&lt;br /&gt;
&lt;br /&gt;
In [[computer programming]], the &amp;#039;&amp;#039;&amp;#039;interpreter pattern&amp;#039;&amp;#039;&amp;#039; is a [[design pattern (computer science)|design pattern]] that specifies how to evaluate sentences in a language.&lt;br /&gt;
The basic idea is to have a [[Class (computer science)|class]] for each symbol ([[Terminal symbol|terminal]] or [[Nonterminal symbol|nonterminal]]) in a [[Domain specific languages|specialized computer language]]. The [[abstract syntax tree|syntax tree]] of a sentence in the language is an instance of the [[composite pattern]] and is used to evaluate (interpret) the sentence for a client.&amp;lt;ref name=GoF&amp;gt;{{cite book |author1=Gamma, Erich |author2-link=Richard Helm |author2=Helm, Richard |author3=Johnson, Ralph |author4=Vlissides, John |&lt;br /&gt;
 title=Design Patterns: Elements of Reusable Object-Oriented Software |&lt;br /&gt;
 publisher=Addison-Wesley |&lt;br /&gt;
 year=1994 |&lt;br /&gt;
 isbn=0-201-63361-2&lt;br /&gt;
 |author1-link=Erich Gamma |title-link=Design Patterns }}&amp;lt;/ref&amp;gt;{{rp|243}} See also [[Composite pattern]].&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The Interpreter&lt;br /&gt;
&amp;lt;ref name=&amp;quot;GoF2&amp;quot;&amp;gt;{{cite book|author=Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides|title=Design Patterns: Elements of Reusable Object-Oriented Software|year=1994|publisher=Addison Wesley|isbn=0-201-63361-2|pages=[https://archive.org/details/designpatternsel00gamm/page/243 243ff]|url-access=registration|url=https://archive.org/details/designpatternsel00gamm/page/243}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
design pattern is one of the twenty-three well-known &lt;br /&gt;
&amp;#039;&amp;#039;[[Design Patterns|GoF design patterns]]&amp;#039;&amp;#039; &lt;br /&gt;
that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse.&lt;br /&gt;
&lt;br /&gt;
===What problems can the Interpreter design pattern solve?===&lt;br /&gt;
&lt;br /&gt;
Source:&amp;lt;ref&amp;gt;{{cite web|title=The Interpreter design pattern - Problem, Solution, and Applicability|url=http://w3sdesign.com/?gr=b03&amp;amp;ugr=proble|website=w3sDesign.com|access-date=2017-08-12}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A [[Backus-Naur form|grammar]] for a simple language should be defined&lt;br /&gt;
* so that sentences in the language can be interpreted.&lt;br /&gt;
&lt;br /&gt;
When a problem occurs very often, it could be considered to represent it as a sentence in a simple language&lt;br /&gt;
([[Domain-specific language|Domain Specific Languages]]) so that an interpreter can solve the problem&lt;br /&gt;
by interpreting the sentence.&lt;br /&gt;
&lt;br /&gt;
For example, when many different or complex search expressions must be specified.&lt;br /&gt;
Implementing (hard-wiring) them directly into a class is inflexible&lt;br /&gt;
because it commits the class to particular expressions and makes it impossible to specify new expressions or change existing ones independently from (without having to change) the class.&lt;br /&gt;
&lt;br /&gt;
===What solution does the Interpreter design pattern describe?===&lt;br /&gt;
* Define a grammar for a simple language by defining an &amp;lt;code&amp;gt;Expression&amp;lt;/code&amp;gt; class hierarchy and implementing an &amp;lt;code&amp;gt;interpret()&amp;lt;/code&amp;gt; operation.&lt;br /&gt;
* Represent a sentence in the language by an abstract syntax tree (AST) made up of &amp;lt;code&amp;gt;Expression&amp;lt;/code&amp;gt; instances.&lt;br /&gt;
* Interpret a sentence by calling &amp;lt;code&amp;gt;interpret()&amp;lt;/code&amp;gt; on the AST.&lt;br /&gt;
&lt;br /&gt;
The expression objects are composed recursively into a composite/tree structure that is called&lt;br /&gt;
&amp;#039;&amp;#039;abstract syntax tree&amp;#039;&amp;#039; (see [[Composite pattern]]).&lt;br /&gt;
&amp;lt;br&amp;gt;The Interpreter pattern doesn&amp;#039;t describe how&lt;br /&gt;
to build an abstract syntax tree. This can&lt;br /&gt;
be done either manually by a client or automatically by a [[parser]].&lt;br /&gt;
&lt;br /&gt;
See also the UML class and object diagram below.&lt;br /&gt;
&lt;br /&gt;
== Uses ==&lt;br /&gt;
* Specialized database query languages such as [[SQL]].&lt;br /&gt;
* Specialized computer languages that are often used to describe communication protocols.&lt;br /&gt;
* Most general-purpose computer languages actually incorporate several specialized languages{{Citation needed|reason=Need reference to a language doing this|date=September 2022}}.&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
=== UML class and object diagram ===&lt;br /&gt;
[[File:w3sDesign Interpreter Design Pattern UML.jpg|frame|none|A sample UML class and object diagram for the Interpreter design pattern.&amp;lt;ref&amp;gt;{{cite web|title=The Interpreter design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=b03&amp;amp;ugr=struct|website=w3sDesign.com|access-date=2017-08-12}}&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
In the above [[Unified Modeling Language|UML]] [[class diagram]], the &amp;lt;code&amp;gt;Client&amp;lt;/code&amp;gt; class refers to the common &amp;lt;code&amp;gt;AbstractExpression&amp;lt;/code&amp;gt; interface for interpreting an expression&lt;br /&gt;
&amp;lt;code&amp;gt;interpret(context)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;TerminalExpression&amp;lt;/code&amp;gt; class has no children and interprets an expression directly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;NonTerminalExpression&amp;lt;/code&amp;gt; class maintains a container of child expressions&lt;br /&gt;
(&amp;lt;code&amp;gt;expressions&amp;lt;/code&amp;gt;) and forwards interpret requests&lt;br /&gt;
to these &amp;lt;code&amp;gt;expressions&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The object collaboration diagram &lt;br /&gt;
shows the run-time interactions: The &amp;lt;code&amp;gt;Client&amp;lt;/code&amp;gt; object sends an interpret request to the abstract syntax tree.&lt;br /&gt;
The request is forwarded to (performed on) all objects downwards the tree structure.&lt;br /&gt;
&amp;lt;br&amp;gt;The &amp;lt;code&amp;gt;NonTerminalExpression&amp;lt;/code&amp;gt; objects (&amp;lt;code&amp;gt;ntExpr1,ntExpr2&amp;lt;/code&amp;gt;) forward the request to their child expressions.&lt;br /&gt;
&amp;lt;br&amp;gt;The &amp;lt;code&amp;gt;TerminalExpression&amp;lt;/code&amp;gt; objects (&amp;lt;code&amp;gt;tExpr1,tExpr2,&amp;amp;hellip;&amp;lt;/code&amp;gt;) perform the interpretation directly.&lt;br /&gt;
&lt;br /&gt;
=== UML class diagram ===&lt;br /&gt;
[[Image:Interpreter_UML_class_diagram.svg]]&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;!-- Wikipedia is not a list of examples. Do not add examples from favorite programming languages here; this page exists to explain the design pattern, not to show how it interacts with subtleties of every language extant. Feel free to add examples at: http://en.wikibooks.org/wiki/Computer_Science_Design_Patterns/Interpreter --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This C++11 implementation is based on the pre C++98 sample code in the book.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;map&amp;gt;&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Context;&lt;br /&gt;
&lt;br /&gt;
class BooleanExp {&lt;br /&gt;
public:&lt;br /&gt;
  BooleanExp() = default;&lt;br /&gt;
  virtual ~BooleanExp() = default;&lt;br /&gt;
  virtual bool evaluate(Context&amp;amp;) = 0;&lt;br /&gt;
  virtual BooleanExp* replace(const char*, BooleanExp&amp;amp;) = 0;&lt;br /&gt;
  virtual BooleanExp* copy() const = 0;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
class VariableExp;&lt;br /&gt;
&lt;br /&gt;
class Context {&lt;br /&gt;
public:&lt;br /&gt;
  Context() :m() {}&lt;br /&gt;
  bool lookup(const VariableExp* key) { return m.at(key); }&lt;br /&gt;
  void assign(VariableExp* key, bool value) { m[key] = value; }&lt;br /&gt;
private:&lt;br /&gt;
  std::map&amp;lt;const VariableExp*, bool&amp;gt; m;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
class VariableExp : public BooleanExp {&lt;br /&gt;
public:&lt;br /&gt;
  VariableExp(const char* name_) :name(nullptr) {&lt;br /&gt;
    name = strdup(name_);&lt;br /&gt;
  }&lt;br /&gt;
  virtual ~VariableExp() = default;&lt;br /&gt;
  virtual bool evaluate(Context&amp;amp; aContext) {&lt;br /&gt;
    return aContext.lookup(this);&lt;br /&gt;
  }&lt;br /&gt;
  virtual BooleanExp* replace( const char* name_, BooleanExp&amp;amp; exp ) {&lt;br /&gt;
    if (0 == strcmp(name_, name)) {&lt;br /&gt;
      return exp.copy();&lt;br /&gt;
    } else {&lt;br /&gt;
      return new VariableExp(name);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  virtual BooleanExp* copy() const {&lt;br /&gt;
    return new VariableExp(name);&lt;br /&gt;
  }&lt;br /&gt;
  VariableExp(const VariableExp&amp;amp;) = delete; // rule of three&lt;br /&gt;
  VariableExp&amp;amp; operator=(const VariableExp&amp;amp;) = delete;&lt;br /&gt;
private:&lt;br /&gt;
  char* name;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
class AndExp : public BooleanExp {&lt;br /&gt;
public:&lt;br /&gt;
  AndExp(BooleanExp* op1, BooleanExp* op2)&lt;br /&gt;
    :operand1(nullptr), operand2(nullptr) {&lt;br /&gt;
    operand1 = op1;&lt;br /&gt;
    operand2 = op2;&lt;br /&gt;
  }&lt;br /&gt;
  virtual ~AndExp() = default;&lt;br /&gt;
  virtual bool evaluate(Context&amp;amp; aContext) {&lt;br /&gt;
    return operand1-&amp;gt;evaluate(aContext) &amp;amp;&amp;amp; operand2-&amp;gt;evaluate(aContext);&lt;br /&gt;
  }&lt;br /&gt;
  virtual BooleanExp* replace(const char* name_, BooleanExp&amp;amp; exp) {&lt;br /&gt;
    return new AndExp(&lt;br /&gt;
        operand1-&amp;gt;replace(name_, exp),&lt;br /&gt;
        operand2-&amp;gt;replace(name_, exp)&lt;br /&gt;
      );&lt;br /&gt;
  }&lt;br /&gt;
  virtual BooleanExp* copy() const {&lt;br /&gt;
    return new AndExp(operand1-&amp;gt;copy(), operand2-&amp;gt;copy());&lt;br /&gt;
  }&lt;br /&gt;
  AndExp(const AndExp&amp;amp;) = delete; // rule of three&lt;br /&gt;
  AndExp&amp;amp; operator=(const AndExp&amp;amp;) = delete;&lt;br /&gt;
private:&lt;br /&gt;
  BooleanExp* operand1;&lt;br /&gt;
  BooleanExp* operand2;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  BooleanExp* expression;&lt;br /&gt;
  Context context;&lt;br /&gt;
  VariableExp* x = new VariableExp(&amp;quot;X&amp;quot;);&lt;br /&gt;
  VariableExp* y = new VariableExp(&amp;quot;Y&amp;quot;);&lt;br /&gt;
  expression = new AndExp(x, y);&lt;br /&gt;
&lt;br /&gt;
  context.assign(x, false);&lt;br /&gt;
  context.assign(y, true);&lt;br /&gt;
  bool result = expression-&amp;gt;evaluate(context);&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; result &amp;lt;&amp;lt; &amp;#039;\n&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
  context.assign(x, true);&lt;br /&gt;
  context.assign(y, true);&lt;br /&gt;
  result = expression-&amp;gt;evaluate(context);&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; result &amp;lt;&amp;lt; &amp;#039;\n&amp;#039;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The program output is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Backus–Naur form]]&lt;br /&gt;
* [[Combinator#Combinatory logic in computing|Combinatory logic in computing]]&lt;br /&gt;
* &amp;#039;&amp;#039;[[Design Patterns]]&amp;#039;&amp;#039;&lt;br /&gt;
* [[Domain-specific language]]&lt;br /&gt;
* [[Interpreter (computing)]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
{{wikibooks|Computer Science Design Patterns|Interpreter}}&lt;br /&gt;
* [http://lukaszwrobel.pl/blog/interpreter-design-pattern Interpreter implementation] in [[Ruby (programming language)|Ruby]]&lt;br /&gt;
* [https://github.com/jamesdhutton/Interpreter Interpreter implementation] in [[C++]]&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/interpreter SourceMaking tutorial]&lt;br /&gt;
* [http://c2.com/cgi/wiki?InterpreterPattern Interpreter pattern description from the Portland Pattern Repository]&lt;br /&gt;
&lt;br /&gt;
{{Design Patterns Patterns}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Articles with example C Sharp code]]&lt;br /&gt;
[[Category:Articles with example Java code]]&lt;br /&gt;
[[Category:Software design patterns]]&lt;/div&gt;</summary>
		<author><name>imported&gt;RJFJR</name></author>
	</entry>
</feed>