summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chapter12/docs/12-grammar.md9
-rw-r--r--chapter13/docs/13-grammar.md10
-rw-r--r--chapter14/docs/14-grammar.md11
-rw-r--r--chapter15/docs/15-grammar.md21
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