[Python-Dev] Needing help to change the grammar

Harry (Thiago Leucz Astrizi) thiagoharry at riseup.net
Sat Apr 11 03:58:26 CEST 2009

Hash: SHA1

Hello everybody. My name is Thiago and currently I'm working as a
teacher in a high school in Brazil. I have plans to offer in the
school a programming course to the students, but I had some problems
to find a good langüage. As a Python programmer, I really like the
language's syntax and I think that Python is very good to teach
programming. But there's a little problem: the commands and keywords
are in english and this can be an obstacle to the teenagers that could
enter in the course.

Because of this, I decided to create a Python version with keywords in
portuguese and with some modifications in the grammar to be more
portuguese-like. To this, I'm using Python 3.0.1 source code.

I already read PEP 306 (How to Change Python's Grammar) and changed
the suggested files. My changes currently are working properly except
for one thing: the "comp_op". The code that in english Python is
written as "is not", in portuguese Python shall be "não é". Besides
the translations to the words "is" and "not", I'm also changing the
order in which they appear letting "not" before "is".

It appears to be a simple change, but strangely, I'm not being able to
perform it. I already made correct modifications in Grammar/Grammar
file, the new keywords already appear in Lib/keyword.py and I also
changed the function validate_comp_op in Modules/parsermodule.c:

static int
validate_comp_op(node *tree)
    else if ((res = validate_numnodes(tree, 2, "comp_op")) != 0) {
        res = (validate_ntype(CHILD(tree, 0), NAME)
               && validate_ntype(CHILD(tree, 1), NAME)
               && (((strcmp(STR(CHILD(tree, 0)), "não") == 0)
                    && (strcmp(STR(CHILD(tree, 1)), "é") == 0))
                   || ((strcmp(STR(CHILD(tree, 0)), "não") == 0)
                       && (strcmp(STR(CHILD(tree, 1)), "em") == 0))));
        if (!res && !PyErr_Occurred())
            err_string("operador de comparação desconhecido");
    return (res);

I also looked in the other files proposed in the PEP but I didn't find
in them nothing that I recognized as needing changes.

But when I type "make" to compile the new language, the following
error appears in Lib/encodings/__init__.py (which I already
translated to the portuguese Python):

harry at skynet:~/Python-3.0.1$ make
Fatal Python error: Py_Initialize:
      can't initialize sys standard streams File
"/home/harry/Python-3.0.1/Lib/encodings/__init__.py", line 73
se entry não é _unknown: ^ SyntaxError: invalid syntax

The comp_op doesn't work! I don't know more what to change. Perhaps
there's some file that I should modify, but I didn't paid attention
enough in it... Please, anybody has some idea of what should I do?
Thanks a lot.
Version: GnuPG v1.4.6 (GNU/Linux)


More information about the Python-Dev mailing list