scc

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

commit a8acad8243a648e895baebf39b5672b8209a30c6
parent 5e36187eb6fac0a74254d40302033d0f043f8e72
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 28 Aug 2012 20:43:56 +0200

Added tree structure for continue

Diffstat:
Mflow.c | 18+++++++++++++++++-
Msyntax.h | 2+-
Mtree.c | 1+
3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/flow.c b/flow.c @@ -159,6 +159,22 @@ _break(void) } static struct node * +_continue(void) +{ + register unsigned char *bp; + + expect(CONTINUE); + expect(';'); + + for (bp = blocks; bp < blockp && *bp == OSWITCH; ++bp) + ; /* nothing */ + if (bp == blockp) + error("continue statement not within loop"); + + return node1(OCONT, NULL); +} + +static struct node * stmt(void) { register struct node *np; @@ -170,7 +186,7 @@ stmt(void) case FOR: return _for(); case DO: return _do(); case WHILE: return _while(); - case CONTINUE: + case CONTINUE: return _continue(); case BREAK: return _break(); case RETURN: case GOTO: return _goto(); 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, OWHILE, OLABEL, OGOTO, OBREAK, + OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK, OCONT }; struct node; diff --git a/tree.c b/tree.c @@ -186,6 +186,7 @@ prtree_helper(register struct node *np) [OLABEL] = {2, "label"}, [OGOTO] = {1, "goto"}, [OBREAK] = {1, "break"}, + [OCONT] = {1, "cont"}, }; if (!np) { fputs(" nil", stdout);