473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Simple parser in PHP?

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
3 2169
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Paulo Pinto | last post by:
Hi, does anyone know of a Python package that is able to load XML like the XML::Simple Perl package does? For those that don't know it, this package maps the XML file to a dictionary.
4
by: Leif K-Brooks | last post by:
I'm writing a site with mod_python which will have, among other things, forums. I want to allow users to use some HTML (<em>, <strong>, <p>, etc.) on the forums, but I don't want to allow bad...
8
by: Dan | last post by:
Using XML::Simple in perl is extreemly slow to parse big XML files (can be up to 250M, taking ~1h). How can I increase my performance / reduce my memory usage? Is SAX the way forward?
4
by: Greg B | last post by:
Well since getopt() doesn't seem to be compatible with Windows, and the free implementation of it for Windows that I found still had some annoying restrictions, I thought I'd whip up a simple...
1
by: steve smith | last post by:
Hi I have just downloaded the Borland C# Builder and the Micorsoft ..Net framework SDK v1.1 from the borland webist, and i am trying to get a simple program to run, however I keep getting errors,...
26
by: jacob navia | last post by:
Summary: I have changed (as proposed by Chuck) the code to use isalpha() instead of (c>='a' && c <= 'z') etc. I agree that EBCDIC exists :-) I eliminated the goto statement, obviously it is...
4
by: =?Utf-8?B?SmFu?= | last post by:
In my application the user can configure automation-scripts by inserting different "actions" into a "procedure". These different procedure- and action-objects are all translated into C# code before...
11
by: Stef Mientki | last post by:
hello, I need to translate the following string a = '(0, 0, 0, 255), (192, 192, 192, 255), True, 8' into the following list or tuple b = Is there a simple way to to this. (Not needed...
7
by: bvdp | last post by:
Is there a simple/safe expression evaluator I can use in a python program. I just want to pass along a string in the form "1 + 44 / 3" or perhaps "1 + (-4.3*5)" and get a numeric result. I can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.