473,411 Members | 2,186 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,411 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 2170
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.