summaryrefslogtreecommitdiff
path: root/chapter31/docs/31-grammar.md
diff options
context:
space:
mode:
Diffstat (limited to 'chapter31/docs/31-grammar.md')
-rw-r--r--chapter31/docs/31-grammar.md17
1 files changed, 12 insertions, 5 deletions
diff --git a/chapter31/docs/31-grammar.md b/chapter31/docs/31-grammar.md
index 3083fcc2..37300c46 100644
--- a/chapter31/docs/31-grammar.md
+++ b/chapter31/docs/31-grammar.md
@@ -64,7 +64,7 @@ constructorParameterList : (constructorParameter ','?)+ ;
constructorParameter : type '^'? bindingModifier? IDENTIFIER ;
// ^ accepts an unfinished struct reference; ? independently permits null.
// Only self may be read while incomplete; ^ arguments may be stored/forwarded.
-// A new result is incomplete iff an actual argument is. See construction-groups.md.
+// A new result is incomplete iff an actual argument is. See ../../chapter29/README.md#incomplete-types.
// A method is an ordinary fixed function binding in a struct definition.
// The compiler supplies self; it is not written in parameterList.
@@ -102,7 +102,7 @@ primitiveType
assignment : expression (assignmentOperator assignment)? ;
assignmentOperator
- : '=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^='
+ : '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
| '<<=' | '>>=' | '>>>='
;
@@ -133,7 +133,7 @@ additiveExpression
;
multiplicativeExpression
- : unaryExpression (('*' | '/') unaryExpression)*
+ : unaryExpression (('*' | '/' | '%') unaryExpression)*
;
unaryExpression
@@ -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 |