Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Abstract Syntax Tree for C programs Date: Wed, 29 May 2019 13:58:00 -0700 Organization: None to speak of Lines: 44 Message-ID: References: <17344bb7-9c96-47eb-b006-c6c2e2b8bc59@googlegroups.com> <97b08cce-ec5d-4052-9338-0026b5d449bf@googlegroups.com> <87sgt339na.fsf@bsb.me.uk> <80470a36-78de-417f-bc75-a7966c87b31e@googlegroups.com> <9cbcea67-85a8-4de3-ac01-04922ba5fc74@googlegroups.com> <87muj6lgco.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="c6c26aab05d6bfabe3d5296c6ba02671"; logging-data="23198"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UXFEkMeaIBdB2Lj9FMcgz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:s6F28mG9ZLdZPWb6i7prAwgBUik= sha1:sTOzG5VY8xmHLi5Y3COmSJl5VXE= Xref: csiph.com comp.lang.c:144122 Bart writes: > On 29/05/2019 14:44, David Brown wrote: >> On 29/05/2019 11:01, Keith Thompson wrote: >>> A note on the extra semicolon: In K&R1 (1978), the syntax for a >>> data-definition (a kind of external-definition) was: >>> >>> extern(opt) type-specifier(opt) init-declarator-list(opt) ; >>> static(opt) type-specifier(opt) init-declarator-list(opt) ; >>> >>> so a lone semicolon would have been (at least syntactically) valid. >>> That may be why gcc and some other compilers accept it by default. >>> >> >> Interesting point. Later C standards (I'm looking at C11) also allow >> the init-declarator-list to be optional, but you need at least a >> storage-class-specifier, a type-specifier, a type-qualifier, a >> function-specifier, or an alignment-specifier. But it is syntactically >> fine to write "static ;" or "extern ;". >> >> I guess it was simply easier to define a grammar that allowed such >> harmless oddities, than to add extra rules disallowing them. > > A grammar production for 'one or more of' is just as easy as 'zero or > more of'. Yes, but the syntax in K&R1 didn't define an "N or more of" sequence. It defined a sequence of three different items, each optional, followed by as semicolon. Changing the grammar to require at least one item would have been more difficult and would have make the grammar more difficult to read. Presumably neither `extern ;` nor `static ;` would be allowed. There could have been a semantic rule requiring at least one type-specifier or one init-declarator-list (in modern terms, a constraint), but Ritchie probably didn't feel it was worth the effort at the time. > Empty sequences can make sense for some things (parameter lists, the > contents of {...}) but not for declarations. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */