return when desugaring to closures
Brendan Eich
brendan at mozilla.com
Fri Oct 17 22:39:58 PDT 2008
On Oct 17, 2008, at 7:36 PM, Eric Suen wrote:
> Are you sure about that, because you using hand written top-down
> parser,
> Is it confirmed by a top-down parser generator like ANTLR?
I haven't used ANTLR or any other LL(*) parser generator, no.
I found http://code.google.com/p/antlr-javascript/ and wondered if
anyone on the list has evaluated it.
> I think top-down parser has no issue to parse following code:
>
> function() {
> }();
Agreed.
> but this is not a valid statement because:
>
> ExpressionStatement ::= [lookahead ! {{, function}] Expression ;
That's a good example. See https://bugzilla.mozilla.org/show_bug.cgi?id=376052
if you are interested in why people want to evaluate such a statement.
> This kind question I asked long time ago, but no one answed,
>
> https://mail.mozilla.org/pipermail/es-discuss/2008-July/006640.html
Sorry, Jeff may have missed your question. I don't understand it
myself (no one ever proposed any syntax of the form x = function ()
return y).
> and now seems write a bottom up JS parser is mission impossible.
Why do you say that? Maciej already cited the Bison grammar that
WebKit's JS engine uses. Waldemar has an out of date but ambitious
bottom-up grammar checker. The question before us is what to
standardize and how to check it.
An extension like let expressions is not a foregone conclusion,
likewise expression closures (which some folks in TC39 at the Oslo
meeting favored). If we don't want ambiguities that create prove-a-
negative hazards, we won't standardize these as-is. For example, we
could require parenthesization of the AssignmentExpression body; or
we could do something else, such as the braced lambda body that's been
discussed here recently.
If you mean bottom-up parsing of JS1.7 as implemented in SpiderMonkey
is impossible, I still wouldn't go that far. C and C++ are not easy to
parse bottom-up, but even ignoring lexer/parser feedback, it can be
done with enough hacking, AFAIK.
The C-like languages including JS do not inherit bottom-up grammar
bones from bad old C. The C top-down grammar (dmr's original C
compiler used recursive descent and operator precedence parsing) shows
through pretty clearly. I agree we shouldn't make things worse. I
don't think all hope is lost.
/be
More information about the Es-discuss
mailing list