二次创作Z01语言

目录

一,字符集

二,编译分词

三,token含义

四,Z01翻译成C++

五,执行翻译后的代码

六,打印Hello World!


一,字符集

假设有门语言叫Z01语言,代码中只有0和1这两种字符。

二,编译分词

预处理剔除所有非0和1的字符之后,采用固定分词方式,从左往右每三个字符构成1个token,所以一共有8种token。

PS:预处理不是重点,本文不涉及,假设输入的都是只有0和1的字符。

三,token含义

token

含义

000

指针加一

001

指针减一

010

指针指向的字节的值加一

011

指针指向的字节的值减一

100

输出指针指向的单元内容(ASCⅡ码)

101

输入内容到指针指向的单元(ASCⅡ码)

110

如果指针指向的单元值为零,向后跳转到对应的]指令的次一指令处

111

如果指针指向的单元值不为零,向前跳转到对应的[指令的次一指令处

聪明的读者或许已经看出来了,我这个只是二次创作,毕竟有趣的灵魂互相抄袭。

四,Z01翻译成C++

string translate(char a, char b, char c)
{
    if (a == '0') {
        if (b == '0') {
            if (c == '0') {
                return "p++";
            }
            else {
                return "p--";
            }
        }
        else {
            if (c == '0') {
                return "*p = *p + 1";
            }
            else {
                return "*p = *p - 1";
            }
        }
    }
    else {
        if (b == '0') {
            if (c == '0') {
                return "cout<<char(*p)";
            }
            else {
                return "*p=getchar()";
            }
        }
        else {
            if (c == '0') {
                return "while(*p){";
            }
            else {
                return "}";
            }                
        }
    }
}


int main()
{
    char a,b,c;
    string s;
    while (cin >> a >> b >> c) {
        s += translate(a,b,c);
        if (a == '1'&&b=='1'&&c=='0')continue;
        s += ";\n";
    }
    cout << s;
    return 0;
}

例如,输入:

010010010010010010010010010010010010010110011000010010010010010001111000100

输出:

*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
cout<<char(*p);

五,执行翻译后的代码

void run()
{
    char arr[1000] = { 0 };
    char* p = arr+500;
    //input code
}

int main()
{
    run();
    return 0;
} 

只要把翻译后的代码粘贴进去就行。

六,打印Hello World!

有了打印一个字符的经验和归0操作,接下来就可以输出任意字符了:

Ascii码分别是72,101,108,108,111,32,87,111,114,108,100,33

代码应该是:

010010010010010010010010010110011000010010010010010010010010001111000100110110011111001111010010010010010010010010010010110011000010010010010010010010010010010001111000010100110110011111001111010010010010010010010010010110011000010010010010010010010010010010010010001111000100110110011111001111010010010010010010010010010110011000010010010010010010010010010010010010001111000100110110011111001111010010010010010010010010010110011000010010010010010010010010010010010010001111000010010010100110110011111001111010010010010010010010010110011000010010010010001111000100110110011111001111010010010010010010010010110011000010010010010010010010010010010010001111000011100110110011111001111010010010010010010010010010110011000010010010010010010010010010010010010001111000010010010100110110011111001111010010010010010010010010010110011000010010010010010010010010010010010010001111000010010010010010010100110110011111001111010010010010010010010010010110011000010010010010010010010010010010010010001111000100110110011111001111010010010010010010010010010010110011000010010010010010010010010010010001111000100110110011111001111010010010010010010010010110011000010010010010001111000010100110110011111001111

翻译结果:

*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
*p = *p + 1;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
*p = *p - 1;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
while(*p){*p = *p - 1;
p++;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
*p = *p + 1;
p--;
};
p++;
*p = *p + 1;
cout<<char(*p);
while(*p){while(*p){*p = *p - 1;
};
p--;
};

运行效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值