lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

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:


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:

(And let's not even get started on C++ and the one-argument-constructor

(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.)

- --
┌─── ───── ─────
│ "People who think they know everything really annoy those of us who
│ know we don't." --- Bjarne Stroustrup
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla -