Interpreter pattern

The basic idea is to have a class for each symbol (terminal or nonterminal) in a specialized computer language.

Source:[3] When a problem occurs very often, it could be considered to represent it as a sentence in a simple language (Domain Specific Languages) so that an interpreter can solve the problem by interpreting the sentence.

The expression objects are composed recursively into a composite/tree structure that is called abstract syntax tree (see Composite pattern).

The Interpreter pattern doesn't describe how to build an abstract syntax tree.

This C++11 implementation is based on the pre C++98 sample code in the book.

A sample UML class and object diagram for the Interpreter design pattern. [ 4 ]