Re: parsing C function declarations to generate code to serialize the formal arguments

"Alex McDonald" <alex_mcd@btopenworld.com>
15 Dec 2006 08:33:47 -0500

          From comp.compilers

Related articles
parsing C function declarations to generate code to serialize the form einatbg@zahav.net.il (Moshe Pfeffer) (2006-12-14)
Re: parsing C function declarations to generate code to serialize the eliotm@pacbell.net (Eliot Miranda) (2006-12-14)
Re: parsing C function declarations to generate code to serialize the DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-12-14)
Re: parsing C function declarations to generate code to serialize the alex_mcd@btopenworld.com (Alex McDonald) (2006-12-15)
Re: parsing C function declarations to generate code to serialize the idbaxter@semdesigns.com (Ira Baxter) (2006-12-24)
| List of all articles for this month |

From: "Alex McDonald" <alex_mcd@btopenworld.com>
Newsgroups: comp.compilers
Date: 15 Dec 2006 08:33:47 -0500
Organization: Compilers Central
References: 06-12-056
Keywords: C, parse, tools

Moshe Pfeffer wrote:


> I wish to take a C header file consisting of a list of function
> declarations, parse the function declaration to obtain a
> representation of the formal parameters from which to generate C
> code. Each argument must be processable as a tree, since it may be a
> struct, or pointer to a struct, with further structs/pointer to
> structs as it's members, or member's members, etc. If it is a simple
> type, the tree has 1 node, and depth 1. If it is a pointer to a simple
> type, the tree has 2 nodes and depth 2 (one for the pointer and one
> for the data pointed to).
>
> The result:


[...]


> [Generally speaking, you can't parse a C header file with anything less
> than a full C parser. If you have particular applications in mind, you
> might be able to cheat and get by with less. -John]


http://www.swig.org/ -- "SWIG is an interface compiler that connects
programs written in C and C++ with scripting languages such as Perl,
Python, Ruby, and Tcl. It works by taking the declarations found in
C/C++ header files and using them to generate the wrapper code that
scripting languages need to access the underlying C/C++ code. In
addition, SWIG provides a variety of customization features that let
you tailor the wrapping process to suit your application." It supports
ANSI C/C++.


SWIG outputing XML, which you can then transform, might be a solution;
http://www.rexx.com/~dkuhlman/swigxml.html.


--
Regards
Alex McDonald



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.