No parenthesis for assert?
Stewart Gordon
smjg_1998 at yahoo.com
Sat Jan 14 04:59:00 PST 2012
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.
More information about the Digitalmars-d
mailing list