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) { }