Java interpreter mode (interpreter mode)

Source: Internet
Author: User

Interpreter definition: Define the grammar of the language and create an interpreter to interpret the sentences in that language.

Interpreter seems to use the surface is not very wide, it describes how a language interpreter is constituted, in practical applications, we may rarely construct a language grammar. Let's just take a quick look.

The first thing to do is to create an interface to describe the common operation.
     Public Interface  void  interpret (context context);    

And look at some of the global information that contains the interpreter.

   Public Interfacethe specific implementation of the Context {}abstractexpression is divided into two types: Terminator expressions and non-terminator expressions.  Public classTerminalexpressionImplementsabstractexpression { Public voidinterpret (context context) {}} There is no rule in grammar, and non-terminator expressions are required: Public classNonterminalexpressionImplementsabstractexpression {PrivateAbstractexpression successor;  Public voidSetsuccessor (abstractexpression successor) { This. successor =successor; } Publicabstractexpression getsuccessor () {returnsuccessor; } Public voidinterpret (context context) {}}

Java interpreter mode (interpreter mode)

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.