6

我自己写的 Python 超集语言发布了能用的版本

 3 years ago
source link: https://www.v2ex.com/t/799393
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

我自己写的 Python 超集语言发布了能用的版本

  abersheeran · abersheeran · 3 小时 25 分钟前 · 437 次点击

经过这段时间的学习,我终于把编译原理捡回来了一点。然后重新写了 MingShe 现在基本上可以说能用了,细节上可以再优化。

用的 Python3.9 同款编译器( Guido 写的那个),所以不必担心与 Python 的兼容,Python 支持的,我支持,Python 不支持的,我也支持。

目前支持的三种额外特性都写在 README 了,分别是管道、偏函数以及三元运算符。

我随便写个程序展示一下管道和偏函数的效果。把这个写在一个文本文件里,使用命令 mingshe 你的文件路径 就能看到执行结果了。

10 |> range |> map(pow(?, 2), ?) |> list |> print

三元运算符这个就比较简单了,用的 C 语法,编译结果还是 Python 的 if-else 。主要是我觉得 if-else 太长了,a?b:c 这个短一些。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK