A simple single line, triple-quoted comment is giving syntax error. Why?
Thomas 'PointedEars' Lahn
PointedEars at web.de
Sat Mar 28 14:06:07 EDT 2015
Gregory Ewing wrote:
> Ian Kelly wrote:
>> 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 quite -- STRING+ is not a symbol in the grammar, it's
> a shorthand for a combination of symbols. The parse tree
> is actually just
>
> expr
> / \
> STRING STRING
Or if there is a single STRING,
expr
|
STRING
AISB.
>> Not like this:
>>
>> expr
>> |
>> STRING+
>> / \
>> expr expr
>> | |
>> STRING STRING
> […]
>
> To get a parse tree like the above, there would need to be
> a production like this in the grammar:
>
> expr ::= expr+
>
> There is no such production, so that parse tree is impossible.
> QED.
Correct.
> What you seem to be doing in your mind
Who is “you” here? You appear to be confused, probably supported by your
unconventional quotation style, who made which statement.
> is taking this production:
>
> expr ::= STRING
>
> and using it "backwards" to justify expanding any occurrence
> of STRING into expr.
No.
> But grammars don't work that way. You're committing a logical fallacy:
> just because some exprs are STRINGs doesn't mean that all STRINGs are
> exprs.
The fallacy – a straw man – is yours here. Nobody – in particular not me –
claimed that “STRING” can *only* be produced by “expr” in the first place.
Production rules in a formal grammar of the form
expr → … | any_goal | …
any_goal → … | any_other_goal | …
any_other_goal → … | STRING+ | …
where the steps in-between are optional, mean *exactly* that (*all*)
“STRING”s are “expr”s – but that not all “expr”s are “STRING”s. Because it
follows from the rules above that these production chains – *but not _only_
these* – are possible:
a) expr ⇒ … ⇒ STRING
b) expr ⇒ … ⇒ STRING STRING
c) expr ⇒ … ⇒ STRING STRING STRING
and so on. The truth of the statement “(All) STRING( literal)s are
expr(ession)s” is what follows from the possibility of the first production
chain. (That does not preclude the possibility that “STRING”s are also an
element of another set.)
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
More information about the Python-list
mailing list