Nitpicking the D grammar

Jascha Wetzel "[firstname]" at mainia.de
Sun Sep 9 05:57:45 PDT 2007


Stewart Gordon wrote:
> "Jascha Wetzel" <"[firstname]"@mainia.de> wrote in message 
> news:fbrk6q$1cv5$1 at digitalmars.com...
> <snip>
>> Disallowing expressions without an effect is nice, but wouldn't a 
>> warning suffice? After all the compiler can't find all expressions 
>> that have no effect. Besides, adding for example two integers and not 
>> saving the result (which is classified as a no-effect-expression) 
>> still has the effect of changing the eflags register, which may be 
>> read in an asm block. So it's questionable what "no effect" actually 
>> means.
> 
> Not if the compiler optimises it away.  As such, the contents of any 
> register after such a statement would be undefined, so you can't really 
> do anything with it.

you're right. the registers' contents aren't part of the language 
definition.

>> Wouldn't it be more appropriate here to change the specs to
>> "Expressions that can be interpreted as a declaration, like (a*b), are 
>> illegal in expression statements. If such an expression is needed, 
>> casting it to void will make it legal."
>> (http://www.digitalmars.com/d/statement.html#ExpressionStatement)
> 
> Such a statement in the spec would be null, because it isn't even parsed 
> as an ExpressionStatement.
> 
> What the spec needs to do is properly document the disambiguation rules.

that was my shot at doing this. it's not very elegant, but it describes 
exactly what the parser does.



More information about the Digitalmars-d mailing list