Bläddra i källkod

feat: 添加','为忽略符号

词法分析器忽略','
原','前缀改为'$'前缀
SongZihuan 3 år sedan
förälder
incheckning
81a23c835a
7 ändrade filer med 28 tillägg och 28 borttagningar
  1. 2 2
      include/core/info/prefix_macro.h
  2. 1 1
      src/core/env.c
  3. 6 6
      src/core/lexical.c
  4. 1 1
      test/af/test1.aun
  5. 8 8
      test/export/main.c
  6. 1 1
      test/src/byte_code.c
  7. 9 9
      test/src/run_code.c

+ 2 - 2
include/core/info/prefix_macro.h

@@ -5,8 +5,8 @@
 #ifndef AFUN_PREFIX_MACRO_H
 #ifndef AFUN_PREFIX_MACRO_H
 #define AFUN_PREFIX_MACRO_H
 #define AFUN_PREFIX_MACRO_H
 
 
-#define E_PREFIX ",`'"  /* element前缀 */
-#define B_PREFIX ",`'%^&<?>"  /* block前缀 */
+#define E_PREFIX "$`'"  /* element前缀 */
+#define B_PREFIX "$`'%^&<?>"  /* block前缀 */
 #define ALL_PREFIX B_PREFIX
 #define ALL_PREFIX B_PREFIX
 
 
 // 作为顶层代码,以及'()运行时
 // 作为顶层代码,以及'()运行时

+ 1 - 1
src/core/env.c

@@ -617,7 +617,7 @@ af_Environment *makeEnvironment(enum GcRunTime grt) {
     char prefix[PREFIX_SIZE + 1] = "";
     char prefix[PREFIX_SIZE + 1] = "";
     prefix[E_QUOTE] = '\'';
     prefix[E_QUOTE] = '\'';
     prefix[B_EXEC] = '\'';
     prefix[B_EXEC] = '\'';
-    prefix[B_EXEC_FIRST] = ',';
+    prefix[B_EXEC_FIRST] = '$';
     setEnvVar(ev_sys_prefix, prefix, env);
     setEnvVar(ev_sys_prefix, prefix, env);
 
 
     /* 设置NORMAL顶级处理器 */
     /* 设置NORMAL顶级处理器 */

+ 6 - 6
src/core/lexical.c

@@ -51,7 +51,7 @@ static void setLexicalLast(af_LexicalStatus status, af_TokenType token, af_Parse
  *     -> ] -> [lex_rb] # return -1
  *     -> ] -> [lex_rb] # return -1
  *     -> } -> [lex_rc] # return -1
  *     -> } -> [lex_rc] # return -1
  *     -> ; -> (lex_comment_before)
  *     -> ; -> (lex_comment_before)
- *     -> iscntrl(ch) || isspace(ch) -> [lex_space]
+ *     -> iscntrl(ch) || isspace(ch) || , -> [lex_space]
  *     -> | -> (lex_element_long)
  *     -> | -> (lex_element_long)
  *     -> isgraph(ch) -> [lex_element]
  *     -> isgraph(ch) -> [lex_element]
  */
  */
@@ -105,7 +105,7 @@ static int doneBegin(char ch, af_Parser *parser) {
     } else if (ch == ';') {
     } else if (ch == ';') {
         parser->lexical->status = lex_comment_before;
         parser->lexical->status = lex_comment_before;
         return 1;
         return 1;
-    } else if (iscntrl(ch) || isspace(ch)) {  // 空白符或控制字符被忽略
+    } else if (iscntrl(ch) || isspace(ch) || ch == ',') {  // 空白符或控制字符被忽略
         setLexicalLast(lex_space, TK_SPACE, parser);
         setLexicalLast(lex_space, TK_SPACE, parser);
         return 1;
         return 1;
     } else if (ch == '|') {
     } else if (ch == '|') {
@@ -288,11 +288,11 @@ static int doneElementLongEnd(char ch, af_Parser *parser) {
 /*
 /*
  * 状态机图:
  * 状态机图:
  * [lex_element_short]
  * [lex_element_short]
- *      -> !strchr("!@#([{}]);", ch) && isgraph(ch) -> (lex_element_short)
+ *      -> !strchr("!@#([{}]);,", ch) && isgraph(ch) -> (lex_element_short)
  *      -> other -> (lex_element_short) # return -1
  *      -> other -> (lex_element_short) # return -1
  */
  */
 static int doneElementShort(char ch, af_Parser *parser) {
 static int doneElementShort(char ch, af_Parser *parser) {
-    if (!strchr("!@#([{}]);", ch) && isgraph(ch)) {  // 除空格外的可见字符 (不包括NUL)
+    if (!strchr("!@#([{}]);,", ch) && isgraph(ch)) {  // 除空格外的可见字符 (不包括NUL)
         setLexicalLast(lex_element_short, TK_ELEMENT_SHORT, parser);
         setLexicalLast(lex_element_short, TK_ELEMENT_SHORT, parser);
         return 1;
         return 1;
     }
     }
@@ -303,11 +303,11 @@ static int doneElementShort(char ch, af_Parser *parser) {
 /*
 /*
  * 状态机图:
  * 状态机图:
  * [lex_space]
  * [lex_space]
- *      -> ch != NUL && (iscntrl(ch) || isspace(ch)) -> (lex_space)
+ *      -> ch != NUL && (iscntrl(ch) || isspace(ch)) || , -> (lex_space)
  *      -> other -> (lex_space) # return -1
  *      -> other -> (lex_space) # return -1
  */
  */
 static int doneSpace(char ch, af_Parser *parser) {
 static int doneSpace(char ch, af_Parser *parser) {
-    if (ch != NUL && (iscntrl(ch) || isspace(ch))) {
+    if (ch != NUL && (iscntrl(ch) || isspace(ch)) || ch == ',') {
         setLexicalLast(lex_space, TK_SPACE, parser);
         setLexicalLast(lex_space, TK_SPACE, parser);
         return 1;
         return 1;
     }
     }

+ 1 - 1
test/af/test1.aun

@@ -1,2 +1,2 @@
 global
 global
-{str}
+{str,}

+ 8 - 8
test/export/main.c

@@ -825,7 +825,7 @@ int main() {
     {  // 正常程序
     {  // 正常程序
         printf("TAG A:\n");
         printf("TAG A:\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, NULL);
         af_Code *bt1 = makeElementCode("object", 0, 1, NULL);
-        af_Code *bt2 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt2 = makeElementCode("data", '$', 0, "Unknown");
         connectCode(&bt1, bt2);
         connectCode(&bt1, bt2);
 
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
@@ -859,7 +859,7 @@ int main() {
 
 
     {  // 尾调用优化
     {  // 尾调用优化
         printf("TAG B:\n");
         printf("TAG B:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Unknown");
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
         connectCode(&bt1, bt2);
         connectCode(&bt1, bt2);
 
 
@@ -874,7 +874,7 @@ int main() {
 
 
     {  // 尾调用优化2
     {  // 尾调用优化2
         printf("TAG C:\n");
         printf("TAG C:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Unknown");
 
 
         iterCode(bt1, env);
         iterCode(bt1, env);
         freeAllCode(bt1);
         freeAllCode(bt1);
@@ -883,7 +883,7 @@ int main() {
 
 
     {  // 测试类前缀调用
     {  // 测试类前缀调用
         printf("TAG D:\n");
         printf("TAG D:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Unknown");
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
         connectCode(&bt1, bt2);
         connectCode(&bt1, bt2);
 
 
@@ -923,7 +923,7 @@ int main() {
 
 
         connectCode(&bt3, bt4);
         connectCode(&bt3, bt4);
 
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, '$', 1, NULL, NULL);
 
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         connectCode(&bt5, bt6);
         connectCode(&bt5, bt6);
@@ -954,7 +954,7 @@ int main() {
 
 
         connectCode(&bt3, bt4);
         connectCode(&bt3, bt4);
 
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, '$', 1, NULL, NULL);
 
 
         iterCode(bt5, env);
         iterCode(bt5, env);
         freeAllCode(bt5);
         freeAllCode(bt5);
@@ -1082,7 +1082,7 @@ int main() {
 
 
     {  // 测试错误 (无函数指定)
     {  // 测试错误 (无函数指定)
         printf("TAG F: ERROR\n");
         printf("TAG F: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Unknown");
 
 
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
         connectCode(&bt1, bt5);
         connectCode(&bt1, bt5);
@@ -1097,7 +1097,7 @@ int main() {
 
 
     {  // 测试错误 (object2 Var not found)
     {  // 测试错误 (object2 Var not found)
         printf("TAG G: ERROR\n");
         printf("TAG G: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Unknown");
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
 
 
         connectCode(&bt1, bt2);
         connectCode(&bt1, bt2);

+ 1 - 1
test/src/byte_code.c

@@ -4,7 +4,7 @@
 #include "../../src/core/__code.h"
 #include "../../src/core/__code.h"
 
 
 int main() {
 int main() {
-    af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+    af_Code *bt1 = makeElementCode("data", '$', 0, "Unknown");
     af_Code *bt2 = makeElementCode("var1", 0, 1, NULL);
     af_Code *bt2 = makeElementCode("var1", 0, 1, NULL);
 
 
     af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
     af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);

+ 9 - 9
test/src/run_code.c

@@ -875,7 +875,7 @@ int main() {
     {  // 正常程序
     {  // 正常程序
         printf("TAG A:\n");
         printf("TAG A:\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Taga.aun");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Taga.aun");
-        af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
+        af_Code *bt2 = makeElementCode("data", '$', 0, NULL);
         pushCode(&bt1, bt2);
         pushCode(&bt1, bt2);
 
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
@@ -909,7 +909,7 @@ int main() {
 
 
     {  // 尾调用优化
     {  // 尾调用优化
         printf("TAG B:\n");
         printf("TAG B:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagb.aun");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Tagb.aun");
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
         pushCode(&bt1, bt2);
         pushCode(&bt1, bt2);
 
 
@@ -924,7 +924,7 @@ int main() {
 
 
     {  // 尾调用优化2
     {  // 尾调用优化2
         printf("TAG C:\n");
         printf("TAG C:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagc.aun");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Tagc.aun");
 
 
         runCodeFromMemory(bt1, env);
         runCodeFromMemory(bt1, env);
         freeAllCode(bt1);
         freeAllCode(bt1);
@@ -933,7 +933,7 @@ int main() {
 
 
     {  // 测试类前缀调用
     {  // 测试类前缀调用
         printf("TAG D:\n");
         printf("TAG D:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagd.aun");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Tagd.aun");
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
         pushCode(&bt1, bt2);
         pushCode(&bt1, bt2);
 
 
@@ -973,7 +973,7 @@ int main() {
 
 
         pushCode(&bt3, bt4);
         pushCode(&bt3, bt4);
 
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "Tagf.aun", NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, '$', 1, "Tagf.aun", NULL);
 
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
         pushCode(&bt5, bt6);
@@ -1004,7 +1004,7 @@ int main() {
 
 
         pushCode(&bt3, bt4);
         pushCode(&bt3, bt4);
 
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "Tagh.aun", NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, '$', 1, "Tagh.aun", NULL);
 
 
         runCodeFromMemory(bt5, env);
         runCodeFromMemory(bt5, env);
         freeAllCode(bt5);
         freeAllCode(bt5);
@@ -1131,7 +1131,7 @@ int main() {
     {  // 导入式运行
     {  // 导入式运行
         printf("TAG R:\n");
         printf("TAG R:\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Tagr.aun");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Tagr.aun");
-        af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
+        af_Code *bt2 = makeElementCode("data", '$', 0, NULL);
         pushCode(&bt1, bt2);
         pushCode(&bt1, bt2);
 
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
@@ -1179,7 +1179,7 @@ int main() {
 
 
     {  // 测试错误 (无函数指定)
     {  // 测试错误 (无函数指定)
         printf("TAG b: ERROR\n");
         printf("TAG b: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagb-error.aun");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Tagb-error.aun");
 
 
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
         pushCode(&bt1, bt5);
         pushCode(&bt1, bt5);
@@ -1194,7 +1194,7 @@ int main() {
 
 
     {  // 测试错误 (object2 Var not found)
     {  // 测试错误 (object2 Var not found)
         printf("TAG c: ERROR\n");
         printf("TAG c: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagc-error.aun");
+        af_Code *bt1 = makeElementCode("data", '$', 0, "Tagc-error.aun");
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
 
 
         pushCode(&bt1, bt2);
         pushCode(&bt1, bt2);