01

快速开始

三步上手,从安装到运行第一段中文代码。

安装

要求 Python 3.7+,唯一第三方依赖为 lark 解析器。

bash
$ pip install cql-lang

安装后得到两个命令:cql 编译器 / 解释器 与 cqlip 包管理器。

编写 hello.cql

cql
# 斐波那契数列
函数 斐波那契(n):
    如果 n <= 1:
        返回 n
    返回 斐波那契(n - 1) + 斐波那契(n - 2)

打印("第 10 项斐波那契数:", 斐波那契(10))

运行

bash
$ cql run hello.cql
第 10 项斐波那契数: 55
$ cql build hello.cql      # 生成 hello.py
$ cql repl                  # 进入交互式解释器
在 Python 中以库方式使用
python
import cql
code = cql.compile('打印("你好")')
print(code)          # print("你好")
exec(code)