[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LPEG for C++
- From: David Given <dg@...>
- Date: Sun, 20 Sep 2009 08:23:56 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Wesley Smith wrote:
> Here's a start on a C parser. Mostly useful for lists of expression
> statements without things like structs, or branching/looping code:
I'm not fluent enough with LPEG to be able to tell at a glance whether
you've done it or not in this, but C/C++ is notoriously hard to parse
because the parse type of a symbol depends on the semantic type. In
other words, you have to actually *understand* a large amount of the C
before you can generate the parse tree.
Here's the canonical example:
T(*b)[4];
If T is a type name, this declares an array of function pointers, each
of which returns a T.
If T is not a type name, this calls a function called T with parameter
*b, and then dereferences the result.
Here's a lengthy discussion of Why C Grammar is Bad:
http://groups.google.com/group/comp.compilers/msg/c0797b5b668605b4
(And let's not even get started on C++ and the one-argument-constructor
problem...)
(Yes, I've been burnt by this several times in the past. Turns out that
writing a simple C mutator by parsing the C, modifying the AST and
writing it out again is actually deceptively difficult.)
- --
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ "People who think they know everything really annoy those of us who
│ know we don't." --- Bjarne Stroustrup
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iD8DBQFKtdiJf9E0noFvlzgRAnUtAJ9mOQc7gzacPxqpCDDqksN+qxc2iQCfehDa
WFI6KtF8cKfE27jce85H4rs=
=cH0W
-----END PGP SIGNATURE-----