473,396 Members | 2,059 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,396 software developers and data experts.

SPARK v.s. PLY

Hi all,

I am searching for a suitable parsing tool to parse C++ for a research
project.
Actually I am parsing SystemC, it is a C++ lib with some macros, hence
I need to modify the grammar a little bit to handle some new keywords.

I need to construct the Control Flow Graph and play around with it a
bit.
So far, I have found SPARK and PLY that seem to be suitable to my
task. Other packages are either not so well established or not so well
tested and documented. (Please correct me if I am wrong).

If you know the parsing stuff well, could you briefly tell me the
pros. and cons. of those packages? (or some others you find good too)

Thanks a lot!
Tuan-Anh
Jul 18 '05 #1
9 3499
> If you know the parsing stuff well, could you briefly tell me the
pros. and cons. of those packages? (or some others you find good too)


I use spark and am very satisfied. Its usage is quite natural, and the power
of the earley parsing method ensures the grammars can be easy to write and
understand (close to bnf), as you don't have to care about left-factoring
and the like. In badly designed grammars, it can get quadratic (or even
worse I think, but I'm to lazy now to think about that thorougly..) in
runtime - but I never expirienced any real trouble with that. The
algorithms that afterwards run on the AST are usually complex themselves,
shadowing the parsing complexity. And as I said - only ambigue grammars
produce that overhead at all.

I can't say anything about other parsers though - didn't use them. At least
not in python.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
[Tran Tuan Anh]
I am searching for a suitable parsing tool to parse C++ for a research
project.
and
If you know the parsing stuff well, could you briefly tell me the
pros. and cons. of those packages? (or some others you find good too)


You might find Martin von Loewis paper "Towards a Standard Parser
Generator" useful. It discusses the pros and cons of multiple python
parser frameworks, in the concrete context of implementing xpath
expression parsing. It discusses SPARK, but not PLY.

http://www.python.org/sigs/parser-si...-standard.html

regards,

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
Jul 18 '05 #3
Alan,
You might also want to have a look at TPG (Toy Parser Generator):
http://christophe.delord.free.fr/en/tpg

The documentation is pretty good, feature list extensive and though
there aren't too many examples and you'll have to write your own
grammar, it might be worth trying.

I'm working on a small language implementation at the moment and have
found TPG to be pretty easy to use (but fairly difficult to bugfix)

Regards,
Andrew

Jul 18 '05 #4

an***@hotmail.com (Tran Tuan Anh) wrote:

Hi all,

I am searching for a suitable parsing tool to parse C++ for a research
project.
Actually I am parsing SystemC, it is a C++ lib with some macros, hence
I need to modify the grammar a little bit to handle some new keywords.

I need to construct the Control Flow Graph and play around with it a
bit.
So far, I have found SPARK and PLY that seem to be suitable to my
task. Other packages are either not so well established or not so well
tested and documented. (Please correct me if I am wrong).

If you know the parsing stuff well, could you briefly tell me the
pros. and cons. of those packages? (or some others you find good too)

I've recently found myself in love with DParser. I had planned on
writing my own parser for a particular little query language until I
happened upon it, and within 15 minutes, had a parser that was exactly
what I wanted (variable lengthed list support, recursive rules, etc.).

I've not really used SPARC, TPG or PLY, so can't comment on them.

- Josiah

Jul 18 '05 #5
Tran Tuan Anh wrote:
I am searching for a suitable parsing tool to parse C++ for a research
project.
Actually I am parsing SystemC, it is a C++ lib with some macros, hence
I need to modify the grammar a little bit to handle some new keywords.


OpenC++ (http://opencxx.sourceforge.net/) is not written in Python, but
it knows probably more about C++ than any simple parser generator.

Daniel
Jul 18 '05 #6
SPARK and PLY are similar. I happened upon PLY first, and it worked
well for me. I'm not sure that either SPARK or PLY is up to parsing
full-blown C++, though. (They may be fine with a subset. I used PLY
for a little domain-specific language, and found for the most part
that it worked as advertised.)

Best of luck,

Vinay Sajip
Jul 18 '05 #7
Anyone has used ANTLR?

Daniel Dittmar <da************@sap.corp> wrote in message news:<cn**********@news.sap-ag.de>...
Tran Tuan Anh wrote:
I am searching for a suitable parsing tool to parse C++ for a research
project.
Actually I am parsing SystemC, it is a C++ lib with some macros, hence
I need to modify the grammar a little bit to handle some new keywords.


OpenC++ (http://opencxx.sourceforge.net/) is not written in Python, but
it knows probably more about C++ than any simple parser generator.

Daniel

Jul 18 '05 #8
[Vinay Sajip]
SPARK and PLY are similar.


I used both in various projects. Very shortly said, I found PLY to be
faster than SPARK but more demanding/restrictive on the grammar design.
PLY has a few conveniences (like detection of duplicated methods in
classes), while SPARK is more on the side of Pythonesque elegance.

As I like ease and beauty, I think I still prefer SPARK overall :-).

In many cases, my input files could be designed so to be easily broken
up in chunks by other means, and then parsed one chunk at a time; this
simple trick let me recover enough speed from SPARK so it is not an
annoyance in practice.

--
François Pinard http://pinard.progiciels-bpi.ca
Jul 18 '05 #9

Not ANTLR, but we do use SimpleParse/mxTextTools. For an example, see

<http://www.vrplumber.com/programming/simpleparse/simpleparse.html>

and

<http://www-106.ibm.com/developerworks/library/l-simple.html>
Also, check other web pages by David Mertz on "Text Processing in
Python"

<http://www-106.ibm.com/developerwork...s.jsp?sort_ord
er=desc&expand=&sort_by=Date&show_abstract=true&vi ew_by=Search&search_by
=charming+python%3A>

His book with that same title is highly recommended reading

<http://gnosis.cx/TPiP/>

/Jean Brouwers
ProphICy Semiconductor, Inc.

In article <ed**************************@posting.google.com >, Tran Tuan
Anh <an***@hotmail.com> wrote:
Anyone has used ANTLR?

Daniel Dittmar <da************@sap.corp> wrote in message
news:<cn**********@news.sap-ag.de>...
Tran Tuan Anh wrote:
I am searching for a suitable parsing tool to parse C++ for a research
project.
Actually I am parsing SystemC, it is a C++ lib with some macros, hence
I need to modify the grammar a little bit to handle some new keywords.


OpenC++ (http://opencxx.sourceforge.net/) is not written in Python, but
it knows probably more about C++ than any simple parser generator.

Daniel

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Magnus Lie Hetland | last post by:
I'm working on a project where I have to create parsers on the fly, based on input to my program. I think Spark seems like a good candidate for the parser generation part, but it seems very geared...
1
by: Diez B. Roggisch | last post by:
Hi, I've got to create some spark-based parsers during runtime. For people not familiar with spark, a parser looks like this: class MixFixParser(spark.GenericParser): def __init__(self,...
0
by: pathisunil | last post by:
Dear All I have an xmldocument which is as formed below. It is a bit of loopy in nature. can anyone kindly let me know how can i write a xslt which would take a parameter which is an attribute...
13
by: JAMESICUS | last post by:
Refer to: http://news.com.com/2100-1023-5079580.html James Pickering Pickering Pages http://www.jp29.org/
0
by: Sébastien Boisgérault | last post by:
Hi, Has anybody already implemented a full ANSI C parser with John Aycock's spark module ? (spark : http://pages.cpsc.ucalgary.ca/~aycock/spark/) Cheers, SB
0
by: pathisunil | last post by:
Dear All I have an xmldocument which is as formed below. It is a bit of loopy in nature. can anyone kindly let me know how can i write a xslt which would take a parameter which is an...
4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
1
by: Mr Shore | last post by:
hi,every buddy I've now installed a jabber server,right it's ejabberd mentioned above and 2 jabber client,right again it's spark and psi and I can connect to jabber server by spark but failed by...
2
by: Jeff Louie | last post by:
I stumbled upon an amazing deal if you want to try your hand at Windows CE embedded programming using C#. It is called the SPARK program at: ...
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: 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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.