Implementation References Formal Grammar Formal Grammar at the University of Minnesota. The Structure of Higher Level Languages. Efficiency is not a critical concern. Use the Interpreter pattern when the semantics and syntax of the language you are trying to interpret can be expressed by well defined rules.
Parser generators are a better choice for more complex languages.
The Interpreter design pattern is logically oriented and expressed in an orderly, easily comprehendible manner. There is a definite tradeoff between comprehendibility and efficiency. Participants The AbstractExpression class declares an abstract Interpret operation that is common to all nodes in the abstract syntax tree. TerminalExpression classes implement the Interpret method associated with terminal symbols in the grammar. This class is used when the interpretation is based on a literal comparison.