From the course: Java Design Patterns: Behavioral Part 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding the Interpreter pattern

Understanding the Interpreter pattern - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 1

Start my 1-month free trial

Understanding the Interpreter pattern

- [Instructor] Imagine a scenario, where two people are trying to communicate but they don't speak the same language. A translator or an interpreter can join them and translates everything they say to each other. The interpreter pattern is a way of translating one language into another. So if you think of Google translate for example, it takes the input language and interprets it into a new language. There are many different and varied scenarios where the interpreter pattern might be used. It could be used to write custom regular expressions or writes your own compiler or translate human languages or parsers SQL, or just create a simple calculator. The idea of the interpreter pattern in Java is that if the same problem keeps coming up, then you can express that problem as a sentence and interpret it. The interpreter defines a grammar for the language and then used as an abstract syntax tree to interpret it. This is quite a…

Contents