commit ec3805a1ef3e6d851ecc3e6b0b3ea4135dbaf3ab
parent 0806fd87e7bb0f60a0acc1600b84d1a74351f5d1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 25 Aug 2012 17:54:45 +0200
Added tree struct for do/while statement
Diffstat:
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/flow.c b/flow.c
@@ -29,13 +29,17 @@ do_while(void)
static struct node *
do_do(void)
{
+ register struct node *cond, *body;
+
expect(DO);
- stmt();
+ body = stmt();
expect(WHILE);
expect('(');
- expr();
+ cond = expr();
expect(')');
- return NULL;
+ expect(';');
+
+ return node2(ODO, body, cond);
}
static struct node *
diff --git a/syntax.h b/syntax.h
@@ -11,7 +11,7 @@ enum opcode {
OBOR, OAND, OOR, OTERN, OASSIGN, OA_MUL, OA_DIV,
OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND,
OA_XOR, OA_OR, OSYM, OCOMP, OSWITCH, OIF, OFOR,
- OFEXP
+ OFEXP, ODO
};
struct node;
diff --git a/tree.c b/tree.c
@@ -180,7 +180,8 @@ prtree_helper(register struct node *np)
[OSWITCH] = {2, "switch"},
[OIF] = {3, "if"},
[OFOR] = {2, "for"},
- [OFEXP] = {3, "efor"}
+ [OFEXP] = {3, "efor"},
+ [ODO] = {2, "do"}
};
if (!np) {
fputs(" nil", stdout);