IF,
THEN,
ELSE,
- ELSIF
+ ELSIF,
+ WHILE,
+ DO
};
// =======================================================================
{
ctx -> token = ELSIF;
}
+ else if(strcmp(ident, "WHILE") == 0)
+ {
+ ctx -> token = WHILE;
+ }
+ else if(strcmp(ident, "DO") == 0)
+ {
+ ctx -> token = DO;
+ }
}
static void
oberon_generate_label(ctx, end);
oberon_assert_token(ctx, END);
}
+ else if(ctx -> token == WHILE)
+ {
+ gen_label_t * begin;
+ gen_label_t * end;
+ oberon_expr_t * cond;
+
+ begin = oberon_generator_reserve_label(ctx);
+ end = oberon_generator_reserve_label(ctx);
+
+ oberon_assert_token(ctx, WHILE);
+ oberon_generate_label(ctx, begin);
+ cond = oberon_expr(ctx);
+ if(cond -> result -> class != OBERON_TYPE_BOOLEAN)
+ {
+ oberon_error(ctx, "condition must be boolean");
+ }
+ oberon_generate_branch(ctx, cond, false, end);
+
+ oberon_assert_token(ctx, DO);
+ oberon_statement_seq(ctx);
+ oberon_generate_goto(ctx, begin);
+
+ oberon_assert_token(ctx, END);
+ oberon_generate_label(ctx, end);
+ }
else if(ctx -> token == RETURN)
{
oberon_assert_token(ctx, RETURN);
" i : INTEGER;"
""
"BEGIN"
- " i := 4;"
+ " i := 0;"
" Out.Open();"
- " IF i = 0 THEN"
- " Out.String('Branch 0'); Out.Ln;"
- " ELSIF i = 1 THEN"
- " Out.String('Branch 1'); Out.Ln;"
- " ELSIF i = 2 THEN"
- " Out.String('Branch 2'); Out.Ln;"
- " ELSE"
- " Out.String('Branch else'); Out.Ln;"
+ " WHILE i < 4 DO"
+ " Out.String('Count '); Out.Int(i, 0); Out.Ln;"
+ " i := i + 1;"
" END;"
" Out.String('end'); Out.Ln;"
"END Test."