Interpreter in design mode

zhaozj2021-02-16  102

Interpreter definition: Define the textual method of the language and establish an interpreter to explain the sentence in the 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-based law. We still come to a simple understanding:

First create a interface, used to describe a common operation.

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 types: end conforming operations and non-ending operations:

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

For not a grammar rule nonterminal expressions are necessary: ​​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) {}}

Posted on June 24, 2004 8:13 PM

HREF = "/ arielxp / services / pingback.aspx" rel = "pingback">

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

New Post(0)