ANSI grammar questions

Adam Kao chekmate at athena.mit.edu
Sun Nov 13 15:50:00 AEST 1988


I've been playing around with the (presumably) most recent ANSI C grammar.
Right now I'm just building a parse tree, eventually I'll do interesting
things with the tree.  I've got a couple of questions.
First, about declaration specifiers:

declaration_specifiers
	: storage_class_specifier
	| storage_class_specifier declaration_specifiers
	| type_specifier
	| type_specifier declaration_specifiers
	| type_qualifier
	| type_qualifier declaration_specifiers
	;

So you can stack any number of storage_class_spec, type_spec, and type_qual
in front of your declaration, in any order?  Things like:

void static fn();

and

void static extern int auto volatile fn();

With my C, the first compiles, while the second won't compile and won't
pass lint (rightly so!).  But both slide through the grammar fine.  Why?
Why didn't ANSI do this:

declaration_specifiers
	: storage_class_specifier
	| storage_class_specifier type_specifier
	| storage_clase_specifier type_qualifier
	| storage_class_specifier type_specifier type_qualifier
	| type_specifier
	| type_specifier type_qualifier
	| type_qualifier
	;

Yes, I know, now you can't put them in any order, but who would write
"void static fn();" anyway?  And if it's that important, another eight
lines will do it.  I'm considering using this specification for my parser.
Technically I would then be parsing a subset of ANSI, but who cares?
Should I?

Second, I've never seen the ellipsis ("...") before.  (Guess it's time to
buy K&R 2nd ed.)  As far as I can tell, the only uses for it are:

void static fn(int c, ...);

or

void static a (n, fn)
     int n;
     void fn(int c, ...);
{
	:
	:

Are these in fact the intended uses?  Are there any other uses?
Unfortunately, my C rejects both of these with "parameters only legal in
function definition" and "syntax error".  (Guess it's time to buy a new C.)

Thanks mulchy,
Adam

"Wherever you grow, there you are."
	Buckaroo Bonsai



More information about the Comp.lang.c mailing list