changing the Python grammar ?

D a v i d E m r i c h emrich at bigfoot.extrastuff.com
Mon Nov 18 15:53:50 EST 2002


"Michele Simionato" <mis6 at pitt.edu> wrote in message news:2259b0e2.0211181221.2eab9db7 at posting.google.com...
...
> But now a question arise to me: can I modify the grammar ??
>
> Suppose for instance I want to make able Python to recognize identifiers
> starting with some funny symbol, say "@". All I must do is to modify
> the first line of the grammar as
>
> identifier ::=
>                ["@"] (letter|"_") (letter | digit | "_")*
>
> In the best of the worlds, I would look for some file in the Python
> source distribution containing the grammar, I would change that line,
> and recompiling I would have a new Python able to understand identifiers
> starting with "@". Is this possible in practice ?
>
> Notice that I do NOT want to introduce ugly perlish-like identifiers in
> Python, I simply want to know how much it is possible to customize the
> Python grammar: is this a simple hack or a nightmare ?

All the parser source code is provided in the distribution.  I would start
with Parser/tokenizer.c (except I wouldn't go there).  It could be a very simple
change.  Have fun.

David






More information about the Python-list mailing list