473,890 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2519
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*****@fluffyc at.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
1907
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* system instead of the system details of the machine that the interpreter is running on? Any ideas? Thanks!!! import os import socket
12
2421
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 find it fun to study the language heh Anyways to the point of my post.....
1
2918
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 module could initialize only once, otherwise the boost.python will throw a exception said that something already registered; second conversion method ignored. So I try another way, initialize and import the module in one interpreter such as the main...
12
12295
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 the message "Spawning Child Process: invalid argument." What do I need to do/download to fix this? I read in a post in this group from a while back where someone had the following lines in his .emacs file:
6
5520
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 interpreter. so I need this interpreter code that is written with C language.(or it can be C++) I searched this codes in google and some websites, but codes which I found are useless.. if you can help me, you gladden me.
0
1674
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
1578
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 mod_python and I'm looking for ways to improve the situation. Basically the main things that are wrong are all privately cached copies of python variables. This sample code
13
12816
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 scripting language that makes writing automated tests simpler. Really, I'm looking to kind of abstract the power of the C# language into a simpler language that's easier to learn. The script files would be interpreted by a script interpreter...
40
2398
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 value in the register Move the addition's result to place x
0
9976
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9815
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9618
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7160
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6035
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4665
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4259
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.