ref: 026e7301f8e481ff1702f0287d577981801889e6
parent: ec3805a1ef3e6d851ecc3e6b0b3ea4135dbaf3ab
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Aug 25 13:58:14 EDT 2012
Added tree struct for while statement
--- a/flow.c
+++ b/flow.c
@@ -18,12 +18,13 @@
static struct node *
do_while(void)
{
+ register struct node *cond;
+
expect(WHILE);
expect('(');
- expr();
+ cond = expr();
expect(')');
- stmt();
- return NULL;
+ return node2(OWHILE, cond, stmt());
}
static struct node *
@@ -76,13 +77,13 @@
static struct node *
do_switch(void)
{
- register struct node *e1;
+ register struct node *cond;
expect(SWITCH);
expect('(');
- e1 = expr();
+ cond = expr();
expect(')');
- return node2(OSWITCH, e1, stmt());
+ return node2(OSWITCH, cond, stmt());
}
static struct node *
--- a/syntax.h
+++ b/syntax.h
@@ -11,7 +11,7 @@
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, ODO
+ OFEXP, ODO, OWHILE
};
struct node;
--- a/tree.c
+++ b/tree.c
@@ -181,7 +181,8 @@
[OIF] = {3, "if"},
[OFOR] = {2, "for"},
[OFEXP] = {3, "efor"},
- [ODO] = {2, "do"}
+ [ODO] = {2, "do"},
+ [OWHILE] = {2, "while"},
};
if (!np) {
fputs(" nil", stdout);