By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,255 Members | 1,701 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,255 IT Pros & Developers. It's quick & easy.

Simple parser in PHP?

P: n/a
Well, I'm coming to the end of a large and exhausting project, done in my
new favorite language PHP, and its time for a diversion.

I'm wondering if anyone has experience with writing simple parsers. I've
never done it myself, but I know they are not as mysterious as they may
seem, it's a matter of finding the tools.

The idea is to take something like CSS format, except that it allows
nesting, and turn it into associative arrays, such as:

anykey {
property: value;
property: value;
nestedkey {
property: value;
property: value;
}
}

could be processed by a command like:

<?php
$parsed = ParseMyFile(...)
?>

and $parsed would hold the same as if we'd done this:

$arr = array(
anykey("property"=>"value",...

This would be moderately easy to do by hand as an ad-hoc diversion, but
would get out of hand if we got carried away and began adding to the
syntax.

So anybody know how to generate a parser in PHP? Any idea where I might
start?

P.S., all recommendations to use XML go to /dev/null, no hard feelings.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Fri, 25 Mar 2005 19:54:06 -0500, Kenneth Downs
<kn**************@see.sigblock> wrote:
Well, I'm coming to the end of a large and exhausting project, done in my
new favorite language PHP, and its time for a diversion.

I'm wondering if anyone has experience with writing simple parsers. I've
never done it myself, but I know they are not as mysterious as they may
seem, it's a matter of finding the tools.

The idea is to take something like CSS format, except that it allows
nesting, and turn it into associative arrays, such as:

anykey {
property: value;
property: value;
nestedkey {
property: value;
property: value;
}
}

So anybody know how to generate a parser in PHP? Any idea where I might
start?


Parser generators still seem to be very thin on the ground for PHP. Last time
this came up I think I recommended calling out to Perl which has a million and
one parser classes, for example
http://search.cpan.org/~dconway/Pars...RecDescent.pod

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
Kenneth Downs wrote:
<snip>
I'm wondering if anyone has experience with writing simple parsers. I've never done it myself, but I know they are not as mysterious as they may seem, it's a matter of finding the tools.

The idea is to take something like CSS format,

<snip>

If it is to parse the PHP codes, you may use tokenizer functions
<http://in.php.net/tokenizer>

To parse CSS, the quick Google search yields results
<http://www.google.com/search?q=php+css+parser>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #3

P: n/a
Andy Hassall wrote:

So anybody know how to generate a parser in PHP? Any idea where I might
start?
Parser generators still seem to be very thin on the ground for PHP. Last
time
this came up I think I recommended calling out to Perl which has a million
and one parser classes, for example

http://search.cpan.org/~dconway/Pars...RecDescent.pod


Thanks. Perl makes sense.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.