Pārlūkot izejas kodu

fix: 修复了控制语句吞噬stop_token的问题

SongZihuan 4 gadi atpakaļ
vecāks
revīzija
f40a51eb66
2 mainītis faili ar 14 papildinājumiem un 12 dzēšanām
  1. 0 3
      main.c
  2. 14 9
      parser/grammar.c

+ 0 - 3
main.c

@@ -24,10 +24,7 @@ int main(int argc, char *argv[]) {
  * __call__ 设定
  * __var__ 设定
  * 下标和切片
- * super函数
- * 默认形参
  * 官方函数
  * 官方类
  * for 循环
- * yield 语句
  */

+ 14 - 9
parser/grammar.c

@@ -55,13 +55,13 @@ void parserCommandList(PASERSSIGNATURE, bool global, Statement *st) {
                 delToken(pm);
             else  if(stop != MATHER_EOF){
                 if (global) {
-                    fprintf(stderr, "stop = %d\n", stop);
                     Token *tk = popNewToken(pm->tm);
                     freeToken(tk, true);
                     syntaxError(pm, command_list_error, command_token->line, 1, "ERROR from parserCommand list(get stop)");
                     freeToken(command_token, true);
                 }
                 else{
+                    printf("stop = %d\n", stop);
                     connectStatement(st, command_token->data.st);
                     freeToken(command_token, false);
                 }
@@ -447,16 +447,22 @@ void parserControl(PASERSSIGNATURE, MakeControlFunction callBack, int type, bool
     Token *tmp = NULL;
     long int line = delToken(pm);
     parserOperation(CALLPASERSSIGNATURE);
-    if (!call_success(pm) || readBackToken(pm) != OPERATION && must_operation){
-        syntaxError(pm, syntax_error, line, 1, message);
-        goto return_;
+    if (!call_success(pm))
+        goto error;
+    else if (readBackToken(pm) == OPERATION){
+        tmp = popNewToken(pm->tm);
+        opt = tmp->data.st;
+        freeToken(tmp, false);
     }
-    tmp = popNewToken(pm->tm);
-    opt = tmp->data.st;
-    freeToken(tmp, false);
+    else if (must_operation)
+        goto error;
+
     st = callBack(opt, line, pm->file);
     addStatementToken(type, st, pm);
-    return_:
+    return;
+
+    error:
+    syntaxError(pm, syntax_error, line, 1, message);
     return;
 }
 
@@ -960,7 +966,6 @@ void parserCode(PASERSSIGNATURE) {
         goto error_;
 
     if (!checkToken(pm, MATHER_RC)) {
-        printf("tk = %d\n", readBackToken(pm));
         syntaxError(pm, syntax_error, line, 1, "Don't get the }");  // 使用{的行号
         goto error_;
     }