lua-users home
lua-l archive

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


On Mon, Jul 25, 2005 at 06:51:39PM +0700, Antero Vipunen wrote:
> Dave Dodge wrote:
> In general, I don't need `understanding-parser'. I need `silly-parser' 
> that will only build syntax trees for me, so I can do some code
> preprocessing.

A starting point would be the C99 draft (since it's free):

  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/

"Annex A" contains the C grammar in a notation that is almost
trivially converted into something that bison/yacc could understand.
There will be some shift/reduce conflicts, though.  If you cut some
corners instead of doing a complete implementation, it shouldn't take
too long to throw something together.

You may find that the C syntax tree is a little bit unusual.  The
order of operations in an expression comes from having a very deep
grammar instead of using explicit precedence rules.  This leads to
things such as:

  a == b
  a || b
  (int)a

all being considered 'assignment-expr' by the grammar in the Standard
even though there is no assignment involved.

> >I only mention this stuff because I was working on a C parser (sorry,
> >not in Lua) in recent weeks and ran into all of this myself.
>
> Can you share with me your code?

Sorry, no.

                                                  -Dave Dodge