Are Python's reserved words reserved in places they dont need to be?
Kay Schluehr
kay.schluehr at gmx.net
Thu Sep 14 10:32:46 EDT 2006
Carl Banks wrote:
> metaperl wrote:
> > --> python -i
> > >>> class = "algebra"
> > File "<stdin>", line 1
> > class = "algebra"
> > ^
> > SyntaxError: invalid syntax
> > >>>
> >
> >
> > Why isn' t the parser smart enough to see that class followed by an
> > identifier is used for class definition but class followed by equals is
> > a simple assignment?
>
> Hmm. Someone called "metaPERL" is asking why Python doesn't have a
> more complicated grammar. Why does this not surprise me? :)
Yeah. But elimination of all keywords and replacement by punctuation is
clearly an alternative. One might just start with:
@class X(object):
@def __init__(self):
@print "an X"
and move on to:
@% X(object):
@_ _init__(self):
>> "an X"
That's all still LL(1) parsable.
More information about the Python-list
mailing list