V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
xuanwu
V2EX  ›  分享创造

尝试扩展 Python 控制台添加中文关键字

  •  
  •   xuanwu · 2019-05-20 07:15:32 +08:00 · 1498 次点击
    这是一个创建于 1802 天前的主题,其中的信息可能已经有所发展或是发生改变。
    delectate
        1
    delectate  
       2019-05-20 08:33:04 +08:00
    中文编程,就是闲的。
    LokiSharp
        2
    LokiSharp  
       2019-05-20 09:16:44 +08:00   ❤️ 1
    pyparsing 性能太差了 antlr 还靠谱点
    xuanwu
        3
    xuanwu  
    OP
       2019-05-20 10:35:28 +08:00
    @LokiSharp 因为是参考了周蟒实现. 请问有性能比较出处吗?
    LokiSharp
        4
    LokiSharp  
       2019-05-20 11:49:30 +08:00   ❤️ 1
    @xuanwu #3 https://qiita.com/osamunmun/items/54a00e963d1a7db0cf59

    » python test.py
    ## benchmarker: release 4.0.1 (for python)
    ## python version: 3.5.1
    ## python compiler: GCC 4.2.1 (Apple Inc. build 5666) (dot 3)
    ## python platform: Darwin-15.6.0-x86_64-i386-64bit
    ## python executable: .../antlr/query/venv.d/bin/python
    ## cpu model: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    ## parameters: loop=1000, cycle=1, extra=0

    ## real (total = user + sys)
    antlr 34.1303 34.0900 34.0500 0.0400
    pyparsing 159.7840 159.5700 158.7100 0.8600

    ## Ranking real
    antlr 34.1303 (100.0) ********************
    pyparsing 159.7840 ( 21.4) ****

    ## Matrix real [01] [02]
    [01] antlr 34.1303 100.0 468.2
    [02] pyparsing 159.7840 21.4 100.0
    xuanwu
        5
    xuanwu  
    OP
       2019-05-20 11:52:21 +08:00
    @LokiSharp 多谢. 回头试试 antlr 自带的 python 语法定义. 不过也许遥遥无期了..估计在那之前就会有像样的中文编程环境出现.
    LokiSharp
        6
    LokiSharp  
       2019-05-20 11:57:17 +08:00
    @xuanwu #5 https://github.com/antlr/grammars-v4

    antlr 对大部分语言的语法定义都有社区的实现,你可以用他们直接改个编译器。
    xuanwu
        7
    xuanwu  
    OP
       2019-05-20 12:22:05 +08:00
    @LokiSharp 嗯, 了解. 本来的打算是像周蟒那样包一层, 尽量轻量实现一个中文环境原型.
    LokiSharp
        8
    LokiSharp  
       2019-05-20 12:24:48 +08:00
    @xuanwu #7 antlr 可以生成 C 代码,理论上可以直接挂在 CPython 上面做一次预编译,性能影响也不会太大
    xuanwu
        9
    xuanwu  
    OP
       2019-05-20 14:02:46 +08:00
    @LokiSharp :) 我说的轻量是工作量最小(关键我还不熟 C), 不过谢谢思路哈.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5298 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 344ms · UTC 08:21 · PVG 16:21 · LAX 01:21 · JFK 04:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.