From 58af6dcf569c7f83b317d30f8dd85d96d314d785 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 13 Aug 2022 07:11:23 +0200 Subject: cond switch --- bootstrap/parse.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'bootstrap/parse.c') diff --git a/bootstrap/parse.c b/bootstrap/parse.c index bf6b534..74ab2e2 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -2112,6 +2112,37 @@ psteuswitch(struct parser *P, const struct expr *test) { return st; } +static struct stmt +pstcswitch(struct parser *P) { + struct stmt st = {Scswitch}; + struct tok tok; + vec_t(struct cswitchcase) cs = {0}; + struct blockstmt *f = NULL; + + while (!lexmatch(P, &tok, '}')) { + struct cswitchcase c = {0}; + + lexexpect(P, TKkw_case); + + if (lexmatch(P, &tok, TKkw_else)) { + if (f) + fatal(P, tok.span, "duplicate 'case else' block"); + f = malloc(sizeof *f); + *f = parseblock0(P); + } else { + c.test = parseexpr(P); + lexexpect(P, ';'); + c.t = parseblock0(P); + vec_push(&cs, c); + } + } + + vec_slice_cpy(&st.cswitch.cs, &cs); + st.cswitch.f = f; + return st; + +} + static struct stmt pstswitch(struct parser *P) { struct tok tok; @@ -2126,7 +2157,7 @@ pstswitch(struct parser *P) { else fatal(P, test.span, "bad switch test expression (%t)", test.ty); } else { - assert(0 && "NYI"); + return pstcswitch(P); } } -- cgit v1.2.3