scc

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

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

Added tree structure for break statement

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

diff --git a/flow.c b/flow.c @@ -149,6 +149,16 @@ label(void) } static struct node * +_break(void) +{ + expect(BREAK); + expect(';'); + if (blockp == blocks) + error("break statement not within loop or switch"); + return node1(OBREAK, NULL); +} + +static struct node * stmt(void) { register struct node *np; @@ -161,7 +171,7 @@ stmt(void) case DO: return _do(); case WHILE: return _while(); case CONTINUE: - case BREAK: + case BREAK: return _break(); case RETURN: case GOTO: return _goto(); case CASE: /* TODO */ 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 + OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK, }; struct node; diff --git a/tree.c b/tree.c @@ -184,7 +184,8 @@ prtree_helper(register struct node *np) [ODO] = {2, "do"}, [OWHILE] = {2, "while"}, [OLABEL] = {2, "label"}, - [OGOTO] = {1, "goto"} + [OGOTO] = {1, "goto"}, + [OBREAK] = {1, "break"}, }; if (!np) { fputs(" nil", stdout);