Jaon 是一门融合了 Python 的简洁 与 Java 的严谨 的实验性编程语言。
- 自定义源文件后缀:
.jaon - 自定义编译器:完整的前端(Lexer / Parser / 语义分析)+ 后端(Bytecode 编译器 / 栈式虚拟机)
- 类型系统:静态类型 + 局部类型推断
- 语法风格:Python 式关键字 + Java 式
{}块结构 - 面向对象:类、继承、构造器、访问控制
git clone https://github.com/ExploreMaths/Jaon.git
cd jaon
pip install -e .pip install -e .[dev,docs]python -m jaon run examples/hello.jaon项目根目录也提供了独立的 Windows 可执行文件(无需 Python):
dist/compiler.exe run examples/hello.jaonpython -m jaon replpython scripts/run_tests.py
# 或
python -m unittest discover testscd sphinx-docs
python -m sphinx -b html . _build/html文档也可在 Read the Docs 上自动构建(配置见 .readthedocs.yml)。
需要安装 Nuitka 和 Visual C++ 编译器(通常已随 Visual Studio 或 Build Tools 安装):
pip install nuitka
python scripts/build_exe.py生成的 dist/compiler.exe 可直接运行,不依赖 Python 环境。
PowerShell 安装(无需额外工具):
cd installer
powershell -ExecutionPolicy Bypass -File install.ps1或使用 Inno Setup 生成安装包:
iscc installer/setup.iss安装后,双击任意 .jaon 文件即可自动使用 Jaon 编译器执行。
jaon/
├── __init__.py
├── __main__.py # python -m jaon 入口
├── ast_nodes.py # AST 节点定义
├── lexer.py # 词法分析器
├── parser.py # 递归下降语法分析器
├── analyzer.py # 语义分析 / 类型检查
├── bytecode.py # 字节码与 CodeObject
├── compiler.py # AST -> Bytecode 编译器
├── vm.py # 栈式虚拟机
├── builtins.py # 内建函数
├── cli.py # 命令行接口
└── errors.py # 错误类型
examples/ # 示例程序 (*.jaon)
tests/ # 单元测试
scripts/ # 辅助脚本
var x = 10; // 类型推断为 Int
var y: Float = 3.14; // 显式类型
val pi = 3.14159; // 常量
支持类型:Int、Float、Bool、String、List<T>、Dict<K,V>、类类型、Any。
fun add(a: Int, b: Int): Int {
return a + b;
}
if (x > 0) {
println("positive");
} elif (x < 0) {
println("negative");
} else {
println("zero");
}
while (i < 10) {
i = i + 1;
}
for (n in [1, 2, 3]) {
println(n);
}
class Animal {
public var name: String = "";
constructor(n: String) {
this.name = n;
}
public fun speak(): String {
return "Some sound";
}
}
class Dog extends Animal {
constructor(n: String) {
this.name = n;
}
public fun speak(): String {
return "Woof!";
}
}
var dog = new Dog("Buddy");
println(dog.speak());
fun divide(a: Int, b: Int): Int {
if (b == 0) {
throw "Division by zero";
}
return a / b;
}
try {
divide(10, 0);
} catch (e) {
println("Error: " + e);
}
var nums = [1, 2, 3];
nums[1] = 99;
println(nums[1]);
var scores = {"Alice": 90, "Bob": 85};
println(scores["Alice"]);
print(x)/println(x)input()len(x)range(n)str(x)/int(x)/float(x)type(x)
Jaon 编译器采用经典分层设计:
- Lexer:将
.jaon源码切分为 Token 流。 - Parser:递归下降解析生成 AST。
- Analyzer:类型检查、作用域解析、类成员解析。
- Compiler:AST 编译为自定义 Bytecode。
- VM:基于栈的虚拟机执行 Bytecode。
python -m jaon --help
python -m jaon run file.jaon
python -m jaon repl
python -m jaon dis file.jaon欢迎提交 Issue 和 Pull Request!
提交前请确保:
python -m unittest discover tests
flake8 jaon tests scripts --max-line-length=120 --extend-ignore=E203,W503详见 CONTRIBUTING.md。
推送标签即可触发 GitHub Actions 自动构建 Windows 可执行文件并发布 Release:
git tag v0.1.1
git push origin v0.1.1MIT License
