Open minux opened 9 years ago
Looks like is_funcdef() in parse.c makes some incorrect assumptions so it tries to parse this as a decl.
That's right. is_funcdef returns a wrong result for the input. Maybe we should stop making a guess before calling the parser but instead call the parser directly, because making a good guess is as hard as parsing input.
The look ahead is good for readability. If we don't have the ability to save and reset the parser at choice points on an error, decl and function parsing may need to be combined into an ugly mess.
It actually might not be too bad, I think it comes down to a check in read_decl like:
decl = read_decl()
if ( peek == '{' && ! first decl in list )
error("function cannot appear in decl list");
if (peek == '{') {
if (sclass == typdef)
error()
parse_body()
}
Edit: Yeah, this is what I am currently doing (my function is too big), but I don't handle old style arguments. https://github.com/andrewchambers/cc/blob/master/parse/parse.go#L547