From 77c272bf67beb30997021947ff8d7fc5cef7b637 Mon Sep 17 00:00:00 2001 From: kdx Date: Mon, 12 Jun 2023 18:43:11 +0200 Subject: return w/o argument --- src/main.c | 14 +++++++++++++- testing.sh | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 9951685..6337b1d 100644 --- a/src/main.c +++ b/src/main.c @@ -107,6 +107,14 @@ tokenize(char *p) continue; } + if (*p == '#') { + char *q = p + 1; + while (*p != '\n' && *p != '\0') { + p += 1; + } + printf("%.*s\n", (int)(p - q), q); + } + if (isspace(*p)) { p++; continue; @@ -677,7 +685,11 @@ static Node * return_stmt(Token **rest, Token *tok) { tok = skip(tok, "return"); - Node *const node = new_unary(NOD_RETURN_STMT, expr(&tok, tok)); + Node *node; + if (equal(tok, ";")) + node = new_unary(NOD_RETURN_STMT, new_num(0)); + else + node = new_unary(NOD_RETURN_STMT, expr(&tok, tok)); *rest = skip(tok, ";"); return node; } diff --git a/testing.sh b/testing.sh index 142103b..6db3877 100755 --- a/testing.sh +++ b/testing.sh @@ -51,4 +51,5 @@ test "$1" "main() { wrt('0' + (9 >= 7)); wrt '\n'; }" test "$1" "main() { local a; dbg a; inc(&a); dbg a; } inc(p) { [p] = [p] + 1; }" test "$1" "global a; main() { dbg a; inc(&a); dbg a; } inc(p) { [p] = [p] + 1; }" test "$1" "main() 0; //ayayayayayayaya comment" +test "$1" "main() return;" rm -f build/tmp.* -- cgit v1.2.3