[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua parser generator or c-grammar parser
- From: Dave Dodge <dododge@...>
- Date: Mon, 25 Jul 2005 07:17:53 -0400
On Mon, Jul 25, 2005 at 10:59:24AM +0700, Antero Vipunen wrote:
> Well, even simple C-grammar parser would be enough for my needs.(I
> mean it should parse C files, and be written in lua)
Note that the C grammar is a bit tricky because of the preprocessor.
Consider what happens if the code has macros, stringization, token
pasting, or #if statements with mathematical expressions. If you
implement your own preprocessor, you also have the issue that
conditional code might expect compiler-specific predefined values.
If you want to follow the standard completely, you also run into
unusual things like:
- Trigraphs
- Alternate punctuator spellings such as <: and %:%:
- The fact that string-literal concatenation is assumed to take place
before tokenization
- Preprocessor tokenization is context-sensitive. "yes\no" tokenizes
as a header-name when it appears on an #include line but as a
string-literal elsewhere. The rules for handling the backslash
are different in those two contexts.
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.
-Dave Dodge