Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Choosing the right parser for parsing C headers

Reply
Thread Tools

Choosing the right parser for parsing C headers

 
 
John Machin
Guest
Posts: n/a
 
      02-08-2005

Jean de Largentaye wrote:
> Hi,
>
> I need to parse a subset of C (a header file), and generate some unit
> tests for the functions listed in it. I thus need to parse the code,
> then rewrite function calls with wrong parameters. What I call

"shaking
> the broken tree"


I was thinking "cdecl", and googling brought up this:

http://arrowtheory.com/software/python/

Another option, which I used recently when I had to parse a whole bunch
of Oracle 'create table' scripts [with semi-structured comments which
had to be mined for additional info]: write a recursive descent parser
-- but maybe the grammar of C function declarations is too complicated
for this.

HTH,
John

 
Reply With Quote
 
 
 
 
Caleb Hattingh
Guest
Posts: n/a
 
      02-09-2005
Jean, Paddy

I use "pym" to extract bits of pascal out of delphi code for documentation
purposes. You have to add some stuff to the delphi code (in your case, C
header), but these are added within comment blocks, and the interesting
thing is that you add python code(!) as a kind of dynamic markup which pym
executes while parsing the file.

In other words, you can write python code within a comment block in your
C-header to generate unit-tests into other files, and get that code
executed with pym.

Keep well
Caleb


On Tue, 08 Feb 2005 19:58:33 GMT, Paddy McCarthy <(E-Mail Removed)>
wrote:

> Jean de Largentaye wrote:
>> Hi,
>> I need to parse a subset of C (a header file), and generate some unit
>> tests for the functions listed in it. I thus need to parse the code,
>> then rewrite function calls with wrong parameters. What I call "shaking
>> the broken tree"
>> I chose to make my UT-generator in Python 2.4. However, I am now
>> encountering problems in choosing the right parser for the job. I
>> struggle in choosing between the inappropriate, the out-of-date, the
>> alpha, or the too-big-for-the task...

>
> Why not see if the output from a tags file generator such as ctags or
> etags will do what you want.
>
> I often find that some simpler tools do 95% of the work and it is easier
> to treat the other five percent as broken-input.
>
> try http://ctags.sourceforge.net/
>
>
> - Paddy.


 
Reply With Quote
 
 
 
Reply

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
advice on choosing right control Mark Siffer ASP .Net 1 06-17-2004 06:26 AM
Reading 'received' headers: Email Headers Parsing dont bother Python 0 03-03-2004 08:18 PM
Need help choosing the right router. Robert Le Feve Cisco 3 11-19-2003 02:31 AM
Re: Choosing the right training company Deane MCSE 0 09-05-2003 07:58 PM
Re: Choosing the right training company S. O'Brien MCSE 0 09-05-2003 01:58 PM



Advertisments