Error in the SRFI-30 formal specification
Alsatian Petrofsky 28 Dec 2002 21:28 UTC
I was just looking at the final SRFI-30 and noticed that the
production rules are ambiguous. I see that this was brought up on the
discussion list, but I don't think it was resolved correctly. Sorry I
wasn't paying attention in August.
The production rules are:
<comment> ---> ; <all subsequent characters up to a line break>
| #| <comment-text> (<comment> <comment-text>)* |#
<comment-text> ---> <character sequence not containing #| or |#>
Gasbichler wrote:
> >>>>> "John" == jtobey <xxxxxx@john-edwin-tobey.org> writes:
>
> John> Is this supposed to be a comment or only the beginning of one?
> John> #| ; |#
>
> John> The lexical production rules say this "|#" is ignored as part of a
> John> nested single-line comment, but the implementation regards it as the
> John> end of a multi-line comment.
>
> The semicolon does not start a single-line comment because it matches
> <comment text>.
But the production rules don't say that. They say that "; |#" +
newline is a legal comment, that " " and "foo ; " are legal
comment-texts, and that for any legal comment X and comment-texts T1
and T2, "#|" + T1 + X + T2 + "#|" is a legal comment. Thus, the rules
say that this text:
#| ; |#
foo ; |#
may be parsed as either a comment or as an identifier preceeded and
followed by comments.
I think the way to write the specification you intended is like this:
<comment> ---> ; <all subsequent characters up to a line break>
| <srfi-30-comment>
<srfi-30-comment> #| <comment-text> (<srfi-30-comment> <comment-text>)* |#
<comment-text> ---> <character sequence not containing #| or |#>
-al