ref: 9e7035dc20b95a41672e56d086569988c8130975
parent: 9fa589f963e560b02cfecd13b724664a239693b6
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 24 14:13:59 EDT 2014
Add if statement This is a first version of if, that it is not functional because the direction of the jump is wrong. We have to negate the condition in order to get the correct jump.
--- a/stmt.c
+++ b/stmt.c
@@ -260,6 +260,23 @@
lswitch->deflabel = ldefault;
}
+static void
+If(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
+{
+ Symbol *end = label(NULL, 1);
+
+ expect(IF);
+ /* TODO: negate the condition */
+ emitjump(end, condition());
+ stmt(lbreak, lcont, lswitch);
+ if (accept(ELSE)) {
+ emitlabel(end);
+ stmt(lbreak, lcont, lswitch);
+ } else {
+ emitlabel(end);
+ }
+}
+
void
compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
{
@@ -289,6 +306,7 @@
case WHILE: While(lswitch); break;
case FOR: For(lswitch); break;
case DO: Dowhile(lswitch); break;
+ case IF: If(lbreak, lcont, lswitch); break;
case BREAK: Break(lbreak); break;
case CONTINUE: Continue(lcont); break;
case GOTO: Goto(); break;