DEADSOFTWARE

Добавлена конструкция REPEAT-UNTIL
[dsw-obn.git] / src / oberon.c
index 8a84e1359dcd48f368f41cd945a76bb92a11b599..e8cbf428c12a7261b90dd057c8dc96381f465a3b 100644 (file)
@@ -67,7 +67,9 @@ enum {
        ELSE,
        ELSIF,
        WHILE,
-       DO
+       DO,
+       REPEAT,
+       UNTIL
 };
 
 // =======================================================================
@@ -410,6 +412,14 @@ oberon_read_ident(oberon_context_t * ctx)
        {
                ctx -> token = DO;
        }
+       else if(strcmp(ident, "REPEAT") == 0)
+       {
+               ctx -> token = REPEAT;
+       }
+       else if(strcmp(ident, "UNTIL") == 0)
+       {
+               ctx -> token = UNTIL;
+       }
 }
 
 static void
@@ -2986,6 +2996,27 @@ oberon_statement(oberon_context_t * ctx)
                oberon_assert_token(ctx, END);
                oberon_generate_label(ctx, end);
        }
+       else if(ctx -> token == REPEAT)
+       {
+               gen_label_t * begin;
+               oberon_expr_t * cond;
+
+               begin = oberon_generator_reserve_label(ctx);
+               oberon_generate_label(ctx, begin);
+               oberon_assert_token(ctx, REPEAT);
+
+               oberon_statement_seq(ctx);
+
+               oberon_assert_token(ctx, UNTIL);
+
+               cond = oberon_expr(ctx);
+               if(cond -> result -> class != OBERON_TYPE_BOOLEAN)
+               {
+                       oberon_error(ctx, "condition must be boolean");
+               }
+
+               oberon_generate_branch(ctx, cond, true, begin);
+       }
        else if(ctx -> token == RETURN)
        {
                oberon_assert_token(ctx, RETURN);