diff options
| author | Cliff Click <cliffc@acm.org> | 2024-10-12 14:02:50 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2024-10-13 09:49:57 -0700 |
| commit | f4dee3cff700026b0997aac681752257aa03b4bd (patch) | |
| tree | f843232a06aa4f3e5101e09ee218ac414c1cc90a /chapter15 | |
| parent | 96d028ce004f5b4581997fd1d1a0ccfa87d67ea3 (diff) | |
| download | Simple-f4dee3cff700026b0997aac681752257aa03b4bd.tar.gz Simple-f4dee3cff700026b0997aac681752257aa03b4bd.zip | |
update grammar files
no idea if these are right, but seem closer to the mark
Diffstat (limited to 'chapter15')
| -rw-r--r-- | chapter15/docs/15-grammar.md | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/chapter15/docs/15-grammar.md b/chapter15/docs/15-grammar.md index ec9ac123..0b4ccc04 100644 --- a/chapter15/docs/15-grammar.md +++ b/chapter15/docs/15-grammar.md @@ -1,4 +1,4 @@ -# Grammar for Chapter 14 +# Grammar for Chapter 15 ```antlrv4 grammar SimpleLanguage; @@ -20,7 +20,7 @@ statement | metaStatement ; -type +PRIMTYPE : 'int' | 'i8' | 'i16' @@ -34,9 +34,10 @@ type | 'f64' | 'bool' ; - + field - : type IDENTIFIER ';' + : PRIMTYPE IDENTIFIER ';' + | structName IDENTIFIER ('?')? ';' ; fields @@ -81,7 +82,7 @@ structName ; declStatement - : type IDENTIFIER '=' expression ';' + : PRIMTYPE IDENTIFIER '=' expression ';' | structName IDENTIFIER ('?')? '=' expression ';' ; @@ -110,7 +111,7 @@ additiveExpression ; multiplicativeExpression - : unaryExpression (('*' | '|') unaryExpression)* + : unaryExpression (('*' | '/') unaryExpression)* ; unaryExpression @@ -119,17 +120,13 @@ unaryExpression | primaryExpression ; -arrayExpression - : XXX '[' expression ']' - | primaryExpression - ; - newExpression - : 'new' IDENTIFIER + : 'new' IDENTIFIER ('[' expression ']')? ; fieldExpression : primaryExpresson '.' IDENTIFIER + | primaryExpresson '[' expression ']' ; primaryExpression |
