ntt@dciem.UUCP (Mark Brader) (05/29/84)
Obviously, it's a religious issue. I learned ALGOL before C, and when I switched, the semicolons bothered me ... for about a week. I'd just like to point out that I've read that people make fewer mistakes involving semicolons in languages that use them C-style than ALGOL-style. Mark Brader
chris@umcp-cs.UUCP (05/31/84)
(Apply :-) to entire article) ... I'd just like to point out that I've read that people make fewer mistakes involving semicolons in languages that use them C-style than ALGOL-style. Perhaps it's because we're used to periods as sentence *terminators*, not *separators*. Just a thought (Of course, I don't want to start a debate on ``English-like'' languages. Blech, COBOL) Have you noticed that I've been using punctuation as sentence separators? Looks weird, I think -- In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690 UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland
alan@allegra.UUCP (Alan S. Driscoll) (05/31/84)
> (Apply :-) to entire article) > >> ... I'd just like to point out that I've read that people >> make fewer mistakes involving semicolons in languages that >> use them C-style than ALGOL-style. > > Perhaps it's because we're used to periods as sentence *terminators*, > not *separators*. Just a thought We use periods as terminators; we use semicolons as separators; [There, doesn't that look just as funny? :-) ] -- Alan S. Driscoll AT&T Bell Laboratories
phipps@fortune.UUCP (06/01/84)
For one reference, see John D. Gannon and J. J. Horning: "Language Design For Programming Reliability", *IEEE Transactions On Software Engineering*, vol. SE-1, num. 2, June 1975, p. 179 .. 191. The difference in the semicolon errors is "an order of magnitude", in favor of PL/I-style (C-style for C chauvinists who don't know that PL/I did it earlier) semicolon usage, as stated on page 189 of this paper. The paper discusses issues more meaty than semicolon placement, by the way. -- Clay Phipps -- {cbosgd decvax!decwrl!amd70 harpo hplabs!hpda ihnp4 sri-unix ucbvax!amd70} !fortune!phipps
mnc@hou2g.UUCP (#M.CONDICT) (06/08/84)
Not wishing to drag out a rather uninteresting discussion but unable to resist pontificating on language design matters, I submit the following on the semicolon controversy. It is true that semicolons are not, strictly speaking, statement terminators in C, because not all statements end with them. In fact, a quick look at the grammar in the C Reference Manual shows that only the following statements are terminated with semicolons: expression ; do statement while ( expression ) ; /* This one was new to me! */ return expr ; goto identifier ; continue ; break ; ; /* A null statement */ The rest, including for loops, while loops and compound statements are not. It is the presence of null statements that confuses the matter by making people think that while ( expr ) statement ; is one statement and is terminated with a semicolon, when in fact it is two statements -- a while loop followed by a null statement. Can anyone explain why, of all the loop statements, only do-while is terminated with semicolon? The required closing right-paren would seem sufficient for easy parsing. Michael Condict allegra!hou2g!mnc AT&T Bell Labs, Holmdel
kjm@ut-ngp.UUCP (06/09/84)
> ... Look at C's excuse for a grammar, and you will see massive > amounts of extranea in the production for "statement" whose sole > purpose in life is to make it possible to avoid having to type a > semicolon after the } in a compound statement. C therefore does > *NOT* use semicolon as a statement terminator, no matter how many > times you see people claim it does. > > I think that Huffman coding of tokens is not the best principle > for language design. > > James Jones OK, so C effectively has two kinds of statement terminator: ';' and '}'. So what? The two tokens terminate two different kinds of objects. BTW, if C had been done with Huffman coding, wouldn't reserved words be only one character long? :-) Ken "Smurf-shredder" Montgomery ...{ihnp4,seismo,ctvax}!ut-sally!ut-ngp!kjm
ron@BRL-TGR.ARPA (06/09/84)
From: Ron Natalie <ron@BRL-TGR.ARPA>
First of all. You are misleading people:
while(expr) statement ;
does have a null statement, nobody codes that way because
an example of that would be:
while(i=4) foo(i); ;
because expr = "i=4" and statement is "foo(i);". Note that for
the expression to be a statement it must contain it's own semicolon.
You don't do
while(i=4) {
foo(i);
goo(i);
};
either because blocks as statements don't need semicolon termination.
-Ron
andrew@orca.UUCP (Andrew Klossner) (06/09/84)
> Not wishing to drag out a rather uninteresting discussion but unable to > resist pontificating on language design matters, I submit the following > on the semicolon controversy. It is true that semicolons are not, strictly > speaking, statement terminators in C, because not all statements end with > them. In fact, a quick look at the grammar in the C Reference Manual shows > that only the following statements are terminated with semicolons: > > expression ; > do statement while ( expression ) ; /* This one was new to me! */ > return expr ; > goto identifier ; > continue ; > break ; > ; /* A null statement */ > > The rest, including for loops, while loops and compound statements are not. > It is the presence of null statements that confuses the matter by making > people think that > > while ( expr ) statement ; > > is one statement and is terminated with a semicolon, when in fact it is > two statements -- a while loop followed by a null statement. > > Can anyone explain why, of all the loop statements, only do-while is > terminated with semicolon? The required closing right-paren would seem > sufficient for easy parsing. You've become confused about the grammar. It isn't really true that the other loops may terminate with something other than semicolon or right-brace. Here are the other for loops, while loops, and compound statements: compound-statement if (expression) statement if (expression) statement else statement while (expression) statement for (expression-1-opt; expression-2-opt; expression-3-opt) statement switch (expression) statement case constant-expression: statement default: statement identifier: statement compound-statement: { declaration-list-opt statement-list-opt } Notice that, except for "compound-statement", all of these for loops, while loops, and compound statements end in "statement". Every statement-producing rule that doesn't end in "statement" ends in semicolon. Through the recursive nature of programming language grammars, this ensures that each statement construct will end in a single semicolon, unless it ends in compound-statement in which case it end in a right-brace. Consider the alternative, e.g., "if (expression) statement;". This would lead to statements such as if (a==0) b=5;; with mandated double semicolons, and the conventional if (a==0) b=5; would be a syntax error. -- Andrew Klossner (decvax!tektronix!orca!andrew) [UUCP] (orca!andrew.tektronix@rand-relay) [ARPA]
gwyn@BRL-VLD.ARPA (06/10/84)
From: Doug Gwyn (VLD/VMB) <gwyn@BRL-VLD.ARPA> Sorry, but while ( expr ) statement is not a C statement at all. Where did you get the idea that this is a complete statement? Does YOUR compiler accept this idea? etc.
gwyn@brl-vgr.UUCP (06/10/84)
But C reserved words ARE one character long, at last some of them: ? : { } , ;
ags@pucc-i (Seaman) (06/14/84)
> Sorry, but > while ( expr ) statement > is not a C statement at all. Where did you get the idea that this > is a complete statement? Does YOUR compiler accept this idea? etc. By gosh, he's right! According to K&R, p. 202, the correct form for a while statement is not while ( expr ) statement but while ( expression ) statement It certainly pays to read. :-) -- Dave Seaman "My hovercraft is full of eels." ..!pur-ee!pucc-i:ags
gwyn@brl-vgr.ARPA (Doug Gwyn ) (06/17/84)
Of course I was confused by the way the analysis was being phrased (as Ron@BRL-TGR nicely pointed out). If "statement" is given its normal meaning, as intended in the C language specification, then while ( expression) statement is correct syntax. I think this shows what confusion about statement terminators and statement separators can produce. Sorry I allowed myself to be confused by the bogus analysis I was responding to..