在python中重命名elif

lok*_*cus 4 python grammar cpython python-2.7

我最近玩了一些在python中添加一些可选语句名称,并且工作正常,直到我进入if语句并且我为else和elif添加了一个可选名称:

if_stmt = 'if' test ':' suite ('elif' test ':'suite)* ['else' ':' suite] |  'wenn' test ':' suite ('andernfalls' test ':'suite)* ['sonst' ':' suite]
Run Code Online (Sandbox Code Playgroud)

然后它编译没有错误,但当我用wenn和andernfalls运行测试时,解释器抛出了错误:

SystemError: unexpected token in 'if' statement: andernfalls 
Run Code Online (Sandbox Code Playgroud)

而我所做的每一个加法都很有效.那么为什么我不能添加其他和elif,我该怎么办?

我正在修改python网站上最新的python 2.7代码

编辑我的测试代码是:

x = 1
y = 2
wenn x > y:
    print 1
andernfalls x < y:
    print 2
sonst:
    print 3
Run Code Online (Sandbox Code Playgroud)

我在顶部添加行的文件是python源代码的Grammar目录中的语法文件

use*_*ica 6

elseelif在AST生成代码中进行一些特殊情况处理:

static stmt_ty
ast_for_if_stmt(struct compiling *c, const node *n)
{
    ...
    /* s[2], the third character in the string, will be
       's' for el_s_e, or
       'i' for el_i_f
    */
    if (s[2] == 's') {
        ...
    }
    else if (s[2] == 'i') {
        ...
        if (TYPE(CHILD(n, (n_elif + 1))) == NAME
            && STR(CHILD(n, (n_elif + 1)))[2] == 's') {
            ...
Run Code Online (Sandbox Code Playgroud)

你必须修改ast_for_if_stmtPython/ast.c更改操作.