Interpreter definition: Defines the grammar of a language and creates an interpreter to interpret the sentences in that language.
Interpreter does not seem to have a wide range of facets, it describes how a language interpreter is constructed, and in practical applications we may rarely construct a language grammar. Let's just take a quick look.
The first step is to create an interface to describe the common operation.
Copy Code code as follows:
Public interface Abstractexpression {
void interpret (context context);
}
And look at some global information outside of the interpreter.
Copy Code code as follows:
Public interface Context {}
The concrete implementations of abstractexpression are divided into two types: non-terminal expressions and non-terminal expressions.
public class Terminalexpression implements Abstractexpression {
public void Interpret {}
}
No non-terminal expression is required for a rule in the grammar:
public class Nonterminalexpression implements Abstractexpression {
Private Abstractexpression successor;
public void Setsuccessor (Abstractexpression successor) {
This.successor = successor;
}
Public Abstractexpression Getsuccessor () {
return successor;
}
public void Interpret {}
}