scc

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

commit 68fd23753b7c670097f9dbb0ada76ea59189157a
parent adc45909f04c3cd3c7ee4e3e1e62ce5d67eaef7d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 26 Aug 2012 20:58:54 +0200

Added tree structure for goto statement

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

diff --git a/flow.c b/flow.c @@ -10,9 +10,16 @@ static struct node *stmt(void); static struct node * _goto(void) { + register struct node *np; + expect(GOTO); expect(IDEN); - return NULL; + if (yyval.sym->ns != NS_LABEL) + yyval.sym = lookup(yytext, NS_LABEL, CTX_ANY); + np = node1(OGOTO, nodesym(yyval.sym)); + expect(';'); + + return np; } 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, OWHILE, OLABEL + OFEXP, ODO, OWHILE, OLABEL, OGOTO }; struct node; diff --git a/tree.c b/tree.c @@ -183,7 +183,8 @@ prtree_helper(register struct node *np) [OFEXP] = {3, "efor"}, [ODO] = {2, "do"}, [OWHILE] = {2, "while"}, - [OLABEL] = {2, "label"} + [OLABEL] = {2, "label"}, + [OGOTO] = {1, "goto"} }; if (!np) { fputs(" nil", stdout);