Interpreter

E173616

Interpreter is a behavioral design pattern that defines a representation for a language’s grammar along with an interpreter that uses this representation to interpret sentences in the language.

All labels observed (2)

How this entity was disambiguated

Statements (45)

Predicate Object
instanceOf Behavioral design pattern
Design pattern
advantage Encapsulates grammar rules in classes
Makes it easy to change and extend the grammar
Makes it easy to implement a simple language
alternativeTo Using a full parser generator for simple languages
applicableWhen Efficiency is not a primary concern
The grammar is simple
The language can be represented as an abstract syntax tree
bestFor Small, well-defined grammars
contextHolds Global state for interpretation
Input string or tokens
Variable bindings
definedIn Design Patterns: Elements of Reusable Object-Oriented Software
surface form: Gang of Four design patterns
definesOperation Interpret
definesRole Interpreter self-linksurface differs
surface form: AbstractExpression defines an abstract Interpret operation

Context stores global information for interpretation
NonterminalExpression implements Interpret for nonterminal symbols
TerminalExpression implements Interpret for terminal symbols
describedIn Design Patterns: Elements of Reusable Object-Oriented Software
disadvantage Can be hard to maintain for large languages
Complex grammars lead to many classes
May be inefficient for complex parsing
hasCategory Behavioral pattern
hasComponent AbstractExpression
Context
NonterminalExpression
TerminalExpression
hasIntent Define a representation for a language’s grammar
Provide an interpreter to evaluate sentences in the language
notRecommendedFor Complex, industrial-strength languages
oftenImplementedWith Composite pattern
Visitor pattern
relatedTo Composite pattern
Iterator pattern
Visitor design pattern
surface form: Visitor pattern
structureBasedOn Abstract syntax tree
typicalUseCase Boolean expression evaluation
Configuration or rule languages
Mathematical expression evaluation
Simple query languages
usedFor Defining simple domain-specific languages
Implementing simple grammars
Interpreting sentences in a language
Parsing and evaluating expressions

How these facts were elicited

Referenced by (2)

Full triples — surface form annotated when it differs from this entity's canonical label.

Interpreter definesRole Interpreter self-linksurface differs
this entity surface form: AbstractExpression defines an abstract Interpret operation