From e6fb10125ddd820586bd2e87560614ae3e27e62b Mon Sep 17 00:00:00 2001 From: Gary Gan Date: Tue, 3 Jun 2025 18:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0README.md=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E7=BB=93=E6=9E=84=E4=BD=93=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 36 ++++++++++++++++++++++++++++++++++++ include/Scanner.h | 7 ++++++- src/Scanner.cpp | 14 +------------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 92d15bc..6dcffc0 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,41 @@ println("Hello", 42) // 输出: Hello42\n | 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.1 词法分析的符号表结构 @@ -273,6 +308,7 @@ println("Hello", 42) // 输出: Hello42\n | 40 | ] | | 41 | ? | | 42 | : | +| 43 | -> | #### 常量表 diff --git a/include/Scanner.h b/include/Scanner.h index 9d8988a..9b0cb08 100644 --- a/include/Scanner.h +++ b/include/Scanner.h @@ -4,6 +4,11 @@ #include "Tbs.h" class Scanner { 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; }; \ No newline at end of file diff --git a/src/Scanner.cpp b/src/Scanner.cpp index 3d1a5c9..8b6e530 100644 --- a/src/Scanner.cpp +++ b/src/Scanner.cpp @@ -2,17 +2,5 @@ using std::vector,std::string; -bool Scanner::scan(std::string org_s,Tbs& t) { - string tmp; - int cnt = 0; - for (auto e : org_s) { - if (e==' ') { - t.ConstTable[++cnt] =tmp; - tmp = ""; - } - else { - tmp += e; - } - } - return true; +int Scanner::is_int(int index) { }