`if` `(` expr `)` stmt vs `if` expr `then` stmt .....

Steven Pemberton steven at mcvax.UUCP
Thu May 24 23:52:31 AEST 1984

>	Anyone who is a serious student of programming linguistics,
>    should realize that a delimiter is necessary to separate the
>    expression from the statement in all conditional language-constucts
>    -- if you want to keep your grammer LALR(1) (almost a given).
Nonsense. You can even define an LL1 grammar with no delimiter.

>    I prefer the '(' ')' of C, to the 'if' 'then' of Pascal, because:
>    [1] It is shorter to type, [2] Is symmetrical, and
>    [3] Does not disguise the true purpose of the construct.
Isn't <keyword> <expression> <keyword> also symmetrical? How is the true
purpose of the construct disguised by the absence of brackets,
and the presence of 'then'?

>    NON-symmetry is the most aggravating part of programming Pascal,
>    as anyone who has been bitten by the:
>       <if> <stmt> <NO-SEMICOLON> <else> <stmt> <semicolon>
>    can tell you.
Semicolons are separators in Pascal and not terminators, just as commas are
in C. Your mistake is thinking that the semicolon has anything to do with
the statement. It doesn't; the correct view is
        <if> <stmt> <NO-SEMICOLON> <else> <stmt> <ALSO-NO-SEMICOLON>
You wouldn't expect to see a function call like f(a,b,c,); semicolons play
the same role as commas in Algol-like languages.

I expect that having trouble with Pascal semicolons is a product of one's
previous experience. My first languages were Fortran followed by Algol 68,
and I've never experienced the separator vs. terminator problem.
However, I expect that if my first language had been C, I would have had.
When I first learnt C, I kept missing semicolons out, such as
    if (a>b) {a=0; b=0}
But that was my fault, not the language's.

Actually, semicolons are completely unnecessary. You can define a language
without statement terminators or separators, and also without things like
Fortran's continuation lines. See for instance "Keyword Grammars" by Geurts
and Meertens, in Proc. 5th Annual III conference, 1977, published by INRIA,
Le Chesnay, France.

More information about the Comp.lang.c mailing list