https://github.com/impact-eintr/monkey
用Go自制解释器/编译器
https://github.com/impact-eintr/monkey
Last synced: 2 months ago
JSON representation
用Go自制解释器/编译器
- Host: GitHub
- URL: https://github.com/impact-eintr/monkey
- Owner: impact-eintr
- License: gpl-3.0
- Created: 2022-10-12T06:10:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-14T08:34:34.000Z (over 3 years ago)
- Last Synced: 2025-12-30T19:26:49.043Z (5 months ago)
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Monkey
用Go自制解释器/编译器
# 解释器
## 词法分析
**源代码** => **词法单元** => **抽象语法树**
### 定义词法单元
``` sh
let five = 5;
let ten = 10;
let add = fn(x, y) {
x + y;
};
let result = add(five, ten);
```
``` go
type TokenType string
type Token struct {
Type TokenType
Literal string
}
```
### 词法分析器
词法分析器将源代码作为输入,并输出对应的词法单元。词法分析器会遍历输入的字符,然后逐个输出识别的词法单元。
# 编译器