From 0543c146ad5904e3f7ad5a6208e9f30f72f47ca5 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 1 Jul 2024 19:58:46 +0200 Subject: Support assignments to mutable variables --- README | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'README') diff --git a/README b/README index c00a5d9..bf648e1 100644 --- a/README +++ b/README @@ -149,3 +149,22 @@ The build script also accepts some subcommands. They are as follows: returns_42′ :: () int { return --x; } + +9. Assignment statements (not expressions). Unlike in C, you cannot put + an assignment inside of an expression. + + return_42 :: () int { + x := 4; + y := 2; + x = x*10 + y; + return x; + } + + Due to quirks of the language grammar identifiers may be wrapped in + (arbitrary levels of) parenthesis, however assignments are only + permitted if the left-hand side with parenthesis removed is a lone + identifier. The rationale behind this is to allow in the future + assignments to expressions that return pointers. + + ((x)) = x*10 + y; /* legal */ + (true ? x : y) = x*10 + y; /* illegal */ -- cgit v1.2.3