> On 30 Nov 2016, at 19:54, Simon Richter <[email protected]> wrote:
> I have a grammar for ECMAScript, ...
You might check in the Usenet newsgroup comp.compilers if somebody has done it
before.
> ...which has both brace delimited statement
> blocks and brace delimited object literals, and allows expressions to be
> used as statements, which creates conflicting interpretations for "{ }" as
> either an empty block or an empty object.
>
> The specification clarifies that expression statements may not begin,
> among other things, with a brace, resolving the conflict. If I wanted to
> transform that into rules, I'd have to create two versions of most of the
> rules for expressions, one allowing object literals, one disallowing them.
There are various ways to do that: One is to parse a larger language and
resolve it in the actions; this way a C++ Yacc grammar has been made. For
example, making your "statements" variable non-empty, and check what the empty
brackets are is in the action. Another is setting context switches; for example
the lexer might return different token symbols for the braces. This method has
the disadvantage that the parser may or may not make a token lookahead (check
manual). Also, one might try the GLR parser.
_______________________________________________
[email protected] https://lists.gnu.org/mailman/listinfo/help-bison