A simple single line, triple-quoted comment is giving syntax error. Why?
Ian Kelly
ian.g.kelly at gmail.com
Thu Mar 26 14:29:02 EDT 2015
On Thu, Mar 26, 2015 at 10:45 AM, Thomas 'PointedEars' Lahn
<PointedEars at web.de> wrote:
> Ian Kelly wrote:
>> What the grammar that you quoted from shows is that STRING+ is an
>> expression. The individual STRINGs of a STRING+ are not expressions,
>> except to the extent that they can be parsed in isolation as a
>> STRING+.
>
> How did you get that idea? STRING+ means one or more consecutive STRING
> tokens (ignoring whitespace in-between), which means one or more consecutive
> string literals. A (single) string literal definitely is an expression as
> it can be produced with the “expr” goal symbol of the Python grammar (given
> there in a flavor of EBNF).
Yes, that's what I was referring to in my parenthetical "except..." above.
What I mean is that if you construct a parse tree of "foo" "bar" using
that grammar, it looks like this:
expr
|
STRING+
/ \
STRING STRING
Not like this:
expr
|
STRING+
/ \
expr expr
| |
STRING STRING
There is only one expr node, and it contains both STRING tokens.
>> By the same token, a STRING+ is a single string literal, not
>> an aggregate of several.
>
> No, in the used flavour of EBNF the unquoted “+” following a goal symbol
> clearly means the occurrence of *at least one* of the immediately preceding
> symbol, meaning either one *or more than one*.
It means one or more *tokens*, not one or more literals.
More information about the Python-list
mailing list