Reserved words as identifiers (was Re: Long names are doom ?)

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Sun May 27 17:13:15 EDT 2001


----- Original Message -----
From: "Thomas Wouters" <thomas at xs4all.net>
Subject: Re: Long names are doom ?


> There are basically two choices wrt. allowing reserved words as vrbl
names:
>
> 1) allow them everywhere, in any situation. This is doable, even with the
> LL(1) parser Python currently has, but doing it in the LL(1) parser would
be
> atrociously ugly, both in the grammar and in the compiler/scanner.
However,
> there would be problems with, e.g., print. What would
>
>   print(spam)
>
> mean ?

This is why I suggested only allowing them in unambiguous locations;
specifically, reserved words which would cause a SyntaxError to be
raised would be rechecked as identifiers.  This shouldn't take much
work on the part of the parser IMHO although it still looks a bit like
a Rubik's Cube to me...

In other words, I DON'T want to be able to do this:

    class = 99   # BAD

but I would like to do this:

    myobject.class = 99
    myobject.if = 0
    myobject.then = callback

etc.

<some commentary hacked out here>

> Like Tim posted, Guido agreed with #2 already (pending implementation).
I'm
> not sure what his opinion of #1 is, but if the print() problem can be
worked
> around (by making it illegal ;) and no other problems arrise, I'm pretty
> sure it's discussable. *I* like it, anyway :) Unfortunately, I don't have
> the time, nor the experience with non-LL parsers, to build a new parser.
> Using the old parser is possible, but would probably mean a preprocessor
(or
> an extra pass in the grammar-parser) and much ugly hacks.

I've seen a language (Clipper 5.0 I think) where the following lines of code
are actually different:

    name (var1)
    name(var1)

The first is a statement with it's parameter in parentheses, which tells the
compiler that it is a sort of macro substitution and name is a statement.
The
second is a function call to name with var1 as a parameter.

Gah.  Needless to say I don't want a brain damaged mess like that in Python.

<more commentary hacked away here>






More information about the Python-list mailing list