From afcf96444366fb4b7c83f938763013cbc360aade Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 13 Nov 2026 16:17:13 -0800 Subject: Array init syntax New array init syntax; used in a bunch of places. Allows e.g. read-only arrays with not-null entries. Fix bug x86 encoding of mem/cmp/fp compares --- chapter31/docs/31-grammar.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'chapter31/docs/31-grammar.md') diff --git a/chapter31/docs/31-grammar.md b/chapter31/docs/31-grammar.md index 3083fcc2..f4ca76f1 100644 --- a/chapter31/docs/31-grammar.md +++ b/chapter31/docs/31-grammar.md @@ -185,7 +185,14 @@ argumentList : assignment (',' assignment)* ','? ; // Allocation invokes the declared constructor; inline initializer blocks from // earlier chapters are replaced by constructor arguments. -newExpression : 'new' type ('[' assignment ']' | callSuffix)? ; +newExpression + : 'new' type ('[' '~'? assignment ']' arrayInitializer? | arrayInitializer | callSuffix)? + ; +// With no explicit length, type must end in [] or [~] and the initializer is a list. +arrayInitializer + : '{' (assignment (',' assignment)* ','?)? '}' + | '{' ('int' | 'i32' | 'i64' | 'u32') IDENTIFIER '->' statement* '}' + ; INTEGER_LITERAL : [1-9] DIGIT* | '0' [0-7]* | '0' [xX] HEX_DIGIT+ ; // The f suffix also accepts an integer-shaped token, e.g. 12f. @@ -231,7 +238,7 @@ there is no inheritance chain, AST, or additional compiler pass. | `assignment` through `primaryExpression` | [`Expressions`](../src/main/java/com/seaofnodes/simple/parser/Expressions.java): `parseAssignment`, `parseExpression`, `parseLogical`, `parseBitwise`, `parseEquality`, `parseComparison`, `parseShift`, `parseAddition`, `parseMultiplication`, `parseUnary`, `parsePrimary` | | `postfixExpression`, member selection and updates | `Expressions.parsePostfix` / `parsePostfixMethod` dispatch to [`References.parseField`](../src/main/java/com/seaofnodes/simple/parser/References.java); `References.parseName` handles bare names, implicit receivers, and forward references | | `functionExpression`, `parameterList`, calls, `argumentList` | [`Functions`](../src/main/java/com/seaofnodes/simple/parser/Functions.java): `parseFunction`, `parseConstructor`, shared `parameters` and `arguments`, then `parseBody` | -| `newExpression` | [`Allocations.parseNew`](../src/main/java/com/seaofnodes/simple/parser/Allocations.java); the allocation-helper graph builder follows the expression routines | +| `newExpression`, `arrayInitializer` | [`Allocations.parseNew`](../src/main/java/com/seaofnodes/simple/parser/Allocations.java), [`ArrayInitializers`](../src/main/java/com/seaofnodes/simple/parser/ArrayInitializers.java); private initialization, list checks, and generator loops | | `stringExpression`, `interpolation` | [`Strings.parse`](../src/main/java/com/seaofnodes/simple/parser/Strings.java), using `Lexer.stringPart` / `stringFormat`; normal expression parsing resumes inside each interpolation | | Literals, identifiers, comments, token matching | [`Lexer`](../src/main/java/com/seaofnodes/simple/parser/Lexer.java); it also supplies source-location snapshots used by diagnostics and serialized IR | -- cgit v1.2.3