HomePHP Manipulating String Literals with Interpreter Classes in PHP 5
Manipulating String Literals with Interpreter Classes in PHP 5
Among the huge variety of design patterns that can be easily implemented in PHP 5, the interpreter is one that might be particularly interesting to you. It allows you to build effortlessly the so-called parser layers. Welcome to the second installment of the series that began with “Building Interpreter Classes with PHP 5.” Made up of three parts, this series introduces the core concepts on this useful pattern, and also complements its theory with numerous educational hands-on examples.
Stepping back for a moment to the preceding article of the series, I’m pretty sure that all the concepts deployed in that tutorial concerning the concrete implementation of the interpreter pattern in PHP 5 will be familiar to you now. However, if that’s not the case, let me remind you quickly how this pattern works, so you can grasp more easily all the code samples that I plan to include in this article.
In plain terms, where this pattern is applied, there’s a class, usually called “interpreter,” which is responsible for parsing a predefined set of commands. These commands are sent out by one or more additional classes. As you can see, this definition is easy to understand because it is similar to the concept of parsers.
However, building interpreter classes is by far a much simpler process than developing full-featured parsers. I hope to demonstrate this by showing you some didactical code samples, where this pattern will be mostly used as a simple yet efficient parsing layer.
Bearing in mind that in the first article of the series I illustrated how to use an interpreter class to handle a group of fictional users, in this tutorial I’m going to go teach you how to utilize this pattern for manipulating a set of string processing classes.
By the end of this tutorial, you should be equipped with a solid background in how the interpreter pattern works. This may be very useful to you, particularly if you’re taking your first steps into pattern-based programming with PHP 5.
Now, having outlined the topics that will be covered in the next few lines, it’s time to move on and continue learning more on how to build interpreter classes. Let’s get started now!