Simple change of python's behaviour
Martin v. Löwis
martin at v.loewis.de
Wed Mar 26 22:15:24 CET 2003
"Tim Gahnström /Bladerman" <tim at bladerman.com> writes:
> Another way would be to add loop as a native keyword in my python
> interpreter, is it a feasible idea or is it just overworking something
> simple? Where would I start for this?
It is feasible, and it shouldn't be that hard. You have to implement
the following steps:
1. Modify the lexer to recognize the new keyword.
2. Modify the grammar to incorporate it, adding non-terminals as necessary.
3. Modify the compiler to recognize the non-terminals
Changes to the byte code are not needed for this feature (as you plan
to represent it with existing statements). Optionally, you can implement
4. Add a __future__ statement, making your extension optional.
I'm not sure whether the list of keywords is generated; it might be
that you just have to modify the grammar. So I recommend to start with
2), editing Grammar/Grammar. Make sure you build on Unix, so that the
compiler generator is invoked. For 3), look at Python/compile.c
> Is there a better way?
I'd personally consider "don't extend the language" better, but you
haven't actually given a rationale for this extension, so this is a
More information about the Python-list