summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e9b6494)
raw | patch | inline | side by side (parent: e9b6494)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Thu, 3 Aug 2017 10:38:25 +0000 (13:38 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Thu, 3 Aug 2017 10:38:25 +0000 (13:38 +0300) |
src/oberon.c | patch | blob | history | |
src/test.c | patch | blob | history |
diff --git a/src/oberon.c b/src/oberon.c
index b428ecf73f6bda15c85365a8d49a5dd6aafb45ad..8a84e1359dcd48f368f41cd945a76bb92a11b599 100644 (file)
--- a/src/oberon.c
+++ b/src/oberon.c
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);
diff --git a/src/test.c b/src/test.c
index bcc8e86c8fe1c3a607d1d235ef29bd3d92c62820..549e5eaa69e890f6c70b2c053474152028f2f571 100644 (file)
--- a/src/test.c
+++ b/src/test.c
" 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."