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.

Creating an interpreter for a language

Creating an interpreter for a language - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 1

Start my 1-month free trial

Creating an interpreter for a language

- [Instructor] One of the possible uses of the interpreter pattern is interpreting code itself. You've probably come across features in your IDE that show you hints when there are things in your code that could be improved. One example is the organize inputs feature where your IDE will rearrange your input statements in alphabetical order and remove any unused ones. In this example, I'm going to implement a new feature similar to those used by your IDE to alter variable names to meet Java naming conventions using the interpreter pattern. So the first thing I need to do to implement the interpreter pattern is create a class which has an interpret method. So I'm going to create a new class called Expression and this is going to be an interface. I'm just going to define a single method in here called interprets and it's going to return a String. So I'm going to do String interpret and it's going to take a String as an…

Contents