MultiLineCommentChars and PostAsteriskCommentChars productions
Isiah Meadows
isiahmeadows at gmail.com
Mon Apr 10 00:17:02 UTC 2017
It's a single-character lookahead, which is sufficient for an LR(1)
language. All it does is validate that `/* * */` is a complete block
comment, but not `/* *` or `/* * /`.
On Sun, Apr 9, 2017, 17:13 Darien Valentine <valentinium at gmail.com> wrote:
> I am curious about this lexical production, because if I understand
> correctly, it seems to imply either backtracking or a lookahead that isn’t
> made explicit.
>
> ```
> MultiLineComment ::
> /* MultiLineCommentChars[opt] */
>
> MultiLineCommentChars ::
> MultiLineNotAsteriskChar MultiLineCommentChars[opt]
> * PostAsteriskCommentChars[opt]
>
> PostAsteriskCommentChars ::
> MultiLineNotForwardSlashOrAsteriskChar MultiLineCommentChars[opt]
> * PostAsteriskCommentChars[opt]
>
> MultiLineNotAsteriskChar ::
> SourceCharacterbut not *
>
> MultiLineNotForwardSlashOrAsteriskChar ::
> SourceCharacterbut not one of / or *
> ```
>
> In the second choices within PostAsteriskCommentChars and
> MultiLineCommentChars, the appearance of PostAsteriskCommentChars following
> the literal asterisk is optional. Because of this, a naive match will be
> made for PostAsteriskCommentChars against the `*` of a terminal `*/` of the
> MultiLineComment.
>
> While this is not ultimately ambiguous because, having made that match,
> the next attempt will fail and we can backtrack one step to find another
> way out; or, more realistically, an implementation would look ahead at
> whether the next character (after "*") is `/` before deciding that
> PostAsteriskCommentChars/2 should _really_ be matched. However it seems
> unusual that the grammar is written this way since elsewhere the grammar
> seems to carefully avoid implied backtracking, and lookaheads are rare and
> explicit.
>
> This section of the lexical grammar has remained unchanged since ES1, so
> it may be that it just hasn’t been revisited as the grammar specification
> style developed. Am I reading it correctly and, if so, is it actually
> unusual, or does this sort of thing fall within the boundaries of how the
> grammar is normally described?
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170410/6d2617d6/attachment.html>
More information about the es-discuss
mailing list