December 13, 2005 Re: What is it? Syntax sugar or some stupid lazyness? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Walter Bright wrote:
>
>> "BCS" <BCS_member@pathlink.com> wrote in message
>> news:dnn794$1psk$1@digitaldaemon.com...
>>
>>> As to a+b+c being unambiguous, I can't find the rules that make that
>>> true. Could you please point me to them?
>>
>>
>>
>> It's implicit in the grammar for AddExpression's.
>>
>>
>
> I just reread that, and I don't see it.
>
> (I'm looking at http://www.digitalmars.com/d/expression.html#AddExpression , is this the right place )
First, you should trust Walter when he says something :)
And to the point - AddExpr is defined as (among others)
AddExpr + MulExpr
So, if you have a+b+c, it can't parse as a+(b+c), as that would mean that "a" is an AddExpr and "b+c" must then be a MulExpr, which it obviously can't be. OTOH, (a+b)+c does fit the grammar..
xs0
|
December 13, 2005 Re: What is it? Syntax sugar or some stupid lazyness? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Walter Bright wrote:
>> "BCS" <BCS_member@pathlink.com> wrote in message
>> news:dnn794$1psk$1@digitaldaemon.com...
>>
>>> As to a+b+c being unambiguous, I can't find the rules that make that
>>> true. Could you please point me to them?
>>
>> It's implicit in the grammar for AddExpression's.
>
> I just reread that, and I don't see it.
I believe this is because expressions are evaluated left to right, assuming equal operator precedence. This seems to be a standard rule for expression evaluation regardless of the programming language. What is not predetermined (as Walter points out) is the evaluation of each member of an expression, as this should not affect the evaluated result. Typically, building side-effects into the evaluation of expression members is considered bad form, and except for the few defined cases such as short-circuit evaluation, the order in which these members are evaluated is undefined.
Sean
|
December 13, 2005 Re: What is it? Syntax sugar or some stupid lazyness? | ||||
---|---|---|---|---|
| ||||
Posted in reply to xs0 | xs0 wrote:
> BCS wrote:
>
>> Walter Bright wrote:
>>
>>> "BCS" <BCS_member@pathlink.com> wrote in message
>>> news:dnn794$1psk$1@digitaldaemon.com...
>>>
>>>> As to a+b+c being unambiguous, I can't find the rules that make that
>>>> true. Could you please point me to them?
>>>
>>> It's implicit in the grammar for AddExpression's.
>>
>> I just reread that, and I don't see it.
>>
>> (I'm looking at http://www.digitalmars.com/d/expression.html#AddExpression , is this the right place )
>
> First, you should trust Walter when he says something :)
>
> And to the point - AddExpr is defined as (among others)
>
> AddExpr + MulExpr
>
> So, if you have a+b+c, it can't parse as a+(b+c), as that would mean that "a" is an AddExpr and "b+c" must then be a MulExpr, which it obviously can't be. OTOH, (a+b)+c does fit the grammar..
>
>
>
> xs0
Thank you for that explanation, (I was looking in the text so I missed that).
Also, I was trying to ask the question as "You say its true so I must be a dumb schmuck for not finding it."
-BCS
"I would rather feel like an fool now for asking a dumb question then tomorrow for not asking a smart one ."
|
Copyright © 1999-2021 by the D Language Foundation