Interpreter in design mode

xiaoxiao2021-03-06  73

Interpreter Interpreter Mode Definition: Defines the textual method of the language and establishes an interpreter to explain the sentence in the language.

Interpreter seems not very wide, it describes how a language interpreter is constituted, in practical applications, we may rarely construct a language of literacy. We still come to learn about it:

First create an interface to describe common operations.

Public interface AbstractExpression {void interpret (context context);

Take a look at some global information other than the interpreter.

Public interface context {}

Part of AbstractExpression is divided into two species: end-assignment expressions and non-endache expression:

Public Class TerminalExpression Implements AbstractExpression {Public Void Interpret (CONTEXT CONTEXT) {}

For not a grammar rule nonterminal expressions must: public class NonterminalExpression implements AbstractExpression {private AbstractExpression successor; public void setSuccessor (AbstractExpression successor) {this.successor = successor;} public AbstractExpression getSuccessor () {return successor; } Public void interpret (context context) {}}

转载请注明原文地址:https://www.9cbs.com/read-93051.html

New Post(0)