Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ kylin-go Public archive

Kylin Go 是一款基于 Golang 的跨平台高效的编程语言,面相过程,动态脚本语言。Kylin Go is a cross-platform efficient programming language based on Golang (Go interpreter). Can be programmed in Chinese and other languages. Faceted process, direct translation programming language.

License

Notifications You must be signed in to change notification settings

zmh-program/kylin-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ kylin-go

Kylin Go, 一款基于 Golang 的跨平台简洁高效轻量的编程语言

Last Commit Status Dependence License

» Kylin Jvm »

语言特性

  • ✨ 语法简单,易学易用
  • ⚡ 语法高效,编译速度快
  • 📦 内存占用小
  • 🎃 跨平台编译
  • 🎈 国际化支持 (英,中文)
  • Windows
  • Linux Ubuntu
  • MacOS

语言示例

fn main() {
    print("Hello, World!")
}

main()

国际化

use 'chinese'

遍历 变量 在 范围(2) {
    输出(变量, "hi")
     尝试 {
        输出(变量位置, "hi")
    } 捕获 {
        输出("报错:", error)
    }
}

0 hi
报错: ReferenceError(type="ReferenceError", message="Variable 变量位置 not defined", line=7, column=15)
1 hi
报错: ReferenceError(type="ReferenceError", message="Variable 变量位置 not defined", line=7, column=15)
2 hi
报错: ReferenceError(type="ReferenceError", message="Variable 变量位置 not defined", line=7, column=15)

语言规范

1. 赋值计算

a = 1024
a += 2
a -= 4
a *= 8
a **= 12
a /= 16

b = a + 1

2. 函数

fn add(a, b) {
    return a + b
}

fn main() {
    print("Hello, World!")
    return add(1, 2)
}

3. 条件判断

if val > 10 {
    print("val > 10")
} elif val < 10 {
    print("val < 10")
} else {
    print("val = 10")
}

if condition {
    print("condition")
}

if n + 1 != 0 && n {
    print("n & (n + 1) != 0")
}

4. 循环

for i in range(0, 10) {
    print(i)
}
n = 0
while n < 10 {
    print(n)
    n += 1
}

5. 数组

arr = [1, 2, 3, 4, 5]

for i in arr {
  ...
}

for i in ["hello", "world"] {
  print(i)
}

6. 异常截获

for i in range(1,10,2) {
    try {
        print(id)
    } catch {
        print("a", error, "b")
    }
}
$ kylin test.ky
a ReferenceError(message="Variable id not defined", type="ReferenceError",
 line=3, column=22) b
a ReferenceError(message="Variable id not defined", type="ReferenceError",
 line=3, column=22) b
a ReferenceError(message="Variable id not defined", type="ReferenceError",
 line=3, column=22) b
a ReferenceError(message="Variable id not defined", type="ReferenceError",
 line=3, column=22) b
a ReferenceError(message="Variable id not defined", type="ReferenceError",
 line=3, column=22) b
a ReferenceError(message="Variable id not defined", type="ReferenceError",
 line=3, column=22) b

运行

kylin main.ky

.ky 后缀可省略

kylin server

关键字

  • fn 函数
  • if 条件判断
  • else 条件判断
  • for 循环
  • in 循环
  • while 循环
  • return 返回
  • true
  • false
  • null
  • try 异常截获
  • catch 异常截获
  • break 跳出循环
  • continue 跳过本次循环
  • import 导入
  • use 国际化导入语言包

内置函数

  • print 打印
  • input 输入
  • str 字符串
  • int 整数
  • float 浮点数
  • bool 布尔值
  • array 数组
  • range 范围
  • len 长度
  • sum 求和
  • max 最大值
  • min 最小值
  • abs 绝对值
  • all 全部为真
  • any 任意为真
  • join 连接字符串
  • split 分割字符串
  • type 类型
  • time 时间 (ms)
  • sleep 阻塞等待 (ms)
  • timenano CPU 时间 (ns)
  • read 读取文件
  • write 写入文件
  • shell 执行 shell 命令
  • exit 退出程序

语言设计

1. 词法分析

  • Lexer 编译 AST 语法树
  • 词法分析器使用递归下降进行语法分析

2. 语言解释

  • 动态解释器

3. 语言编译

  • 编译器使用 Golang SSA 进行编译

基准测试

性能测试

n = 0
val = 2345
t = time()
while n < 9999999 {
    n += 1
    val **= 1289
    val = n * 999
}

print(time() - t, "ms")
  1. C (GCC) 891.9ms
  2. Golang 1012.5ms
  3. NodeJS 1170.0ms
  4. Kylin Go 1751.2ms
  5. Python 4681.8ms

内存占用 (整体)

n = 0
while n < 1000000 {
    n += 1
    print('hello world')
}
  1. C (GCC) 0.9 MB
  2. Golang 3.2 MB
  3. Kylin Go 8 MB
  4. Node 10 MB
  5. Python 14MB
  6. Kylin JVM 84MB

内存溢出测试

  1. C ❌
  2. Golang ❌
  3. Kylin Go
  4. NodeJS ❌
  5. Python ❌
  6. Kylin JVM ✔

风格对比

C 语言

#include <stdio.h>

int main() {
    int n = 0;
    
    while (n < 1000000) {
        n++;
        printf("hello world\n");
    }
    
    return 0;
}

Golang

package main

import "fmt"

func main() {
	n := 0
	for n < 1000000 {
		n++
		fmt.Println("hello world")
	}
}

Kylin Go

n = 0
while n < 1000000 {
    n += 1
    print('hello world')
}

Kylin JVM

var n = 0
while n < 1000000 {
    n = <n + 1>
    out('hello world')
}

NodeJS

let n = 0;
while (n < 1000000) {
    n++;
    console.log('hello world');
}

Python

n = 0
while n < 1000000:
    n += 1
    print('hello world')

About

Kylin Go 是一款基于 Golang 的跨平台高效的编程语言,面相过程,动态脚本语言。Kylin Go is a cross-platform efficient programming language based on Golang (Go interpreter). Can be programmed in Chinese and other languages. Faceted process, direct translation programming language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages