[antlr-interest] PHP AST Grammar

Darien Hager darien.hager at etelos-inc.com
Tue Mar 11 11:40:52 PDT 2008


On 3/11/08, Adam Cooney <ad_cooney at hotmail.com> wrote:
>
> Hey,
> I've been searching for a grammar for PHP that can build ASTs and so far
> have come up with nothing for ANTLR (in fact, nothing at all related to
> PHP). However, I did find a program called PHC which contains a php grammar
> I am thinking of attempting to convert to ANTLR, but was wondering if anyone
> has attempted to build a PHP AST grammar before or has a PHP grammar.
>

Depending on what you're trying to do with your ASTs, I'd like to recommend
you at least take a look at PHP's built-in lexer/tokenizer extension. I've
found it useful for things like disallowing dangerous code in eval()
statements (don't ask, yes, eval() is actually evil() )

http://us.php.net/manual/en/ref.tokenizer.php

Mind you, this is only a tokenizer, but it means you don't need to
reimplement all the possible quoting, comments, whitespace, and HEREDOC
rules. There are some wrinkles (you need to do lookahead for a parenthesis
to figure out if something is a function call or not.)

You can't directly integrate it with ANTLR--that'd have to be some custom
project for a particular rntime...Hmmm... A custom token
stream in Java which can deserialize those tokens (e.g. from JSON) for
use with an ANTLR parser...

-- 
Darien Hager
Developer
Etelos, Inc.
darien at etelos.com

http://www.etelos.com
"Revolutionizing the way applications are developed, distributed and
consumed."

This e-mail message, including attachments, may contain confidential
information for the sole use of the intended recipient(s). If you are not
the intended recipient, then this is notice that any use, disclosure,
dissemination, distribution or copying is strictly prohibited. If you have
received this message in error please contact the sender by reply mail and
destroy all copies of the original message.

This e-mail message, including attachments, may contain confidential information 
for the sole use of the intended recipient(s). If you are not the intended recipient,
then this is notice that any use, disclosure, dissemination, distribution or copying is 
strictly prohibited.  If you have received this message in error please contact the 
sender by reply mail and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080311/e501bc47/attachment.html 


More information about the antlr-interest mailing list