scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 026e7301f8e481ff1702f0287d577981801889e6
parent ec3805a1ef3e6d851ecc3e6b0b3ea4135dbaf3ab
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 25 Aug 2012 17:58:14 +0200

Added tree struct for while statement

Diffstat:
Mflow.c | 13+++++++------
Msyntax.h | 2+-
Mtree.c | 3++-
3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/flow.c b/flow.c @@ -18,12 +18,13 @@ do_goto(void) 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 @@ do_if(void) 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 * 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, ODO + OFEXP, ODO, OWHILE }; struct node; diff --git a/tree.c b/tree.c @@ -181,7 +181,8 @@ prtree_helper(register struct node *np) [OIF] = {3, "if"}, [OFOR] = {2, "for"}, [OFEXP] = {3, "efor"}, - [ODO] = {2, "do"} + [ODO] = {2, "do"}, + [OWHILE] = {2, "while"}, }; if (!np) { fputs(" nil", stdout);