why ; ?

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon May 5 07:28:08 PDT 2008


"Tomasz Sowinski" <tomeksowi at gmail.com> wrote in message 
news:fvmfjs$q4n$1 at digitalmars.com...
>
> Just another feature thought. Never gonna happen, but still...
>
> What's the reason of having lines end with a semicolon? Anything else than 
> a legacy issue with C/C++?
>
> The only thing I can think of is having multiple statements in one line, 
> but that only makes code unreadable. Wouldn't getting rid of ; improve 
> readability?

I don't like semicolons.  To that end, I have changed statement terminators 
in my scripting language to accept semicolons or newlines.  Having a C-style 
syntax, it's been a sort of interesting experiment to see what ambiguities 
arise in the C syntax without them.

The language has not dropped semicolons entirely, it's just made it possible 
to skip them at the end of lines.  If you want multiple statements on one 
line, you still have to separate them with semicolons.

There are really only two places in the grammar where there are possible 
parsing ambiguities:

1) Return statements.  Does:

return
f()

parse as "return f();", or does it parse as a "return;" followed by a 
function call?  I have it parse as the latter, as that makes the most sense 
to me.

2) Function calls vs. parenthesized expressions.  Does:

x = f
(g + h).i()

parse as "x = f(g + h).i();" or as "x = f; (g + h).i();" ?  I have this give 
a parsing error since one way or the other doesn't really make sense.  In 
order to resolve the ambiguity, you either have to put a semicolon after the 
first statement to make it 2 statements, or move the open paren up to the 
first line to make it one.

Other than these two cases, I haven't run into any other tricky parsing 
spots.  Granted, the language is simpler than D and doesn't have nearly as 
many statements, but it doesn't seem like there would be any other 
difficulties in parsing.

The one major downside to this change in the grammar, however, is that it 
makes lexical analysis dependent upon syntactic analysis, since the 
significance of newlines depends upon the current construct being parsed.  D 
prides itself on having no such interdependencies, and you'd be hard-pressed 
to convince Walter to do otherwise. 





More information about the Digitalmars-d mailing list