larmel / lacc

A simple, self-hosting C compiler
MIT License
915 stars 66 forks source link

Tricky abstract function declarator cases #13

Closed michaelforney closed 5 years ago

michaelforney commented 5 years ago

Some interesting examples

typedef int x;
void f1(int(x));    // same as void f(int (*)(int))
void f2(int(y));    // same as void f(int)
void f3(int((*)));  // same as void f(int *)
void f4(int((*x))); // same as void f(int *)
void f5(int((x)));  // same as void f(int (*)(int))
void f6(int(int));  // same as void f(int (*)(int))

It looks like lacc is handling all but f1, f5, and f6.

This is a bit tricky, but I think it can be done by checking the token after the opening (. If it is a *, (, or an identifier that is a typename, it is just a parenthesized declarator or abstract-declarator. Otherwise, it begins the parameter-type-list of an abstract function declarator.

larmel commented 5 years ago

Thanks again for reporting, appreciate the detailed info and test cases. I think your suggestion about checking the next token is correct, and that is what I ended up implementing. Fixed in dcc700fe.