From f4dee3cff700026b0997aac681752257aa03b4bd Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 12 Oct 2024 14:02:50 -0700 Subject: update grammar files no idea if these are right, but seem closer to the mark --- chapter12/docs/12-grammar.md | 9 +++++++-- chapter13/docs/13-grammar.md | 10 ++++++++-- chapter14/docs/14-grammar.md | 11 ++++++----- chapter15/docs/15-grammar.md | 21 +++++++++------------ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/chapter12/docs/12-grammar.md b/chapter12/docs/12-grammar.md index 8048bb8c..a576bd7a 100644 --- a/chapter12/docs/12-grammar.md +++ b/chapter12/docs/12-grammar.md @@ -20,8 +20,13 @@ statement | metaStatement ; +PRIMTYPE + : 'int' + | 'flt' + ; + field - : 'int' IDENTIFIER ';' + : PRIMTYPE IDENTIFIER ';' ; fields @@ -66,7 +71,7 @@ structName ; declStatement - : 'int' IDENTIFIER '=' expression ';' + : PRIMTYPE IDENTIFIER '=' expression ';' | structName IDENTIFIER ('?')? '=' expression ';' ; diff --git a/chapter13/docs/13-grammar.md b/chapter13/docs/13-grammar.md index 65611618..63871a39 100644 --- a/chapter13/docs/13-grammar.md +++ b/chapter13/docs/13-grammar.md @@ -20,8 +20,14 @@ statement | metaStatement ; +PRIMTYPE + : 'int' + | 'flt' + ; + field - : 'int' IDENTIFIER ';' + : PRIMTYPE IDENTIFIER ';' + | structName IDENTIFIER ('?')? ';' ; fields @@ -66,7 +72,7 @@ structName ; declStatement - : 'int' IDENTIFIER '=' expression ';' + : PRIMTYPE IDENTIFIER '=' expression ';' | structName IDENTIFIER ('?')? '=' expression ';' ; diff --git a/chapter14/docs/14-grammar.md b/chapter14/docs/14-grammar.md index 4534684d..d7b11d24 100644 --- a/chapter14/docs/14-grammar.md +++ b/chapter14/docs/14-grammar.md @@ -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 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 -- cgit v1.2.3