The trouble with ambiguous grammars

Brendan Eich brendan at mozilla.com
Fri Oct 17 15:50:32 PDT 2008


On Oct 17, 2008, at 3:47 PM, Brendan Eich wrote:

> On Oct 17, 2008, at 3:39 PM, Brendan Eich wrote:
>
>> On Oct 17, 2008, at 12:25 PM, Waldemar Horwat wrote:
>>
>>> ...
>>> let (a = 1) a ? f : x++();
>>>
>>> The grammar states that the last statement must evaluate to "f".
>>> Firefox gives a syntax error.  This is incorrect because the let
>>> expression up to the ++ is a PrimaryExpression so can be used as the
>>> left operand of a function call.
>
> Er, you are right, I should have acknowedged this point. The rest of
> my post is about x++() not being a valid sentence, which supports your
> argument.
>
> While we don't have any usability problems, and torturous statements
> such as
>
> let (a = 1) a ? f : x++();
>
> are not written by real users (they'd parenthesize to clear up
> things), I agree that we don't want the "prove a negative" problem.


This shows a problem with ES4's reliance on top-down parser  
construction. We never created an LR(1) grammar (ignoring ASI and the  
other exceptions that don't fit in LR-anything, and solving dangling  
else as is customary). To avoid the "prove a negative" problem, we  
need one. IIRC you have one -- can you share it via ecmascript.org?

/be


More information about the Es-discuss mailing list