Liste des Groupes | Revenir à cl c |
Bart <bc@freeuk.com> wrote:A do-loop ends with:On 07/12/2024 11:34, Janis Papanagnou wrote:Technically, 'do' loop ends in a semicolon.On 06.12.2024 02:20, Bart wrote:>>I used to be puzzled by this too: 'while' can both start a while>
statement, and it can delimit a do-while statement. How is that possible?
A keyword (like 'while') is just a lexical token that can be used in
different syntactical contexts.
Is it common to both start and end a statememt with the same keyword?
Concerning "start and end a statememt with the same keyword",I think it's uncommon. In Algol68 you both start and end a comment with 'comment', or 'co' or '#', which is a spectacularly bad idea. It's easy to get them out of step. Or if looking at an isolated delimiter, you can't tell, if in the middle of code, whether it is the beginning or end of the comment.
this is clearly common when statement consist of a single
symbol, like empty statement in many langages, including C and
Algol68
I think it was already noted that this is not a valid C statement.That's still pretty confusing! In languages where 'while' doesn't do two jobs, you see 'while' and know instantly what it denotes. With C, you need to scan outwards from a 'while' to be able to infer from the surrounding context whether it is normal while-loop or is part of do-while.
do while(cond) ; while (cond);
is valid, and indeed may be confusing to humans. But people
would normally write it as
do {
while(cond) ;
} while (cond);
or even
do {
while(cond) {
;
}
} while (cond);
to stress that inner loop is "do nothing" loop. In this form
structure is clear.
If you want human-oriented rule for parsing badly written code,The inner loop might be this:
you may notice that body of a C loop can not be syntactually
empty, you need at least a semicolon. So first 'while'
after 'do' must start an inner loop.
Concerning "subtle", note that changing say '*' to '+' can; and to a lesser extent {} are regarded as punctuation. The problem is more in leaving them out or adding extra ones.
signifcantly change parse tree and semantics in almost any
programming language. Most people are not bothered by this
and take care when writing/reading operators. Similarly
C programmers are careful when writing/reading semicolons.
You can design a laguage with more redundancy. For exampleOK, I should have read this first. Of course, that's already been done. C decided to keep its delicate grammar rather than tighten it up.
one of languages that I use has
if cond then expr1 else expr2 endif
while cond do expr endwhile
repeat expr endrepeat
Les messages affichés proviennent d'usenet.