Goldie Parsing System v0.4 Released - Now for D2
Nick Sabalausky
a at a.a
Fri Apr 15 17:25:54 PDT 2011
Andrej Mitrovic Wrote:
> What I meant was that code like this will throw if MyType isn't
> defined anywhere:
>
> int main(int x)
> {
> MyType var;
> }
>
> goldie.exception.UnexpectedTokenException at src\goldie\exception.d(35):
> test.c(3:12): Unexpected Id: 'var'
>
> It looks like valid C /syntax/, except that MyType isn't defined. But
> this will work:
> struct MyType {
> int field;
> };
> int main(int x)
> {
> struct MyType var;
> }
>
> So either Goldie or ParseAnything needs to have all types defined.
> Maybe this is obvious, but I wouldn't know since I've never used a
> parser before. :p
>
> Oddly enough, this one will throw:
> typedef struct {
> int field;
> } MyType;
> int main(int x)
> {
> MyType var;
> }
>
> goldie.exception.UnexpectedTokenException at src\goldie\exception.d(35):
> test.c(7:12): Unexpected Id: 'var'
>
> This one will throw as well:
> struct SomeStruct {
> int field;
> };
> typedef struct SomeStruct MyType;
> int main(int x)
> {
> MyType var;
> }
>
> goldie.exception.UnexpectedTokenException at src\goldie\exception.d(35):
> test.c(13:12): Unexpected Id: 'myvar'
>
> Isn't typedef a part of ANSI C?
I'm not at my computer right now, so I can't check, but it sounds like the grammar follows the really old C-style of requiring structs to be declared with "struct StructName varName". Apperently it doesn't take into account the possibility of typedefs being used to eliminate that. When I get home, I'll check, I think it may be an easy change to the grammar.
More information about the Digitalmars-d-announce
mailing list