The style of the software architecture---interpreter

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.