Your syntax implies that [\n] should be treated as [;]. So why not use [\n] as alternative?
Cheers, Ricky > On Dec 6, 2016, at 4:23 PM, Simon Richter <simon.rich...@hogyros.de> wrote: > > Hi, > > I'm still building an ECMAScript parser, it's mostly running, except for > the Automatic Semicolon Insertion rule in the language: if a token stream > is invalid, but can be made valid by inserting a semicolon in front of the > current token, pretend that a semicolon is there. > > For example inside a function: > > function f() { > i = 5 > } > > the semicolon at the end of the assignment is implied, because a closing > brace is unexpected there. Similarly, > > var foo = 4 > var bar = 5 > > is legal, because the "var" token after the 4 is unexpected. At the same > time, if I make the semicolon optional, I'm in shift/reduce hell as the > next token could be unary or binary minus (as well as some other things). > > Is there a way to create a last-resort alternative that always loses any > conflict, so I can do something similar to > > variable_statement: > "var" variable_declaration_list ";" %prec WIN | > "var" variable_declaration_list %prec LOSE; > > The expected result would be that anything that can be used to continue a > variable_declaration_list should go into it, anything that cannot be used > would terminate it, and a semicolon would terminate it nonetheless. > > Alternatively, can I somehow use YYBACKUP or the error symbol here, by > allowing error productions instead of a semicolon, and inserting a > semicolon token as the next lookahead? > > Simon > > _______________________________________________ > help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison