. NET design Pattern instance interpreter mode (interpreter pattern)

Source: Internet
Author: User
Tags abstract extend

Introduction to the Interpreter model (Brief Introduction)

The Interpreter mode (interpreter pattern), given a language, defines a representation of its grammar, and defines an interpreter that uses the representation to interpret a sentence in a language. With the interpreter pattern, you can easily change and extend the grammar, because the pattern uses classes to represent the grammar rules, and you can use inheritance to change or extend the grammar. It is also easier to implement grammars because the implementations of classes that define the nodes in the abstract syntax tree are broadly similar, and these classes are easy to write directly.

Ii. issues addressed (What to Solve)

If the frequency of a particular type of problem is high enough, it may be worthwhile to express each instance of the problem as a sentence in a simple language so that an interpreter can be constructed that interprets the sentences to solve the problem.

Analysis of Interpreter mode

1. Interpreter Mode structure

Abstractexpression abstract class: Declares an interface for performing an operation.

Terminalexpression class: An non-terminal expression that implements an interpretation operation related to the non-terminal in the grammar.

Nonterminalexpression class: A non-terminal expression that interprets operations for a non-non-terminal implementation in a grammar. R1 and R2 every rule in grammar. RN requires a specific non-terminal expression class.

Context class: Contains some global information outside the 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.