Skip to content
This repository was archived by the owner on Jan 8, 2023. It is now read-only.

Commit e37a0bb

Browse files
author
ApsarasX
committed
docs: add more detail in README.md and README-zh_CN.md
1 parent e0156a3 commit e37a0bb

File tree

2 files changed

+253
-8
lines changed

2 files changed

+253
-8
lines changed

README-zh_CN.md

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,130 @@
1-
# StaticScript
1+
<h1 align="center">StaticScript</h1>
22

3-
> StaticScript是一门语法类似于TypeScript的编程语言.
3+
<div align="center">
44

5-
## Status
5+
StaticScript是一门类TypeScript的静态强类型编程语言
66

7-
![Build](https://github.com/StaticScript/StaticScript/workflows/Build/badge.svg)
7+
![Github Workflow Status](https://img.shields.io/github/workflow/status/StaticScript/StaticScript/Build?style=flat-square)
8+
![Platform](https://img.shields.io/badge/platform-linux--64%20%7C%20macos--64-brightgreen?style=flat-square)
9+
![License](https://img.shields.io/github/license/StaticScript/StaticScript?style=flat-square)
10+
11+
![GitHub Repo stars](https://img.shields.io/github/stars/StaticScript/StaticScript?style=flat-square)
12+
![GitHub forks](https://img.shields.io/github/forks/StaticScript/StaticScript?style=flat-square)
13+
![GitHub issues](https://img.shields.io/github/issues-raw/StaticScript/StaticScript?style=flat-square)
14+
![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/StaticScript/StaticScript?style=flat-square)
15+
16+
![GitHub Repository Size](https://img.shields.io/github/repo-size/StaticScript/StaticScript?style=flat-square)
17+
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/StaticScript/StaticScript?style=flat-square)
18+
![GitHub top language](https://img.shields.io/github/languages/top/StaticScript/StaticScript?style=flat-square)
19+
20+
[English](./README.md) | 简体中文
21+
22+
</div>
23+
24+
25+
## 语言特性概要
26+
27+
### 变量和常量的声明
28+
29+
下面是一些变量声明
30+
31+
```typescript
32+
let flag: boolean = true;
33+
let count: number = 20;
34+
let content: string = "Hello World";
35+
```
36+
37+
得益于StaticScript的类型推导特性, 我们可以把上面的变量声明写成下面这样, 它们是等效的
38+
39+
```typescript
40+
let flag = true;
41+
let count = 20;
42+
let content = "Hello World";
43+
```
44+
45+
StaticScript的编译器可以巧妙地从变量的初始值推导出变量的类型
46+
47+
除了使用`let`声明变量外,还可以使用`const`声明常量
48+
49+
```typescript
50+
const name = "StaticScript";
51+
const age = 1;
52+
const developing = true;
53+
```
54+
55+
`let``const`的区别在于`const`声明的常量不能被修改
56+
57+
### 变量运算
58+
59+
可以使用多种多样的运算符对变量执行操作,包括算术运算、按位运算、逻辑运算、关系运算、赋值和字符串连接
60+
61+
```typescript
62+
let a = 1;
63+
let b = 2;
64+
65+
// 加减乘除
66+
let sum = a + b;
67+
let diff = a - b;
68+
let product = a * b;
69+
let quotient = a / b;
70+
71+
a = a << 1; // 等效于 `a <<= 1`
72+
b = b >> 1; // 等效于 `b >>= 1`
73+
74+
let year = "2020", month = "08", day = "06";
75+
let birthday = year + "/" + month + "/" + day;
76+
```
77+
78+
### 控制流
79+
80+
```typescript
81+
let a = 1;
82+
let b = 100;
83+
if (a < b) {
84+
ss_println_string("b更大");
85+
} else {
86+
ss_println_string("b不比a大");
87+
}
88+
89+
90+
let max = a;
91+
if (a < b) {
92+
max = b;
93+
}
94+
```
95+
96+
### 循环
97+
98+
StaticScript支持使用`while`语句和`for`语句执行一些重复的操作
99+
100+
```typescript
101+
// 计算[1, 100]间所有偶数的和
102+
let sum1 = 0;
103+
let i = 1;
104+
while(i <= 100) {
105+
if (i % 2 == 0) {
106+
sum1 += i;
107+
}
108+
}
109+
110+
111+
// 计算[1, 100]间所有整数的和
112+
let sum2 = 0;
113+
for(let i = 1; i <= 100; i++) {
114+
sum2 += i;
115+
}
116+
```
117+
118+
### 函数
119+
120+
StaticScript支持在顶级范围内定义函数并在任何作用域内使用函数
121+
122+
```typescript
123+
function add(a: number, b: number): number {
124+
return a + b;
125+
}
126+
```
127+
128+
StaticScript可以通过return语句的表达式来推断返回类型, 因此上面的函数可以省略返回类型
129+
130+
需要注意的是,函数的参数类型必须显式声明, 不能省略

README.md

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,129 @@
1-
# StaticScript
1+
<h1 align="center">StaticScript</h1>
22

3-
> StaticScript is a statically typed and strongly typed programming language, syntactically like TypeScript.
3+
<div align="center">
44

5-
## Status
5+
StaticScript is a statically typed and strongly typed programming language, syntactically like TypeScript.
66

7-
![Build](https://github.com/StaticScript/StaticScript/workflows/Build/badge.svg)
7+
![Github Workflow Status](https://img.shields.io/github/workflow/status/StaticScript/StaticScript/Build?style=flat-square)
8+
![Platform](https://img.shields.io/badge/platform-linux--64%20%7C%20macos--64-brightgreen?style=flat-square)
9+
![License](https://img.shields.io/github/license/StaticScript/StaticScript?style=flat-square)
10+
11+
![GitHub Repo stars](https://img.shields.io/github/stars/StaticScript/StaticScript?style=flat-square)
12+
![GitHub forks](https://img.shields.io/github/forks/StaticScript/StaticScript?style=flat-square)
13+
![GitHub issues](https://img.shields.io/github/issues-raw/StaticScript/StaticScript?style=flat-square)
14+
![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/StaticScript/StaticScript?style=flat-square)
15+
16+
![GitHub Repository Size](https://img.shields.io/github/repo-size/StaticScript/StaticScript?style=flat-square)
17+
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/StaticScript/StaticScript?style=flat-square)
18+
![GitHub top language](https://img.shields.io/github/languages/top/StaticScript/StaticScript?style=flat-square)
19+
20+
English | [简体中文](./README-zh_CN.md)
21+
22+
</div>
23+
24+
25+
## Language Features Summary
26+
27+
### Variable and Constant Declaration
28+
29+
Here are some variable declarations.
30+
31+
```typescript
32+
let flag: boolean = true;
33+
let count: number = 20;
34+
let content: string = "Hello World";
35+
```
36+
37+
Thanks to the type inference feature of StaticScript, we can write the above variable declaration as follows. They are exactly equivalent.
38+
39+
```typescript
40+
let flag = true;
41+
let count = 20;
42+
let content = "Hello World";
43+
```
44+
45+
The compiler of StaticScript cleverly deduced the type of the variable from the initial value.
46+
47+
In addition to using `let` to declare variables, you can also use `const` to declare constants.
48+
49+
```typescript
50+
const name = "StaticScript";
51+
const age = 1;
52+
const developing = true;
53+
```
54+
55+
The difference between `let` and `const` is that constants declared with `const` cannot be modified.
56+
57+
### Variable Evaluation
58+
59+
You can use a wealth of operators to perform operations on variables, including arithmetic operations, bitwise operations, logical operations, relational operations, assignments, and string concatenation.
60+
61+
```typescript
62+
let a = 1;
63+
let b = 2;
64+
65+
// add, subtract, multiply and divide
66+
let sum = a + b;
67+
let diff = a - b;
68+
let product = a * b;
69+
let quotient = a / b;
70+
71+
a = a << 1; // equivalent to `a <<= 1`
72+
b = b >> 1; // equivalent to `b >>= 1`
73+
74+
let year = "2020", month = "08", day = "06";
75+
let birthday = year + "/" + month + "/" + day;
76+
```
77+
78+
### Control Flow
79+
80+
```typescript
81+
let a = 1;
82+
let b = 100;
83+
if (a < b) {
84+
ss_println_string("b is bigger");
85+
} else {
86+
ss_println_string("b is not bigger");
87+
}
88+
89+
90+
let max = a;
91+
if (a < b) {
92+
max = b;
93+
}
94+
```
95+
96+
### Loops
97+
StaticScript supports using `while` statement and `for` statement to do some repetitive things.
98+
99+
```typescript
100+
// Calculate the sum of all even numbers between [1, 100]
101+
let sum1 = 0;
102+
let i = 1;
103+
while(i <= 100) {
104+
if (i % 2 == 0) {
105+
sum1 += i;
106+
}
107+
}
108+
109+
110+
// Calculate the sum of all integers between [1, 100]
111+
let sum2 = 0;
112+
for(let i = 1; i <= 100; i++) {
113+
sum2 += i;
114+
}
115+
```
116+
117+
### Function
118+
119+
StaticScript supports defining functions in the top level scope and using function in any scope.
120+
121+
```typescript
122+
function add(a: number, b: number): number {
123+
return a + b;
124+
}
125+
```
126+
127+
The above function can omit the return type because StaticScript can deduce the return type through the expression of the return statement.
128+
129+
It is important to note that the parameter types of functions must be explicitly declared.

0 commit comments

Comments
 (0)