The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

PHP Internals

I'm interested in learning how the PHP parser works.

Can anyone suggest where I should begin ?
Lazy Web
Friday, August 11, 2006
 
 
Complete source code is available free at http://www.php.net/downloads.php

Read the code, then ask your questions at the "php internals" mailing list, also at php.net.
Flow
Saturday, August 12, 2006
 
 
Hello.

First of all, there is grammar description of PHP language.
This description then compilated in C code using Bison:
http://www.gnu.org/software/bison/
"Bison is a general-purpose parser generator that converts an annotated context-free grammar into an LALR(1) or GLR parser for that grammar."

Learn more about Bison, and you will know how PHP parser works.

Grammar description of PHP you can find in PHP sources.  php5-0.0/Zend/zend_language_parser.y

As a start you can look at php.ini file parser. It is implemented the same way as PHP language parser. zend_ini_parser.y

I hope this helps.
Pavel Vasilevich Send private email
Saturday, August 12, 2006
 
 
See this documentation http://derickrethans.nl/files/php-ticks-ffm2005.pdf

From my own experience - the PHP parser uses Flex + Bison to generate a lexer+parser in C. The Flex and Bison definitions are pretty much standard. So if you are familiar with these tools, just grab the latest PHP snapshot from snaps.php.net and read  Zend/zend_language_scanner.l and Zend/zend_language_parser.y

The only quirk of the scanner is that it uses a custom skeleton file to make the scanner re-entrant, but this does not make the scanner harder to understand.
Vesselin Atanasov Send private email
Saturday, August 12, 2006
 
 
Thankyou Pavel and Vesselin for your comments.

The slides by Derick Rethans seem especially useful. They give a nice and simple overview of how PHP works.
Lazy Web
Saturday, August 12, 2006
 
 
This book may be a good place to start. Understanding how to extend it can be a good way to learn how it was written.

http://www.amazon.com/exec/obidos/ASIN/067232704X/libssh2projec-20/104-5944824-9887907?creative=327641&camp=14573&adid=1VVXKFAQ85YKCKPZ4YMB&link_code=as1
Jeff Send private email
Saturday, August 12, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz