diff --git a/src/oberon.c b/src/oberon.c
index f2310db26de0ab2b1bffb82efee2a4b346bf7052..f2c901433aeb49363ef01007ed8336a1e5db1919 100644 (file)
--- a/src/oberon.c
+++ b/src/oberon.c
IMPORT,
REAL,
CHAR,
IMPORT,
REAL,
CHAR,
- STRING
+ STRING,
+ IF,
+ THEN,
+ ELSE
};
// =======================================================================
};
// =======================================================================
{
ctx -> token = IS;
}
{
ctx -> token = IS;
}
+ else if(strcmp(ident, "IF") == 0)
+ {
+ ctx -> token = IF;
+ }
+ else if(strcmp(ident, "THEN") == 0)
+ {
+ ctx -> token = THEN;
+ }
+ else if(strcmp(ident, "ELSE") == 0)
+ {
+ ctx -> token = ELSE;
+ }
}
static void
}
static void
@@ -1641,6 +1656,10 @@ oberon_make_bin_op(oberon_context_t * ctx, int token, oberon_expr_t * a, oberon_
|| b -> result -> class == OBERON_TYPE_INTEGER
|| a -> result -> class == OBERON_TYPE_REAL
|| b -> result -> class == OBERON_TYPE_REAL)
|| b -> result -> class == OBERON_TYPE_INTEGER
|| a -> result -> class == OBERON_TYPE_REAL
|| b -> result -> class == OBERON_TYPE_REAL)
+ {
+ // accept
+ }
+ else
{
oberon_error(ctx, "used only with numeric types");
}
{
oberon_error(ctx, "used only with numeric types");
}
oberon_prevent_undeclarated_procedures(ctx);
}
oberon_prevent_undeclarated_procedures(ctx);
}
+static void
+oberon_statement_seq(oberon_context_t * ctx);
+
static void
oberon_assign(oberon_context_t * ctx, oberon_expr_t * src, oberon_expr_t * dst)
{
static void
oberon_assign(oberon_context_t * ctx, oberon_expr_t * src, oberon_expr_t * dst)
{
oberon_opt_proc_parens(ctx, item1);
}
}
oberon_opt_proc_parens(ctx, item1);
}
}
+ else if(ctx -> token == IF)
+ {
+ gen_label_t * end;
+ gen_label_t * els;
+ oberon_expr_t * cond;
+
+ els = oberon_generator_reserve_label(ctx);
+ end = oberon_generator_reserve_label(ctx);
+
+ oberon_assert_token(ctx, IF);
+ cond = oberon_expr(ctx);
+ if(cond -> result -> class != OBERON_TYPE_BOOLEAN)
+ {
+ oberon_error(ctx, "condition must be boolean");
+ }
+ oberon_assert_token(ctx, THEN);
+ oberon_generate_branch(ctx, cond, false, els);
+ oberon_statement_seq(ctx);
+ oberon_generate_goto(ctx, end);
+
+ oberon_generate_label(ctx, els);
+ if(ctx -> token == ELSE)
+ {
+ oberon_assert_token(ctx, ELSE);
+ oberon_statement_seq(ctx);
+ }
+
+ oberon_generate_label(ctx, end);
+ oberon_assert_token(ctx, END);
+ }
else if(ctx -> token == RETURN)
{
oberon_assert_token(ctx, RETURN);
else if(ctx -> token == RETURN)
{
oberon_assert_token(ctx, RETURN);