Semicolons (Re: Low-Rent Syntax)

thomasm@llama.ingres.com (Tom Markson)
Wed, 22 Aug 90 05:18:29 GMT

          From comp.compilers

Related articles
Semicolons (Re: Low-Rent Syntax) bart@videovax.tv.tek.com (Bart Massey) (1990-08-13)
Re: Semicolons (Re: Low-Rent Syntax) codex!peterd@uunet.UU.NET (1990-08-20)
Semicolons (Re: Low-Rent Syntax) thomasm@llama.ingres.com (1990-08-22)
Re: Semicolons (Re: Low-Rent Syntax) trt@rti.rti.org (1990-08-24)
Re: Semicolons (Re: Low-Rent Syntax) mjr@decuac.DEC.COM (1990-08-25)
Re: Semicolons (Re: Low-Rent Syntax) bart@videovax.tv.tek.com (Bart Massey) (1990-08-26)
Re: Semicolons (Re: Low-Rent Syntax) elsie!ado@uunet.UU.NET (1990-08-27)
Re: Semicolons (Re: Low-Rent Syntax) anw@maths.nott.ac.uk (1990-08-29)
Re: Semicolons (Re: Low-Rent Syntax) liam@cs.qmw.ac.uk (1990-09-03)
[7 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: thomasm@llama.ingres.com (Tom Markson)
Keywords: C, design, debug
Organization: Compilers Central
Date: Wed, 22 Aug 90 05:18:29 GMT

> Well, I'll admit it :-). I've been programming in C professionally for
> about 5 years, and about 1/2 my extra trips into the editor are still to
> correct missing semicolons. I almost never *add* semicolons, though.
> This is true of most C programmers I know. And note that when the added
> semicolon does appear, it usually takes the insidious form


> x = 100;
> while( x );/* a nasty case */
> /*
>
> * these comments are intended only to obscure the fact
> * that the next statement will never be executed...
>
> */
> x--;




The real problem here is not with the semicolon, it is with the grammar
production that dominates C and Pascal:


while: WHILE (expr) statement
;


statement: '{' statements '}'
| while ';'
| /* etc */
;


Thus, If WHILE were terminated with ENDWHILE, This error would not occur:


while: WHILE (expr)
statements ';'


ENDWHILE ';'
;


statements: statements ';' statement
| statement
;




The semicolon in the erroneous code example above would simply be an empty
statement.


> I'm just plain tired of debugging code (of my own and others' :-) like
>
> if( v )
> w;
> if( x )
> y;
> else /*XXX*/;
> z;


Again, this is the same problem as above. As John mentioned, one safe
way to do it in C is to ALWAYS use braces after an if,for, etc.. You'll
find it makes your life much easier.


--
Tom Markson Unix Systems
email: thomasm@llama.rtech.com Ingres Corp
phone: 415-748-250
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.