推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
abersheeran
V2EX  ›  Python

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

  •  
  •   abersheeran · Sep 2, 2021 · 2553 views
    This topic created in 1738 days ago, the information mentioned may be changed or developed.

    经过这段时间的学习,我终于把编译原理捡回来了一点。然后重新写了 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 这个短一些。

    7 replies    2021-09-02 18:21:48 +08:00
    hsfzxjy
        1
    hsfzxjy  
       Sep 2, 2021 via Android
    好奇 MingShe 中文是什么
    abersheeran
        2
    abersheeran  
    OP
       Sep 2, 2021
    @hsfzxjy 《山海经》“鲜山多金玉,无草木,鲜水出焉,而北流注于伊水。其中多鸣蛇,其状如蛇而四翼,其音如磬,见则其邑大旱”。比 Python 多几个翅膀的🐍。
    aloxaf
        3
    aloxaf  
       Sep 2, 2021
    以前玩过个类似的: https://github.com/thautwarm/moshmosh
    abersheeran
        4
    abersheeran  
    OP
       Sep 2, 2021
    @aloxaf 其实不太一样,红姐这个我之前也看了,他是先让 Python 解析到 AST,然后修改 AST 去执行。mingshe 这个是直接从代码生成 AST,语法上更自由。我扩展的这三个 feature,红姐这个库是无论如何都解析不了了。
    37Y37
        6
    37Y37  
       Sep 2, 2021
    虽然看不懂,但感觉很牛逼,支持一下
    O5oz6z3
        7
    O5oz6z3  
       Sep 2, 2021
    好家伙,血糖拉满。稍微跑个题……虽然看不懂 pegen 的语法,但感觉用途广泛,似乎语法糖、超集、DSL 、多国语言本地化、抛弃游标卡尺都能更容易实现,感觉这个自由度有点夸张?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3202 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 03:03 · PVG 11:03 · LAX 20:03 · JFK 23:03
    ♥ Do have faith in what you're doing.