scc

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

commit 84df6c68740f97dcd4ecac1b364987b6aa256fba
parent 0304c0486f58225dca5ee08111a1493d3c58daa7
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 28 Aug 2012 20:50:29 +0200

Added tree structure for default

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

diff --git a/flow.c b/flow.c @@ -207,6 +207,20 @@ _case(void) } static struct node * +_default(void) +{ + register unsigned char *bp; + + expect(DEFAULT); + for (bp = blocks; bp < blockp && *bp != OSWITCH; ++bp) + ; /* nothing */ + if (bp == blockp) + error("default statement not within switch"); + expect(':'); + return node1(ODEFAULT, NULL); +} + +static struct node * stmt(void) { register struct node *np; @@ -223,7 +237,7 @@ stmt(void) case RETURN: return _return(); case GOTO: return _goto(); case CASE: return _case(); - case DEFAULT: /* TODO */ + case DEFAULT: return _default(); case IDEN: return label(); } np = expr(); diff --git a/syntax.h b/syntax.h @@ -12,7 +12,7 @@ enum opcode { 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, OCONT, - ORETURN, OCASE + ORETURN, OCASE, ODEFAULT }; struct node; diff --git a/tree.c b/tree.c @@ -188,7 +188,8 @@ prtree_helper(register struct node *np) [OBREAK] = {1, "break"}, [OCONT] = {1, "cont"}, [ORETURN] = {1, "return"}, - [OCASE] = {1, "case"} + [OCASE] = {1, "case"}, + [ODEFAULT] = {1, "default"} }; if (!np) { fputs(" nil", stdout);