From 3ea3dfde27782205a212b18d8bd3a2743daa7443 Mon Sep 17 00:00:00 2001 From: Guan Inf <2307786059@qq.com> Date: Wed, 4 Jun 2025 21:46:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=8A=9F=E6=B5=8B=E8=AF=95identifier?= =?UTF-8?q?=E5=92=8CPunctutation=20,=20=E5=A2=9E=E5=8A=A0=E7=95=8C?= =?UTF-8?q?=E7=AC=A6;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/input.txt | 52 ++++++++++++++++++++++++++++++++++++++++ include/syntax/Scanner.h | 12 +++++++--- input.txt | 52 ++++++++++++++++++++++++++++++++++++++++ src/input.txt | 52 ++++++++++++++++++++++++++++++++++++++++ unit/input.txt | 52 ++++++++++++++++++++++++++++++++++++++++ unit/scanner_test.cpp | 6 ++++- 6 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 include/input.txt create mode 100644 input.txt create mode 100644 src/input.txt create mode 100644 unit/input.txt diff --git a/include/input.txt b/include/input.txt new file mode 100644 index 0000000..eb79b32 --- /dev/null +++ b/include/input.txt @@ -0,0 +1,52 @@ +//Merge Sort + +struct Point { + x:i8; + y:i8; +} +// Struct + +/* +ababa +*/ +[Point:105] tmp; + +fn MergeSort([Point:20] v,i8 l,i8 r) -> { + if l>r { + return ; + } + var mid = l + r >>1; + MergeSort(v,l,mid); + MergeSort(v,mid+1,r); + i8 i=l,j=mid+1,k=l; + for ;i <= mid && j <= r;k+=1 { + if v[l] < v[r] + { + tmp[k] = v[l]; + l +=1; + } + else{ + tmp[k] = v[r]; + r += 1; + } + } + for ; i<=mid; { + tmp[k] = tmp[i]; + k += 1,i+=1; + } + for ; j <=r ; { + tmp[k] = tmp[j]; + k +=1 , j += 1; + } + +} +fn main()->i8{ + [Point:20] d; + [Point] d; + + for i8 i = 0;i< 20; i++ { + d[i] = {x:i * i,y:i}; + } + MergeSort(d,d+20); + 0 +} \ No newline at end of file diff --git a/include/syntax/Scanner.h b/include/syntax/Scanner.h index 4e80214..e369c46 100644 --- a/include/syntax/Scanner.h +++ b/include/syntax/Scanner.h @@ -140,13 +140,15 @@ private: is_number(module.s_cursor.source[module.s_cursor.guard])) && !at_eof()) { guard_advance(); + } return gen_word(); } inline token_type_t special_char() { - char c = guard_advance(); + char c = module.s_cursor.source[module.s_cursor.guard]; + guard_advance(); switch (c) { case '(': return TOKEN_LEFT_PAREN; @@ -637,7 +639,6 @@ private: inline token_t item() { module.s_cursor.length = 0; // 重置长度 module.s_cursor.current = module.s_cursor.guard; // 重置游标位置 - if (is_alpha(module.s_cursor.source[module.s_cursor.guard])) { std::string word = ident_advance(); return token_t(scanner_ident(word, word.size()),word, module.s_cursor.line, module.s_cursor.column); @@ -662,6 +663,11 @@ private: word = bin_number_advance(); decimal = number_convert(word, 2); } + else { + word = number_advance(); + if (word.size() > 1) word = word.substr(1, word.size() - 1); + decimal = number_convert(word,10); + } } else { word = number_advance(); decimal = number_convert(word, 10); @@ -680,7 +686,7 @@ private: return token_t(TOKEN_LITERAL_STRING, word, module.s_cursor.line, module.s_cursor.column); } - token_type_t type = special_char(); + token_type_t type = special_char(); return token_t(type, gen_word(), module.s_cursor.line, module.s_cursor.column); } diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..eb79b32 --- /dev/null +++ b/input.txt @@ -0,0 +1,52 @@ +//Merge Sort + +struct Point { + x:i8; + y:i8; +} +// Struct + +/* +ababa +*/ +[Point:105] tmp; + +fn MergeSort([Point:20] v,i8 l,i8 r) -> { + if l>r { + return ; + } + var mid = l + r >>1; + MergeSort(v,l,mid); + MergeSort(v,mid+1,r); + i8 i=l,j=mid+1,k=l; + for ;i <= mid && j <= r;k+=1 { + if v[l] < v[r] + { + tmp[k] = v[l]; + l +=1; + } + else{ + tmp[k] = v[r]; + r += 1; + } + } + for ; i<=mid; { + tmp[k] = tmp[i]; + k += 1,i+=1; + } + for ; j <=r ; { + tmp[k] = tmp[j]; + k +=1 , j += 1; + } + +} +fn main()->i8{ + [Point:20] d; + [Point] d; + + for i8 i = 0;i< 20; i++ { + d[i] = {x:i * i,y:i}; + } + MergeSort(d,d+20); + 0 +} \ No newline at end of file diff --git a/src/input.txt b/src/input.txt new file mode 100644 index 0000000..eb79b32 --- /dev/null +++ b/src/input.txt @@ -0,0 +1,52 @@ +//Merge Sort + +struct Point { + x:i8; + y:i8; +} +// Struct + +/* +ababa +*/ +[Point:105] tmp; + +fn MergeSort([Point:20] v,i8 l,i8 r) -> { + if l>r { + return ; + } + var mid = l + r >>1; + MergeSort(v,l,mid); + MergeSort(v,mid+1,r); + i8 i=l,j=mid+1,k=l; + for ;i <= mid && j <= r;k+=1 { + if v[l] < v[r] + { + tmp[k] = v[l]; + l +=1; + } + else{ + tmp[k] = v[r]; + r += 1; + } + } + for ; i<=mid; { + tmp[k] = tmp[i]; + k += 1,i+=1; + } + for ; j <=r ; { + tmp[k] = tmp[j]; + k +=1 , j += 1; + } + +} +fn main()->i8{ + [Point:20] d; + [Point] d; + + for i8 i = 0;i< 20; i++ { + d[i] = {x:i * i,y:i}; + } + MergeSort(d,d+20); + 0 +} \ No newline at end of file diff --git a/unit/input.txt b/unit/input.txt new file mode 100644 index 0000000..eb79b32 --- /dev/null +++ b/unit/input.txt @@ -0,0 +1,52 @@ +//Merge Sort + +struct Point { + x:i8; + y:i8; +} +// Struct + +/* +ababa +*/ +[Point:105] tmp; + +fn MergeSort([Point:20] v,i8 l,i8 r) -> { + if l>r { + return ; + } + var mid = l + r >>1; + MergeSort(v,l,mid); + MergeSort(v,mid+1,r); + i8 i=l,j=mid+1,k=l; + for ;i <= mid && j <= r;k+=1 { + if v[l] < v[r] + { + tmp[k] = v[l]; + l +=1; + } + else{ + tmp[k] = v[r]; + r += 1; + } + } + for ; i<=mid; { + tmp[k] = tmp[i]; + k += 1,i+=1; + } + for ; j <=r ; { + tmp[k] = tmp[j]; + k +=1 , j += 1; + } + +} +fn main()->i8{ + [Point:20] d; + [Point] d; + + for i8 i = 0;i< 20; i++ { + d[i] = {x:i * i,y:i}; + } + MergeSort(d,d+20); + 0 +} \ No newline at end of file diff --git a/unit/scanner_test.cpp b/unit/scanner_test.cpp index 4b9e70e..19055ee 100644 --- a/unit/scanner_test.cpp +++ b/unit/scanner_test.cpp @@ -8,7 +8,11 @@ using std::string,std::vector; TEST_CASE("Scanner test") { - module_t module("{}"); + std::ifstream t("input.txt"); + std::stringstream buffer; + buffer<