#lexer #compiler #language #parser #intersepter

app betadin

用于研究目的的简单编程语言

4个版本

0.2.0 2023年9月27日
0.1.2 2023年9月23日
0.1.1 2023年9月19日
0.1.0 2023年9月19日

#334编程语言

21 每月下载量

MIT 许可证

125KB
3K SLoC

Betadin

Betadin是一种用于研究目的的简单编程语言,用Rust编写。

功能

  • 变量和常量
  • 函数
  • 条件命令
  • 常见运算符
  • for和while循环
  • 原型
  • 内置模块和函数
  • 等等

用法

  1. 使用cargo安装betadin
cargo install betadin
  1. 使用betadin cli运行文件
betadin path.ak

示例


# variables and constants

let name1 = "something"; # can be change
const name2 = "something"; # cannot be change



# functions

fn add(x, y) {
    return x + y;
}

println(add(2, 5)); # prints 7;



# conditional commands and operators

let x = 10;

# if statement
if x >= 10 || true {
    println("if block");
} else {
    println("else block");
}

# if expression
let y = if x == 10 {
    return "if block";
} else {
    return "else block";
};

println(y); # prints "if block"



# for and while loops

for i in 1..10 {
    println(i); # prints 1 to 10
}

let x = 0;
while x <= 10 {
    if x == 5 {
        break;
    }
    println(x); # prints 0 to 4
    x = x + 1;
}



# builtin modules and prototypes
# betadin have some builtin modules like "fs", "system", "env"

# system module

import std::system;
println(system::platform());

# or

import std::system::{platform};
println(platform());

# or 

println(std::system::platform());

# file system

import std::fs;

const content = fs::read_file("path"); # read

# reading file content line
# file content is a string so we can use string methods

println(content.lines()); # prints array of lines
println(content.len()); # prints number of chars
println(content.lines().len()); # prints number of lines;

# more methods
fs::write_file("path");
fs::read_dir("path");
fs::remove_file("path");
# and more


# env module
import std::env;
const args = env::args(); # getting arguments

for arg in args {
    println(arg);
}


# custom module
module custom {
    const name = "custom";
    module inner {
        fn get_parent_name() {
            return custom::inner::name;
        }
    }
}

println(custom::inner::get_parent_name()); # custom

# or 
import custom::inner::{get_parent_name};
println(get_parent_name()) # custom

更多示例: https://github.com/Aidin53-kh/betadin/examples

依赖关系

~2.7–5.5MB
~89K SLoC