statements that could be expressions?

Mike Samuel mikesamuel at
Wed Jun 1 18:49:57 PDT 2011

2011/6/1 Waldemar Horwat <waldemar at>:
> Yes, if you make it mandatory to parenthesize statements then this would
> work, except for the important case of blocks.

I agree that blocks are sticky but important.

The approach below is a way to handle blocks.  It's not particularly
pretty, but I don't think it's syntactically ambiguous.

Add to existing primary expression the following production

     "(" (lookahead in [break, continue, do, for, if, return, switch,
throw, try, while])
     ExpressionBlock ")"

Define the following Expression productions

     ExpressionBlock ::== EmbeddedStatement ( ";" EmbeddedStatement )*
     EmbeddedStatement ::== ExpressionStatement
        | BreakStatement
        | ContinueStatement
        | IfStatement
        | IteratorStatement
        | ReturnStatement
        | SwitchStatement
        | ThrowStatement
        | TryStatement

A block can be a series of semicolon *separated* (not terminated)
statements inside parentheses.
This introduces no additional hanging else risk.

Note that labelled statement is not in that list so an EcmaScript
program can still be treated by editor paren matchers and jump
forward/back macros as a tree of nested parenthetical and curly
bracket regions.  Within a group at the same level of nesting,
semicolons define broad divisions, commas narrower divisions, and
colons narrower still.

>    Waldemar

More information about the es-discuss mailing list