473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

The Interpreter Pattern in PHP 5

Last week I continued my series of design patterns examples using PHP
5 with the Bridge Pattern, Flyweight Pattern, and Proxy Pattern. Here
now is my 20th PHP 5 design pattern example, the Interpreter Pattern.

http://www.fluffycat.com/PHP-Design-...s/Interpreter/

In the Interpreter Design Pattern you define a language syntax, and
parse requests that use that syntax, and call the correct classes and
methods to handle the request.

An interesting pattern, although I don't think I've used it much in
systems I've worked on. It is probably indespensible if you are
writing a compiler.

Aug 27 '06 #1
1 2492
And now, the State Pattern.

http://www.fluffycat.com/PHP-Design-Patterns/State/

In the state pattern a class will change it's behavior based on
circumstances. In my example a subclass of a specific interface may
actually switch the class being used to another subclass of the same
interface.

When I first drew up this example yesterday evening, based on one I did
a few years back in Java, I was pretty enthusiastic about it. Now, I'm
not sure I like it 100%, and may still tinker with it. I guess this
proves that these are perhaps "living examples", just my best try at an
example of a given pattern, are not set in stone, and may change. I
also have a comments section with each pattern, so please feel free to
point out flaws or applaud any examples if you like.


lt*****@fluffycat.com wrote:
Last week I continued my series of design patterns examples using PHP
5 with the Bridge Pattern, Flyweight Pattern, and Proxy Pattern. Here
now is my 20th PHP 5 design pattern example, the Interpreter Pattern.

http://www.fluffycat.com/PHP-Design-...s/Interpreter/

In the Interpreter Design Pattern you define a language syntax, and
parse requests that use that syntax, and call the correct classes and
methods to handle the request.

An interesting pattern, although I don't think I've used it much in
systems I've worked on. It is probably indespensible if you are
writing a compiler.
Aug 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hokieghal99 | last post by:
This may not be possible, but I thought I'd ask anyway. Could I get the below code to run on a Python server where other machines would connect to it (say thru the Web) and get details of *their*...
12
by: Anon | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all I am a beginner teaching myself python, and I am enjoying it immensely :) As a language it is great, I real treat to study, I actually...
1
by: Donnie Leen | last post by:
I wrote a program embbed boost.python, each thread running a sub-interpreter, i made a module implement by boost.python, and i wish this module imported in each sub-interpreter, i find that the...
12
by: Rex Eastbourne | last post by:
Hi, I'm interested in running a Python interpreter in Emacs. I have Python extensions for Emacs, and my python menu lists "C-c !" as the command to run the interpreter. Yet when I run it I get...
6
by: gr | last post by:
hi.. I must implement an interpreter in C programming language that will get the source code of a program in text file format and execute it. but i don't know C language enough to write this...
0
by: tomerdr | last post by:
Hi, I implemented the "Interpreter" pattern for a simple calculator whicu support +\*- I want to ask what is a good way to construct the expression tree? Thanks in advance.
3
by: Robin Becker | last post by:
As part of some django usage I need to get some ReportLab C extensions into a state where they can be safely used with mod_python. Unfortunately we have C code that seems incompatible with...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
40
by: castironpi | last post by:
I'm curious about some of the details of the internals of the Python interpreter: I understand C from a hardware perspective. x= y+ 1; Move value from place y into a register Add 1 to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.