Home arrow PHP arrow Building Interpreter Classes with PHP 5

Building Interpreter Classes with PHP 5

If you have ever written an application that primarily parses commands -- and who hasn't? -- keep reading. As is often the case, pattern-based programming makes this task easier. In this first part of a three-part article series, you'll learn the basic concepts surrounding the Interpreter pattern, with plenty of hands-on examples.

  1. Building Interpreter Classes with PHP 5
  2. The basics of implementing the interpreter pattern
  3. Parsing predefined commands
  4. Seeing the interpreter pattern in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 8
April 02, 2007

print this article




In the vast and fascinating terrain of web development, working with applications whose primary task is to parse commands happens very frequently. Only think about this concept for a moment, and you'll quickly realize that every day you're dealing with some kind of parser, ranging from your own browser that interprets (X)HTML, CSS, XML, JavaScript code, etc. to your loyal PHP module that parses your neatly-crafted web applications.

Actually, the concept of a parser is VERY old, but the impressive advance of technology has brought it to us in a variety of applications that sometimes exceed our imagination. However, it's not my intention to discuss here the influence of parsers on mankind, since it'd be rather irrelevant to the purposes of this article, and possibly it'd also be boring to you.

Instead, I'd like analyze this interesting topic from a practical point of view, and ask you the following question: how many times have you found yourself developing a web application that was intended to interpret a certain number of predefined commands? Certainly, the answer might be dozens, even hundreds of times.

But, what if I extend this concept one step further and tell you that it's possible to apply it in the context of pattern-based programming with PHP? Yes, you guessed right. Among the numerous design patterns available out there, there's one called "Interpreter." As its name suggests, it has the capacity to parse specific commands to perform a set of predefined tasks.

Does this sound a bit confusing? Fear not, because building an interpreter class with PHP is a no-brainer process that can be achieved with only minor efforts. In plain terms, when the interpreter pattern is applied, on one hand there's a class that defines a set of commands that will be parsed, while on the other hand, there are some additional classes that are responsible for sending these commands to the interpreter. Now, the concept sounds much simpler, right?

Naturally, if you're anything like me and want to see different hands-on examples on how to create interpreter classes with PHP, then I've got good news for you. In this series, which is comprised of three articles, I'll provide you with numerous code samples showing how to implement this useful pattern, ranging from building a simple application for managing user information to creating a decent blogger.

Now, having introduced the subject of this series, let's start learning together how to build interpreter classes with PHP 5. It's going to be a truly instructive experience!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: