添加README.md中的函数,结构体部分
This commit is contained in:
parent
f293e14b61
commit
e6fb10125d
36
README.md
36
README.md
@ -193,6 +193,41 @@ println("Hello", 42) // 输出: Hello42\n
|
|||||||
| 13 | <<= | a <<= 1 | a = a << 1 |
|
| 13 | <<= | a <<= 1 | a = a << 1 |
|
||||||
| 13 | >>= | a >>= 1 | a = a >> 1 |
|
| 13 | >>= | a >>= 1 | a = a >> 1 |
|
||||||
|
|
||||||
|
### 1.6 函数
|
||||||
|
|
||||||
|
函数声明语法如下
|
||||||
|
|
||||||
|
````
|
||||||
|
fn 函数名(参数名:参数类型,....) -> 返回类型 {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
> 注意:最后一个表达式如果没有分号,其值默认为返回值
|
||||||
|
|
||||||
|
例子:
|
||||||
|
|
||||||
|
```
|
||||||
|
fn add(x:i8, y:i8) -> i8 {
|
||||||
|
x+y
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1.7 结构体
|
||||||
|
|
||||||
|
结构体声明语法如下
|
||||||
|
|
||||||
|
```
|
||||||
|
struct point {
|
||||||
|
x:i8,
|
||||||
|
y:i8
|
||||||
|
}
|
||||||
|
|
||||||
|
a = point {x:24, y:43};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 2. 实现细节
|
## 2. 实现细节
|
||||||
|
|
||||||
### 2.1 词法分析的符号表结构
|
### 2.1 词法分析的符号表结构
|
||||||
@ -273,6 +308,7 @@ println("Hello", 42) // 输出: Hello42\n
|
|||||||
| 40 | ] |
|
| 40 | ] |
|
||||||
| 41 | ? |
|
| 41 | ? |
|
||||||
| 42 | : |
|
| 42 | : |
|
||||||
|
| 43 | -> |
|
||||||
|
|
||||||
#### 常量表
|
#### 常量表
|
||||||
|
|
||||||
|
@ -4,6 +4,11 @@
|
|||||||
#include "Tbs.h"
|
#include "Tbs.h"
|
||||||
class Scanner {
|
class Scanner {
|
||||||
public:
|
public:
|
||||||
bool scan(std::string org_s,Tbs& t);
|
Scanner(std::string source_code)
|
||||||
|
: m_source_code(source_code) {}
|
||||||
|
|
||||||
|
int is_int(int index);
|
||||||
|
private:
|
||||||
|
std::string m_source_code;
|
||||||
|
int index;
|
||||||
};
|
};
|
@ -2,17 +2,5 @@
|
|||||||
|
|
||||||
using std::vector,std::string;
|
using std::vector,std::string;
|
||||||
|
|
||||||
bool Scanner::scan(std::string org_s,Tbs& t) {
|
int Scanner::is_int(int index) {
|
||||||
string tmp;
|
|
||||||
int cnt = 0;
|
|
||||||
for (auto e : org_s) {
|
|
||||||
if (e==' ') {
|
|
||||||
t.ConstTable[++cnt] =tmp;
|
|
||||||
tmp = "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tmp += e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user