You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Executing the program produces the following console output.
144
+
145
+
```
146
+
popped from stack left: 1 right: 1
147
+
operator: +
148
+
push result to stack: 2
149
+
popped from stack left: 4 right: 2
150
+
operator: *
151
+
push result to stack: 8
152
+
result: 8
153
+
```
16
154
17
155
##Class diagram
156
+
18
157

19
158
20
159
##Applicability
21
-
Use the Interpreter pattern when there is a language to
22
-
interpret, and you can represent statements in the language as abstract syntax
23
-
trees. The Interpreter pattern works best when
24
160
25
-
* the grammar is simple. For complex grammars, the class hierarchy for the grammar becomes large and unmanageable. Tools such as parser generators are a better alternative in such cases. They can interpret expressions without building abstract syntax trees, which can save space and possibly time
26
-
* efficiency is not a critical concern. The most efficient interpreters are usually not implemented by interpreting parse trees directly but by first translating them into another form. For example, regular expressions are often transformed into state machines. But even then, the translator can be implemented by the Interpreter pattern, so the pattern is still applicable
161
+
Use the Interpreter pattern when there is a language to interpret, and you can represent statements
162
+
in the language as abstract syntax trees. The Interpreter pattern works best when
163
+
164
+
* The grammar is simple. For complex grammars, the class hierarchy for the grammar becomes large and unmanageable. Tools such as parser generators are a better alternative in such cases. They can interpret expressions without building abstract syntax trees, which can save space and possibly time
165
+
* Efficiency is not a critical concern. The most efficient interpreters are usually not implemented by interpreting parse trees directly but by first translating them into another form. For example, regular expressions are often transformed into state machines. But even then, the translator can be implemented by the Interpreter pattern, so the pattern is still applicable