aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/parse.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-13 07:11:23 +0200
committerlemon <lsof@mailbox.org>2022-08-13 07:11:23 +0200
commit58af6dcf569c7f83b317d30f8dd85d96d314d785 (patch)
tree76d53089d8510ab9cade4e21200b36d648c4ecb6 /bootstrap/parse.c
parentd98b1ecb7a23b369e533f20386cb7aa83156d25d (diff)
cond switch
Diffstat (limited to 'bootstrap/parse.c')
-rw-r--r--bootstrap/parse.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index bf6b534..74ab2e2 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -2113,6 +2113,37 @@ psteuswitch(struct parser *P, const struct expr *test) {
}
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;
struct expr test;
@@ -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);
}
}