[Types-sig] question regarding adding words to the grammar

Guido van Rossum guido@CNRI.Reston.VA.US
Wed, 19 Jan 2000 22:59:13 -0500


> While I have worked with the pythons grammar to play with type
> checking, I found that no matter where a word is introduced in the
> grammar, it causes that word to become a keyword, even if that word
> cannot appear where a regular variable name might.
> 
> For example, one thing that I once attempted as a way of declaring
> classes relationships to interfaces was:
> 
> classdef: class NAME ['(' NAME (',' NAME)* ')'] ['implements' NAME] ':' suite
> 
> However, when I compiled python with this grammar, it wouldn't let me
> use the word 'implements' as a variable name (gives SyntaxError).
> 
> So the question is:  If you can introduce context-sensitive words, how
> do you do it without making a mess out of the grammar and hacking
> compile.c?

You'd have to hack pgen and friends, the poor excuse for a parser
generator that I wrote before starting to write Python, almost exactly
ten years ago.

Sorry, all quoted identifiers become reserved words.

--Guido van Rossum (home page: http://www.python.org/~guido/)