The interpreter pattern (interpreter pattern) is a scheme that is parsed in accordance with the prescribed syntax, and is used less in the current project (who has nothing to do with writing a PHP or Ruby parser), which is defined as follows: Given a language, define a Representation for it grammar along with a interpreter that uses the representation-interpret sentences in the Langua Ge Given a language, define a representation of its grammar and define an interpreter that uses that representation to interpret sentences in the language.
General class diagram for interpreter mode
Abstractexpression Abstract Interpreter
The specific interpretation task is completed by each implementation class, and the specific interpreter is completed by Terminalexpression and Nonterminalexpression.
Terminalexpression-Terminator Expression
Implements an interpreted operation associated with an element in the grammar, usually with only one terminator expression in an interpreter pattern, but with multiple instances that correspond to different terminators. Specifically to our example is the Varexpression class, where each terminator in the expression produces a Varexpression object in the stack.
Nonterminalexpression Non-Terminator expression
Each rule in the grammar corresponds to a non-terminating expression, and our example is that the addition and subtraction rules correspond to the two classes of addexpression and subexpression respectively. The non-terminator expression increases according to the complexity of the logic, in principle each grammar rule corresponds to a non-terminator expression.
The style of the software architecture---interpreter