mahmoudimus / AIL

the AIL Programming Language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AIL 2.3 alpha 2

AIL 2.3 Diona 版本更新内容

AIL 2.2 Klee 版本更新内容

AIL badge python badge version badge license badge

AIL 是一门开源的运行在 Python 虚拟机上的面向对象的编程语言。支持 Python 的大多数特性的同时,还额外增加了如 match 表达式,匿名函数,名称空间等 AIL 自身的特性。

环境需求

具有完整标准库的 Python3.6+, 最好是 3.7 ~ 3.8 版本

AIL 需要运行在具有完整标准库的 Python 环境上,版本最低不低于3.5,3.5 ~ 3.6 之间的 Python 版本不确保有正常的 AIL 使用体验。若要取得最好的 AIL 体验,请使用 3.7 ~ 3.8 版本的 Python, 3.9+ 的 Python 版本运行 AIL 并不稳定。

推荐使用 cpython 解释器,其他 Python 解释器并未进行过测试。

Hello World

Hello World with one statement

print 'Hello World';

..or..

console.writeln('Hello World!');

Hello World in lambda

(() -> console.writeln('Hello World'))();

Hello World in function

func helloWorld() {
    print "Hello World!";
}

helloWorld();

Hello World in anonymous function

(func () {
    print "Hello World!";
})();

Hello World in class

class Hello {
    func helloWorld(self) {
        print "Hello World!";
    }
}

Hello().helloWorld();

斐波那契数列

func fib(n) {
    if n == 1 or n == 2 {
        return 1;
    } elif n >= 2 {
        return fib(n - 2) + fib(n - 1);
    }
}

主要语言特性

以下例子均已在 AIL 2.3 版本下通过编译

更多的 for 语句

for i = 0, j = len(x); i < len(x); i += 1, j -= 1 {
    // ...
}

for {
    // forever...
}

foreach i in range(100) {
    // ...
}

namespace 名称空间

namespace Vegetables {
    cabbage = 'cabbage';
    leaf_mustard = 'mustard';
}


namespace Fruits {
    apple = 'apple';
    tomato = 'tomato';
}


print 'An %s a day keeps the doctor away' % Fruits.apple;

强大的 match 表达式

name = match lang_name {
    'Python': 'py',
    'Java': 'java',
    'AIL': 'ail',
}

(match point {
    Point! { x: 5, y: 6 }: () -> {
        // handle it...
    },
    else: () -> {
        // handle it...
    }
})();

通过引用 global 变量在 local 域中定义同名变量

a = 10;

func f() {
    a := a;
}

与 Python 协作

在 AIL 中可以直接导入 Python 模块,使用类似 Python 的 import 语句:

import! os.path as ospath;
import! numpy as np;
from PIL import Image;


Image.open('klee.jpg').show();

亦或是在 AIL 程序中直接插入 Python 代码:

func gen(n) {
    #return [x**n for x in range(n)]
}


print gen(5);

安装 AIL

运行 AIL 事先准备好的 setup.py 可以非常快速地在您的电脑上配置好 AIL。

python3 setup.py install

在终端中输入:

ail

或者

python3 -m ail

Windows下应确保 {PYTHON_HOME}/Script/ 已添加到 PATH 中 Linux/Mac OS 下应确保当前用户的 bin 目录已添加到 PATH 中

若进入 AIL 的交互环境,则安装成功。

文档

AIL 的文档仍然在完善中。具体的进度可以在 /docs/ 中查看。

AIL 语句

文档 AIL语句 简要地描述了 AIL 的语句

AIL 代码转换细节

想要了解 AIL 代码是如何转换成 Python 语法树的,可以查看:

ail_in_python

VIM 语法高亮支持

AIL 为 vim 专门编写了其语法高亮文件,写代码的时候妈妈再也不会担心敲错关键字了!

提供了如下高亮支持:

  • 关键字
  • 字符串、数字
  • 基本类型注解
  • AIL 内置函数、常量 (并未高亮 Python 的内置函数与常量)

vim highlight

配置

  1. plugin/vim/syntax/ail.vimplugin/vim/ftdetect/ail.vim 分别复制到 {VIM_HOME}/syntax/{VIM_HOME}/ftdetect/
  2. 重新启动 vim 即可

tree.txt

这是最早期 AIL 语法分析器生成的语法树

对应的程序应该可以在早期 commit 中找到

About

the AIL Programming Language

License:GNU General Public License v3.0


Languages

Language:Python 95.8%Language:Vim Script 4.0%Language:Shell 0.1%Language:Batchfile 0.0%