if (int x=..) but no while(int x=..) ?

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Fri Mar 17 04:51:35 PST 2006


Lionello Lunesu wrote:
>> The grammar for D does not allow a
>>
>> "Declarator = Expression"
>>
>> inside the braces of a while statement. The "IfCondition" rule does allow 
>> this
>> for the if statements, however. Now, can the grammar be modified to accept 
>> the
>> "Declarator = Expression" rule? Yes, I just modified my grammar and it 
>> works
>> without conflicts. As for any deeper questions about the
>> validity/usability/maintainability of this...well that is for Walter to 
>> decide,
>> I guess.
> 
> Nice test, thanks. So with no grammatical conflicts and the added symmetry, 
> it should be easy to get Walter's backing on this : )
> 

Yes, an easy-to-use grammar checker would probably reduce the amount of
totally pointless syntax proposals.

One other thing I don't understand is the "Expression -> Expression |
AssignExpression , Expression" -rule. C++ seems to support this, but
Java doesn't. The comma-operator is mostly used inside the if
-->(...)<-- {} -part of if/while -loops. There can be a lot of uses for
commas inside other statements, e.g. multidimensional arrays:

int[][] a
a.length = 4,5;

or

return 1,2,3;

Currently these operations don't work as expected, thus causing code
obfuscation. I'm not saying these examples are well designed, but I
cannot see why we should prevent potential future extensions. What do
you think?

-- 
Jari-Matti



More information about the Digitalmars-d mailing list