From 29a380366949cad972f419f205f04f024deca7de Mon Sep 17 00:00:00 2001 From: kdx Date: Tue, 5 Dec 2023 16:17:11 +0100 Subject: inverted division operator --- samples/invertdiv.golem | 5 +++++ src/main.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 samples/invertdiv.golem diff --git a/samples/invertdiv.golem b/samples/invertdiv.golem new file mode 100644 index 0000000..f5413ba --- /dev/null +++ b/samples/invertdiv.golem @@ -0,0 +1,5 @@ +main() { + local x = 5, y = 20; + dbg x / y; + dbg x \ y; +} diff --git a/src/main.c b/src/main.c index 94dae81..e9061b5 100644 --- a/src/main.c +++ b/src/main.c @@ -175,7 +175,7 @@ is_punct(const char *p) if (strchr("|=", p[0]) != NULL && p[1] == '>') return 2; - return (strchr("+-*/%()<>,;{}[]=&^|", p[0]) != NULL); + return (strchr("+-*/\\%()<>,;{}[]=&^|", p[0]) != NULL); } static unsigned char @@ -713,6 +713,10 @@ mul(Token **rest, Token *tok) continue; } + if (equal(tok, "\\")) { + node = new_binary(NOD_DIV, tok, primary(&tok, tok->next), node); + } + if (equal(tok, "%")) { node = new_binary(NOD_MOD, tok, node, primary(&tok, tok->next)); continue; -- cgit v1.2.3