No parenthesis for assert?

Alex Rønne Petersen xtzgzorex at gmail.com
Sat Jan 14 07:32:58 PST 2012


On 14-01-2012 13:59, Stewart Gordon wrote:
> On 12/01/2012 22:56, Alex Rønne Petersen wrote:
>> On 12-01-2012 22:35, Peter Alexander wrote:
> <snip>
>>> Not to mention that it would be ambiguous with the comma operator:
>>>
>>> assert (a, b); // is this the comma operator, or two arguments?
>>
>> I did point out that it would only really make sense for asserts
>> without messages.
>
> Therein lies the point. If we changed the AssertExpression grammar to
>
> AssertExpression:
> assert ( AssignExpression )
> assert ( AssignExpression , AssignExpression )
> assert AssignExpression
>
> then the form
>
> assert ( AssignExpression , AssignExpression )
>
> would become ambiguous, because it could be parsed as
>
> assert ( AssignExpression , CommaExpression )
> assert ( CommaExpression )
> assert ( Expression )
> assert AssignExpression
>
> In some cases it's resolved by an "if it's parseable as X, it's X" rule,
> but this would create fragility because of the possibility of a
> CommaExpression of three or more terms. As such, it would be a case of
> explicitly disallowing
>
> assert ( CommaExpression )
>
> in the grammar.
>
> Stewart.

Point taken; I now see what you're getting at. I tend to forget the 
existence of the comma operator when considering these things... I wish 
we wouldn't have it in the language; it seems to be more trouble than 
it's worth (in more ways than one).

-- 
- Alex


More information about the Digitalmars-d mailing list