System Design
15. Software Design PatternsAnimated walkthrough
Interpreter Pattern
Evaluate sentences of a small language.
The idea
A grammar is modelled as classes that interpret expressions.
Watch it work
The steps light up one at a time. Use the controls to pause or step through.
- 1Define the grammar
- 2Build an expression tree
- 3Interpret it
- 4Return the result
1/4
Step by step
- 1Define the grammar
- 2Build an expression tree
- 3Interpret it
- 4Return the result
Where it is used
Rules and query languages.
Watch out for
Slow and hard for large grammars.