SPARK v.s. PLY

T

Tran Tuan Anh

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
 
D

Diez B. Roggisch

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.
 
A

Alan Kennedy

[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-sig/towards-standard.html

regards,
 
A

Andrew James

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
 
J

Josiah Carlson

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
 
D

Daniel Dittmar

Tran said:
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
 
V

Vinay Sajip

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
 
?

=?iso-8859-1?Q?Fran=E7ois?= Pinard

[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.
 
J

Jean Brouwers

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/developerworks/views/linux/articles.jsp?sort_ord
er=desc&expand=&sort_by=Date&show_abstract=true&view_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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top