PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Jul 07, 2020 12:48 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sat Feb 15, 2014 5:33 am 
Offline
The Ninja Space Mod
User avatar

Joined: Fri Aug 05, 2005 1:53 pm
Posts: 6424
Location: Paradise, CA
I have been reading the gang of four book as well as PHP: Objects, Patterns, and Practice. Both of them have chapters devoted to the Interpreter Pattern. The PHP book even has an appendix with a sample parser with an impressive amount of example code to help understand how and why the interpreter pattern is used. But for whatever reason, even with all that help, I can't seem to wrap my head around this pattern. I know this is a really vague question, and I apologize for that, but I'm just basically wondering if anybody can help me understand this pattern and how, exactly, it works. I am having trouble figuring out what problem it solves. Because according to the PHP book, at least what I understand of it, the interpreter doesn't necessarily incorporate a parser. The parser seems to be out of the scope of the actual pattern. So what IS the interpreter pattern? Can anybody point me in the right direction? What am I missing?


Top
 Profile  
 
PostPosted: Sat Feb 15, 2014 7:29 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA


Top
 Profile  
 
PostPosted: Mon Feb 17, 2014 4:15 pm 
Offline
The Ninja Space Mod
User avatar

Joined: Fri Aug 05, 2005 1:53 pm
Posts: 6424
Location: Paradise, CA
I think that the interpreter pattern is more than I need then. I'm simply needing a parser. The file I am trying to parse is not complicated enough to require the interpreter pattern. It doesn't have variables or operators or anything like that. It just has a grammar of sorts.


Top
 Profile  
 
PostPosted: Mon Feb 17, 2014 7:23 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
You might need a bit more than a parser. Technically speaking, a parser is what turns a sequence of characters into specific tokens. Like in PHP, "class" becomes T_CLASS. Once you get a stream of tokens the lexer kicks in and turns them into something you can work with: T_CLASS("class") T_STRING("c") "{" indicates the class definition of "c".
A full Interpreter could be too much for sure, but you'll probably still want the structuring part of it.


Top
 Profile  
 
PostPosted: Tue Feb 18, 2014 12:44 am 
Offline
The Ninja Space Mod
User avatar

Joined: Fri Aug 05, 2005 1:53 pm
Posts: 6424
Location: Paradise, CA
Oh... I thought it was the other way around. I need to rename my classes then because I have my lexer converting the text into tokens and the parser making sense of them.


Top
 Profile  
 
PostPosted: Tue Feb 18, 2014 3:41 am 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine


Top
 Profile  
 
PostPosted: Tue Feb 18, 2014 4:26 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group