Skip to main content

bracket

python制作的转译型简单编程语言

1 安装

pip install bracket-lang

2 Hello world

[INFO] ["Hello world!"]

3 基本语法

# main.bracket

# 打印
[INFO] ["这是一段文本"]
[INFO] ["Loading...", end=" "]
[INFO] ["complete"]

# 变量
[VAR] [integer] [2]
[VAR] [floating_point] [3.0]
[VAR] [string] ["abc"]
[VAR] [lst] [[1, 2, 3, 4, 5]]
[VAR] [t] [(1, 2, 3)]
[VAR] [dict] [{1: 1, 2: 4, 3: 9}]
[INFO] [integer, floating_point, string, lst, t, dict]

# 输入
[VAR] [short] [INPUT] ["单行文本"] [False]
[VAR] [long] [INPUT] ["多行文本"] [True]
[INFO] ["您这两次分别输入了: "]
[INFO] [short]
[INFO] [long]

# 分支语句
[VAR] [a] [6]
[IF] [a>0]
    [INFO] ["正数"]
[ELSEIF] [a==0]
    [INFO] ["零"]
[ELSE]
    [INFO] ["负数"]

# 循环
[VAR] [total] [0]
[FOR] [i] [1, 101, 1]
    [VAR] [total] [total+i]
[INFO] ["1~100的和:", total]
[VAR] [i] [0]
[WHILE] [i<10]
    [INFO] [i]
    [VAR] [i] [i+1]
[LOOP]
    [INFO] [i]
    [IF] [i==100]
        [BREAK]
    [VAR] [i] [i+1]

# 函数
[FUNC] [longest] [x, y]
    [IF] [len(x)>len(y)]
        [RETURN] [x]
    [RETURN] [y]
[INFO] [longest("hi", "hello")]

# 类
[CLASS] [Calculator] [object]
    [FUNC] [add] [a, b]
        [RETURN] [a+b]
    [FUNC] [subtract] [a, b]
        [RETURN] [a-b]
    [FUNC] [mul] [a, b]
        [RETURN] [a*b]
    [FUNC] [division] [a, b]
        [IF] [b==0]
            [ERROR] ["Cannot devide by zero."]
        [RETURN] [a/b]
    [FUNC] [percent] [a]
        [RETURN] [a/100]
[INFO] [Calculator.add(1, 1)]

# 警告
[WARN] ["警告信息"]

# GUI
[USE] [GUI]
[VAR] [root] [Base()]
root.title("Hello bracket")
root.geometry("300x200")
[VAR] [label] [Tag(root, text="Hello, World!")]
label.pack()
root.mainloop()

# 数学计算
[USE] [MATH]
[INFO] [sqrt(2)] # 1.414213562373095
[INFO] [comb(1, 1)] # 1
[INFO] [prod([1, 2])] # 2
[INFO] [sumprod([6, 6], [7, 7])] # 84

输出:

这是一段文本
Loading... complete
2 3.0 abc [1, 2, 3, 4, 5] (1, 2, 3) {1: 1, 2: 4, 3: 9}
单行文本: 1
多行文本: 2
3
您这两次分别输入了
1
2
3
正数
5050
1
2
3
...
100
hello
2
[yellow]警告信息[/yellow]
(显示窗口)
(点击窗口上的叉)
1.414213562373095
1
2
84

窗口显示: 打包:

bracket pack main.bracket

4 命令行工具参数

参数 用法
--help -h 帮助
build 转译
run 转译运行
pack 打包成二进制

6 注意事项

  1. INFO的参数与python的print基本相同
  2. [VAR] [lst] [[1, 2, 3, 4, 5]]是真正的列表, [VAR] [t] [1, 2, 3, 4, 5]是元组
  3. FOR必须要写三个参数
  4. [LOOP]是无限循环, 与[WHILE] [True]等效
  5. 变量名不能与bracket关键字和python关键字重名
  6. bracket语言不兼容python的列表推导式, 三元表达式等
  7. 数学标准库需编译, 可能需要几十秒钟的时间, 请耐心等待
  8. bracket内置轻量编辑器bkted

Metadata

Release files for bracket-lang 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bracket-lang 0.5.0
File Size Uploaded Provenance Actions
bracket_lang-0.5.0.tar.gz 21.0 kB Without provenance Details for bracket_lang-0.5.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bracket-lang 0.5.0
File Interpreter ABI Platform Actions
bracket_lang-0.5.0-cp314-cp314-android_24_arm64_v8a.whl CPython 3.14 CPython 3.14 Android API level 24+ ARM64 v8a Details for bracket_lang-0.5.0-cp314-cp314-android_24_arm64_v8a.whl
bracket_lang-0.5.0-cp312-cp312-manylinux_2_38_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.38+ ARM64 Details for bracket_lang-0.5.0-cp312-cp312-manylinux_2_38_aarch64.whl

Total release size: 2.2 MB

Release files / bracket_lang-0.5.0.tar.gz

Download URL bracket_lang-0.5.0.tar.gz
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a36b3c5dcc36a674b4b0987c1e399774edf453a173cb2b6fd6729b5189c2a669
BLAKE2b-256 checksum
How to use checksums
6e0bbee4a97c9a6dc3a6d7ddff082cc7e336a83e38f3e265820b41b4e16a4aad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bracket_lang-0.5.0-cp314-cp314-android_24_arm64_v8a.whl

Download URL bracket_lang-0.5.0-cp314-cp314-android_24_arm64_v8a.whl
Size 787.8 kB
Tags Android API level 24+ ARM64 v8a CPython 3.14
SHA-256 checksum
How to use checksums
1d762d354cffee35de39cc0e3a7ba09b2fd30c9d50022000197c822e8a86ca0e
BLAKE2b-256 checksum
How to use checksums
9520b5dce54ec770031bcd69448ad6945a862a0d3546d025f74a020605b65580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bracket_lang-0.5.0-cp312-cp312-manylinux_2_38_aarch64.whl

Download URL bracket_lang-0.5.0-cp312-cp312-manylinux_2_38_aarch64.whl
Size 1.4 MB
Tags CPython 3.12 Linux glibc 2.38+ ARM64
SHA-256 checksum
How to use checksums
55bd149d5c839d6a507135089337ff1620248b44dcef457b8a090c26ecdb654d
BLAKE2b-256 checksum
How to use checksums
dc6d93d3a8d2378d4fd8b36a6c52671227753a5a2f327cf7da984854f6251efc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for bracket-lang 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page