This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C parser modification & questions


Nikola Ikonic wrote:
Hello,

I am working on a modification of C parser and I need some help since
I am having difficulties understanding some issues (I am complete
newbie on GCC). Long story short, I am trying to add a new attribute
to function types (similar to "inline", for example). Let's say that
this new keyword is _Something.
So, my new parser should be able to parse c function declared/defined like this:

_Something int Function_Name(unsigned a, int b);


I would suggest using GCC attributes for that. So you would code instead

int Function_Name(unsigned a, int b) __attribute__((YourAttribute));

See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
Of course, you could provide your headerfile which would

#define _Something __attribute__((YourAttribute))

So your user code could be

int Function_Name(unsigned a, int b) _Something;

The big advantages of attributes are:

1. You don't have to hack the GCC parser.

2. People already should be familiar with the notion of attributes and their syntax.

3. There is already a lot of support for attributes inside GCC.

BTW you don't even have to hack GCC 4.5 for your purposes. You could code a plugin for GCC 4.5 (to be released soon, and snapshots are already available thru SVN or FTP), and your plugin (which should be GPL compatible) would accept that extra attribute and handle it appropriately! You could even code your plugin using MELT (a high-level lisp-like language with pattern-matching, objects, functional values, ...).

So my advice is to not touch at all the C parser, and use the existing infrastructure. BTW, attributes are also parsed by the C++ parser!

The big issue when hacking your own variant of the GCC parser is all the work required just to follow GCC's evolution (which is always a big lot of work, even within plugins).

Regards.

PS. For people interested, I am also begin to add an alternative infix syntax to MELT. This only for people allergical to lot of insipid stupid parenthesis syntax.

--
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]