Initial commit: Oraset B-5
Build and Package Oraset / build (macos-latest) (push) Waiting to run
Build and Package Oraset / build (ubuntu-latest) (push) Waiting to run
Build and Package Oraset / build (windows-latest) (push) Waiting to run
Build and Package Oraset / release (push) Blocked by required conditions
Build and Package Oraset / build (macos-latest) (push) Waiting to run
Build and Package Oraset / build (ubuntu-latest) (push) Waiting to run
Build and Package Oraset / build (windows-latest) (push) Waiting to run
Build and Package Oraset / release (push) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
# 入门指南
|
||||
|
||||
本指南将帮助您快速安装和配置 Oraset 编程语言 B-5 版本环境,并运行您的第一个程序。
|
||||
|
||||
## 安装 Oraset
|
||||
|
||||
### macOS
|
||||
|
||||
```bash
|
||||
curl https://oraset.parlz.com/download/sh/install.sh | bash
|
||||
```
|
||||
|
||||
### Linux
|
||||
|
||||
```bash
|
||||
curl https://oraset.parlz.com/download/sh/install-linux.sh | bash
|
||||
```
|
||||
|
||||
或手动下载 <a href="https://oraset.parlz.com/download/deb/Oraset-B5.deb" download="oraset.deb" >oraset.deb</a>,然后运行:
|
||||
```bash
|
||||
sudo dpkg -i oraset.deb
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
下载 <a href="https://oraset.parlz.com/download/exe/Oraset-B5.exe" download="oraset.exe" >oraset.exe</a> 并添加到系统 PATH。
|
||||
|
||||
## 验证安装
|
||||
|
||||
```bash
|
||||
oraset -v
|
||||
```
|
||||
|
||||
应该显示:"B-5"
|
||||
|
||||
## 运行第一个程序
|
||||
|
||||
### 步骤 1:创建脚本文件
|
||||
|
||||
创建一个名为 `hello.ora` 的文件,内容如下:
|
||||
|
||||
```oraset
|
||||
print("Hello, World!");
|
||||
```
|
||||
|
||||
### 步骤 2:运行脚本
|
||||
|
||||
```bash
|
||||
oraset hello.ora
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Hello, World!
|
||||
```
|
||||
|
||||
## 交互模式
|
||||
|
||||
Oraset B-5 支持 REPL 交互模式:
|
||||
|
||||
```bash
|
||||
oraset -i
|
||||
```
|
||||
|
||||
或
|
||||
|
||||
```bash
|
||||
oraset --interactive
|
||||
```
|
||||
|
||||
进入交互模式后,您可以直接输入代码并立即看到结果:
|
||||
|
||||
```
|
||||
Oraset B-5 REPL
|
||||
Type 'exit' or 'quit' to exit.
|
||||
> var x = 10
|
||||
> print(x)
|
||||
10
|
||||
> exit
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
### Q: 命令找不到?
|
||||
|
||||
A: 确保 oraset 已添加到系统 PATH,并重新打开终端。
|
||||
|
||||
### Q: 如何退出交互模式?
|
||||
|
||||
A: 输入 `exit` 或 `quit` 即可退出。
|
||||
|
||||
### Q: 脚本执行完成后自动退出?
|
||||
|
||||
A: 是的,脚本执行完成后自动退出,无需手动操作。
|
||||
|
||||
---
|
||||
|
||||
Oraset Project © 2026
|
||||
@@ -0,0 +1,212 @@
|
||||
# 语言参考
|
||||
|
||||
Oraset 编程语言 B-5 版本的完整语法参考文档,包含变量、数据类型、运算符和控制流等核心特性。
|
||||
|
||||
## 变量
|
||||
|
||||
### 声明变量
|
||||
|
||||
```oraset
|
||||
var x = 10;
|
||||
var name = "test";
|
||||
var pi = 3.14;
|
||||
var flag;
|
||||
```
|
||||
|
||||
### 修改变量
|
||||
|
||||
```oraset
|
||||
x = 20;
|
||||
name = "new name";
|
||||
```
|
||||
|
||||
### 复合赋值
|
||||
|
||||
```oraset
|
||||
x += 5;
|
||||
x -= 3;
|
||||
x *= 2;
|
||||
x /= 2;
|
||||
x %= 3;
|
||||
```
|
||||
|
||||
### 自增自减
|
||||
|
||||
```oraset
|
||||
x++;
|
||||
x--;
|
||||
```
|
||||
|
||||
## 数据类型
|
||||
|
||||
- **数字**:整数和浮点数,如 `42`、`3.14`
|
||||
- **字符串**:用双引号或单引号包围,如 `"Hello"`、`'World'`
|
||||
- **数组**:用方括号定义,如 `[1, 2, 3]`
|
||||
|
||||
## 数组
|
||||
|
||||
### 创建数组
|
||||
|
||||
```oraset
|
||||
var arr = [10, 20, 30, 40, 50];
|
||||
var empty = array(5);
|
||||
```
|
||||
|
||||
### 访问数组元素
|
||||
|
||||
```oraset
|
||||
print(arr[0]);
|
||||
arr[2] = 35;
|
||||
```
|
||||
|
||||
### 数组长度
|
||||
|
||||
```oraset
|
||||
var len = arrlen(arr);
|
||||
```
|
||||
|
||||
## 运算符
|
||||
|
||||
### 算术运算符
|
||||
|
||||
```oraset
|
||||
+ // 加法
|
||||
- // 减法
|
||||
* // 乘法
|
||||
/ // 除法
|
||||
% // 取模
|
||||
```
|
||||
|
||||
### 比较运算符
|
||||
|
||||
```oraset
|
||||
== // 等于
|
||||
!= // 不等于
|
||||
> // 大于
|
||||
< // 小于
|
||||
>= // 大于等于
|
||||
<= // 小于等于
|
||||
```
|
||||
|
||||
### 逻辑运算符
|
||||
|
||||
```oraset
|
||||
&& // 逻辑与
|
||||
|| // 逻辑或
|
||||
! // 逻辑非
|
||||
```
|
||||
|
||||
## 输出
|
||||
|
||||
### print 函数
|
||||
|
||||
```oraset
|
||||
print("Hello"); // 输出并换行
|
||||
print("No newline", "nel"); // 输出不换行
|
||||
print("A", "B", 123); // 多个参数用空格分隔
|
||||
print(arr); // 打印数组
|
||||
```
|
||||
|
||||
## 控制流
|
||||
|
||||
### 条件语句
|
||||
|
||||
```oraset
|
||||
if (x > 10) {
|
||||
print("x is big");
|
||||
} else {
|
||||
print("x is small");
|
||||
}
|
||||
```
|
||||
|
||||
### 循环语句
|
||||
|
||||
```oraset
|
||||
while (x < 100) {
|
||||
print(x);
|
||||
x++;
|
||||
}
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
print(i);
|
||||
}
|
||||
```
|
||||
|
||||
### 函数定义
|
||||
|
||||
```oraset
|
||||
function add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
add(5, 3);
|
||||
```
|
||||
|
||||
## 内置函数
|
||||
|
||||
### 数学函数
|
||||
|
||||
```oraset
|
||||
abs(x) // 绝对值
|
||||
sqrt(x) // 平方根
|
||||
sin(x) // 正弦
|
||||
cos(x) // 余弦
|
||||
tan(x) // 正切
|
||||
pow(x, y) // x的y次方
|
||||
log(x) // 自然对数
|
||||
floor(x) // 向下取整
|
||||
ceil(x) // 向上取整
|
||||
round(x) // 四舍五入
|
||||
int(x) // 转为整数
|
||||
float(x) // 转为浮点数
|
||||
rand() // 0-1随机数
|
||||
rand(n) // 0-n随机数
|
||||
time() // 当前时间戳
|
||||
```
|
||||
|
||||
### 字符串函数
|
||||
|
||||
```oraset
|
||||
len(str) // 字符串长度
|
||||
num(str) // 字符串转数字
|
||||
str(num) // 数字转字符串
|
||||
```
|
||||
|
||||
### 数组函数
|
||||
|
||||
```oraset
|
||||
array(size) // 创建指定大小的数组
|
||||
arrlen(arr) // 获取数组长度
|
||||
```
|
||||
|
||||
### 输入函数
|
||||
|
||||
```oraset
|
||||
input() // 读取用户输入
|
||||
input("提示:") // 带提示的输入
|
||||
```
|
||||
|
||||
## 文件配置
|
||||
|
||||
### sg 语法
|
||||
|
||||
```oraset
|
||||
sg<nel>
|
||||
print("All lines no newline");
|
||||
print("Still same line");
|
||||
```
|
||||
|
||||
`sg<nel>` 设置整个文件的 print 默认不换行。
|
||||
|
||||
## 注释
|
||||
|
||||
```oraset
|
||||
# 单行注释
|
||||
// 单行注释
|
||||
/* 多行
|
||||
注释 */
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Oraset Project © 2026
|
||||
@@ -0,0 +1,133 @@
|
||||
# 贪吃蛇游戏
|
||||
|
||||
这是一个用 Oraset B-5 编写的控制台贪吃蛇游戏!
|
||||
|
||||
## 游戏说明
|
||||
|
||||
使用方向键控制蛇的移动方向,吃食物得分。
|
||||
|
||||
## 运行方法
|
||||
|
||||
```bash
|
||||
oraset examples/snake.ora
|
||||
```
|
||||
|
||||
## 代码
|
||||
|
||||
```oraset
|
||||
// snake.ora - 贪吃蛇游戏
|
||||
// 使用 w/a/s/d 或方向键控制
|
||||
// Oraset B-5 版本 - 使用数组存储蛇的位置
|
||||
|
||||
var width = 40;
|
||||
var height = 20;
|
||||
var speed = 150;
|
||||
var game_over = 0;
|
||||
var score = 0;
|
||||
|
||||
var snake_x = [10, 9, 8];
|
||||
var snake_y = [10, 10, 10];
|
||||
var snake_len = 3;
|
||||
|
||||
var food_x = 25;
|
||||
var food_y = 10;
|
||||
|
||||
var direction = 1;
|
||||
var next_direction = 1;
|
||||
|
||||
function generate_food() {
|
||||
food_x = int(rand() * (width - 4)) + 2;
|
||||
food_y = int(rand() * (height - 4)) + 2;
|
||||
}
|
||||
|
||||
generate_food();
|
||||
|
||||
while (game_over == 0) {
|
||||
direction = next_direction;
|
||||
|
||||
var new_head_x = snake_x[0];
|
||||
var new_head_y = snake_y[0];
|
||||
|
||||
if (direction == 0) new_head_y--;
|
||||
if (direction == 1) new_head_x++;
|
||||
if (direction == 2) new_head_y++;
|
||||
if (direction == 3) new_head_x--;
|
||||
|
||||
if (new_head_x <= 0 || new_head_x >= width - 1 ||
|
||||
new_head_y <= 0 || new_head_y >= height - 1) {
|
||||
game_over = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
while (i < snake_len) {
|
||||
if (new_head_x == snake_x[i] && new_head_y == snake_y[i]) {
|
||||
game_over = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (game_over == 1) break;
|
||||
|
||||
if (new_head_x == food_x && new_head_y == food_y) {
|
||||
score++;
|
||||
snake_len++;
|
||||
generate_food();
|
||||
}
|
||||
|
||||
i = snake_len - 1;
|
||||
while (i > 0) {
|
||||
snake_x[i] = snake_x[i - 1];
|
||||
snake_y[i] = snake_y[i - 1];
|
||||
i--;
|
||||
}
|
||||
|
||||
snake_x[0] = new_head_x;
|
||||
snake_y[0] = new_head_y;
|
||||
|
||||
var y = 0;
|
||||
while (y < height) {
|
||||
var x = 0;
|
||||
while (x < width) {
|
||||
var is_snake = 0;
|
||||
var is_food = 0;
|
||||
|
||||
i = 0;
|
||||
while (i < snake_len) {
|
||||
if (x == snake_x[i] && y == snake_y[i]) {
|
||||
is_snake = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (x == food_x && y == food_y) {
|
||||
is_food = 1;
|
||||
}
|
||||
|
||||
if (is_snake == 1) {
|
||||
print("O", "nel");
|
||||
} else if (is_food == 1) {
|
||||
print("*", "nel");
|
||||
} else if (x == 0 || x == width - 1 || y == 0 || y == height - 1) {
|
||||
print("-", "nel");
|
||||
} else {
|
||||
print(" ", "nel");
|
||||
}
|
||||
x++;
|
||||
}
|
||||
print("");
|
||||
y++;
|
||||
}
|
||||
|
||||
print("分数:", score, " | 长度:", snake_len);
|
||||
print("w=上 a=左 s=下 d=右");
|
||||
}
|
||||
|
||||
print("游戏结束! 最终分数:", score);
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
这个版本使用了 Oraset B-5 的数组功能,代码更加简洁高效。
|
||||
蛇的身体现在存储在数组中,可以无限增长。
|
||||
@@ -0,0 +1,220 @@
|
||||
# 教程
|
||||
|
||||
通过实际示例学习 Oraset 编程语言 B-5 版本,从基础输出到循环和条件判断。
|
||||
|
||||
## 示例 1:基本输出
|
||||
|
||||
```oraset
|
||||
// hello.ora
|
||||
print("Welcome to Oraset B-5!");
|
||||
print("This is my first program.");
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Welcome to Oraset B-5!
|
||||
This is my first program.
|
||||
```
|
||||
|
||||
## 示例 2:变量和计算
|
||||
|
||||
```oraset
|
||||
// calc.ora
|
||||
var a = 10;
|
||||
var b = 20;
|
||||
var sum = a + b;
|
||||
print("The sum is:", sum);
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
The sum is: 30
|
||||
```
|
||||
|
||||
## 示例 3:条件判断
|
||||
|
||||
```oraset
|
||||
// grade.ora
|
||||
var score = 85;
|
||||
if (score >= 60) {
|
||||
print("Pass!");
|
||||
} else {
|
||||
print("Fail!");
|
||||
}
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Pass!
|
||||
```
|
||||
|
||||
## 示例 4:循环
|
||||
|
||||
```oraset
|
||||
// loop.ora
|
||||
var i = 1;
|
||||
while (i <= 5) {
|
||||
print("Count:", i);
|
||||
i++;
|
||||
}
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Count: 1
|
||||
Count: 2
|
||||
Count: 3
|
||||
Count: 4
|
||||
Count: 5
|
||||
```
|
||||
|
||||
## 示例 5:不换行输出
|
||||
|
||||
```oraset
|
||||
// inline.ora
|
||||
print("Loading", "nel");
|
||||
print(".");
|
||||
print(".");
|
||||
print(" Done!");
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Loading...
|
||||
Done!
|
||||
```
|
||||
|
||||
## 示例 6:文件级配置
|
||||
|
||||
```oraset
|
||||
// no_newline.ora
|
||||
sg<nel>
|
||||
print("All");
|
||||
print("on");
|
||||
print("same");
|
||||
print("line");
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Allonsameline
|
||||
```
|
||||
|
||||
## 示例 7:数组
|
||||
|
||||
```oraset
|
||||
// array.ora
|
||||
var arr = [10, 20, 30, 40, 50];
|
||||
print("Array:", arr);
|
||||
print("First element:", arr[0]);
|
||||
print("Array length:", arrlen(arr));
|
||||
|
||||
arr[2] = 35;
|
||||
print("Modified array:", arr);
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Array: [10, 20, 30, 40, 50]
|
||||
First element: 10
|
||||
Array length: 5
|
||||
Modified array: [10, 20, 35, 40, 50]
|
||||
```
|
||||
|
||||
## 示例 8:复合赋值
|
||||
|
||||
```oraset
|
||||
// compound.ora
|
||||
var x = 10;
|
||||
x += 5;
|
||||
print("x += 5:", x);
|
||||
x *= 2;
|
||||
print("x *= 2:", x);
|
||||
x -= 3;
|
||||
print("x -= 3:", x);
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
x += 5: 15
|
||||
x *= 2: 30
|
||||
x -= 3: 27
|
||||
```
|
||||
|
||||
## 示例 9:函数
|
||||
|
||||
```oraset
|
||||
// function.ora
|
||||
function add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function multiply(a, b) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
var result = add(5, 3);
|
||||
print("5 + 3 =", result);
|
||||
|
||||
result = multiply(4, 6);
|
||||
print("4 * 6 =", result);
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
5 + 3 = 8
|
||||
4 * 6 = 24
|
||||
```
|
||||
|
||||
## 示例 10:数学函数
|
||||
|
||||
```oraset
|
||||
// math.ora
|
||||
var pi = 3.14159;
|
||||
print("sin(pi/2) =", sin(pi/2));
|
||||
print("sqrt(16) =", sqrt(16));
|
||||
print("abs(-42) =", abs(-42));
|
||||
print("pow(2, 8) =", pow(2, 8));
|
||||
print("rand() =", rand());
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
sin(pi/2) = 1
|
||||
sqrt(16) = 4
|
||||
abs(-42) = 42
|
||||
pow(2, 8) = 256
|
||||
rand() = 0.123456
|
||||
```
|
||||
|
||||
## 练习题
|
||||
|
||||
### 练习 1
|
||||
|
||||
编写一个程序,计算 1 到 10 的和。
|
||||
|
||||
### 练习 2
|
||||
|
||||
编写一个程序,判断一个数是奇数还是偶数。
|
||||
|
||||
### 练习 3
|
||||
|
||||
编写一个程序,输出 99 乘法表的一行。
|
||||
|
||||
### 练习 4
|
||||
|
||||
编写一个程序,使用数组存储 5 个数字,然后计算它们的平均值。
|
||||
|
||||
---
|
||||
|
||||
Oraset Project © 2026
|
||||
Reference in New Issue
Block a user