Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to parse a list using pyparsing

Thread Tools

How to parse a list using pyparsing

Nitin Madnani
Posts: n/a
Hi Guys

I am using pyparsing to parse transformation rules for my natural
language processing application. The rules also have structure to
them, i.e., a rule might look like:

[ A [ B ] ] <--> [ C [ D ] ]

where A, B, C, D are nodes in the rule (although they are usually much
more complex than this)

I have figured out how to parse the nodes out of the rules and return
them like this:

[ [ A, B ], [ C, D ] ]

but I would like to return them in a list with the same hierarchical
structure as in the original rule, i.e., I would like to return:

[ [ A, [ B ] ] , [ C, [ D ] ] ]

I hope that makes sense. Any advice is much appreciated.
Thanks !
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Pyparsing performance boost using Python 2.6b1 Paul McGuire Python 2 06-20-2008 12:12 PM
Problem using Optional pyparsing Nathan Harmston Python 2 08-16-2007 02:51 PM
using pyparsing to extract METEO DATAS Python 0 05-04-2007 12:45 PM
How to parse a string like C program parse the command line string? C Programming 19 03-15-2005 07:41 PM