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()
输出:
这是一段文本
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]
打包:
bracket pack main.bracket
4 命令行工具参数
| 参数 | 用法 |
|---|---|
--help -h |
帮助 |
build |
转译 |
run |
转译运行 |
pack |
打包成二进制 |
6 注意事项
INFO的参数与python的print基本相同[VAR] [lst] [[1, 2, 3, 4, 5]]是真正的列表,[VAR] [t] [1, 2, 3, 4, 5]是元组FOR必须要写三个参数[LOOP]是无限循环, 与[WHILE] [True]等效- 变量名不能与bracket关键字和python关键字重名
- bracket语言不兼容python的列表推导式, 三元表达式等
- bracket内置轻量编辑器bkted
Metadata
Release files for bracket-lang 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bracket_lang-0.4.0.tar.gz | 17.1 kB | Without provenance | Details for bracket_lang-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bracket_lang-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for bracket_lang-0.4.0-py3-none-any.whl |
Total release size: 31.5 kB
Release files / bracket_lang-0.4.0.tar.gz
| Download URL | bracket_lang-0.4.0.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b77c250533719aca27183ee466f9d8f8ecc68cbbbf37ba09d34799eb0bfb78a
|
|
BLAKE2b-256 checksum How to use checksums |
92ed5d0e123219e15c1c6358dcfaed0d4d2a07111d0e86035adf2b579fc6fd4f
|
| 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.4.0-py3-none-any.whl
| Download URL | bracket_lang-0.4.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
169446ea37f5a538e1e7e0e217ecfc0740cfb1a27f99b0e2937613c0cb32acc2
|
|
BLAKE2b-256 checksum How to use checksums |
6e3fafc716a0c945bdfc94cbf4b433bf217a093686f97d4fa9d144562da56d8b
|
| 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.4.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.