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
Not like this:
expr
|
STRING+
/ \
expr expr
| |
STRING STRING
That would be
> expr
> / \
> expr expr
> | |
> STRING STRING
Thomas 'PointedEars' Lahn wrote:
> Prove it.
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.
What you seem to be doing in your mind is taking this
production:
expr ::= STRING
and using it "backwards" to justify expanding any occurrence
of STRING into expr. 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.
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list