From 63e567def64b515da2832cad368b7a48f03156a7 Mon Sep 17 00:00:00 2001 From: Joshua Phillips Date: Sun, 21 Dec 2008 18:32:37 +0000 Subject: [PATCH] Case labels, break/continue/return. --- parse.c | 18 ++++++++++++++++++ stree.c | 1 + stree.h | 1 + 3 files changed, 20 insertions(+) diff --git a/parse.c b/parse.c index ef1dd04..5f2b444 100644 --- a/parse.c +++ b/parse.c @@ -800,6 +800,24 @@ top: lex_next(LEX); } goto top; + } else if (TOK == TOK_continue || TOK == TOK_break){ + stat = stree_create(); + stat->form = STF_JUMP; + stat->tok = TOK; + stree_append_child(cc->scope, stat); + lex_next(LEX); + cc_accept(cc, "\"}\"", '}', 0); + } else if (TOK == TOK_return){ + stat = stree_create(); + stat->form = STF_JUMP; + stat->tok = TOK; + stree_append_child(cc->scope, stat); + lex_next(LEX); + if (TOK != ';'){ + expr = cc_parse_expr(cc); + stree_append_child(stat, expr); + } + cc_accept(cc, "\"}\"", '}', 0); } else if (TOK == '{'){ lex_next(LEX); block = stree_create(); diff --git a/stree.c b/stree.c index f16392d..f143ed8 100644 --- a/stree.c +++ b/stree.c @@ -23,6 +23,7 @@ static const char *form_strtab[] = { "STAT", "PASS", "LABEL", + "JUMP", }; static int next_id = 1; diff --git a/stree.h b/stree.h index d69d65a..1e67eca 100644 --- a/stree.h +++ b/stree.h @@ -25,6 +25,7 @@ enum stree_form { STF_STAT, // non-expression statement (if, while...) STF_PASS, // nothing (placeholder) STF_LABEL, // label or case label + STF_JUMP, // goto/break/continue/return // WARNING: Add strings to form_strtab in stree.c // when adding constants here! }; -- 2.11.4.GIT