C Grammar for Parse::RecDescent

C Grammar for Parse::RecDescent

am 07.01.2008 06:19:00 von necnecnecnec

Hello,

I'm looking for a grammar to help with parsing C programs. Is there
something ready?
(I've seen in perlmonks some regular expression method, but it's a bit
weak to my needs).

Thanks,
Nec

Re: C Grammar for Parse::RecDescent

am 07.01.2008 07:23:13 von Florian Kaufmann

Thats what I have found when I googled for "c bnf":

Flo


http://c-faq.com/resources/grammars.html, which leads among others to
ftp://ftp.uu.net/usenet/net.sources/ansi.c.grammar.Z

http://lists.canonical.org/pipermail/kragen-hacks/1999-Octob er/000201.html

http://www.cs.man.ac.uk/~pjj/bnf/c_syntax.bnf

Re: C Grammar for Parse::RecDescent

am 07.01.2008 18:46:26 von Ted Zlatanov

On Sun, 6 Jan 2008 21:19:00 -0800 (PST) necnecnecnec@gmail.com wrote:

n> I'm looking for a grammar to help with parsing C programs. Is there
n> something ready? (I've seen in perlmonks some regular expression
n> method, but it's a bit weak to my needs).

AFAIK this is a hard problem that hasn't been solved yet. P::RD could
do it, in theory, but what I've seen are only partial implementations.
If you or anyone else have an actual functioning lexer and parser or the
equivalent P::RD grammar, I'd be very interested in taking a look. I've
wished for something like that myself but never had the time to work on
it.

Florian's answer is a good starting point, but actually implementing the
BNF is the hard part.

Ted