Path: utzoo!attcan!uunet!husc6!mailrus!uflorida!novavax!proxftl!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Re: ANSI grammar questions Message-ID: <179@twwells.uucp> Date: 16 Nov 88 08:48:19 GMT References: <7938@bloom-beacon.MIT.EDU> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 90 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <7938@bloom-beacon.MIT.EDU> chekmate@athena.mit.edu (Adam Kao) writes: : 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(); Right. This is intentional. Believe it or not, there are situations where this flexibility is useful. As is typical in C, there are lots of things that the language permits you to do, that could be restricted with little harm to the language's utility, and aren't. This is consistent with C's bias toward trusting the programmer. This also means that it is more obviously the programmer's responsibility to carefully use the facilities that C provides. (I was originally going to say "This also makes it the programmer's responsibility..." till it occured to me that some might interpret that to mean that other languages don't impose that responsibility. Utter nonsense, of course: some of the worst programs I have seen were written in Modula 2 and followed all the "structured programming" guidelines.) : Yes, I know, now you can't put them in any order, but who would write : "void static fn();" anyway? I might. Though I never have, I can imagine circumstances where doing it that way might be clearer than the other. : 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? There is also another factor you should consider: adding those lines to your grammar (and, by extension, lots of other lines for similar purposes), can make the resulting grammar tables *huge*. It just isn't worth it. Especially since, if you *must* do this, there is a better way: do it with attributes passed up the parse tree. : 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? The ... can also be used in the prototype with the definition of the function: void static fn(int c, ...) { } --- If you're going to write a C compiler, or a reasonable facsimile thereof, make it a *real* C compiler; don't add your stylistic preferences to it. If you do have style preferences that can be detected syntactically, have your lint detect them, but make it optional. You'll thank yourself the first time you have to deal with someone else's code. --- Bill {uunet|novavax}!proxftl!twwells!bill