Skip to content

Commit b9d1ccc

Browse files
committed
Remove matrix from the grammar, add specialMatrixFunction
`vector` is enough
1 parent aafce3b commit b9d1ccc

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

MyParser.g4

+10-17
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ comparison
4747
;
4848

4949
assignment
50-
: (ID | vectorElementReference | matrixElementReference) assignmentOperator expression SEMICOLON
50+
: (ID | elementReference) assignmentOperator expression SEMICOLON
5151
;
5252

5353
print
@@ -66,17 +66,18 @@ expression
6666
| expression op = (MAT_MULTIPLY | MAT_DIVIDE) expression
6767
| expression op = (PLUS | MINUS) expression
6868
| expression op = (MAT_PLUS | MAT_MINUS) expression
69-
| ZEROS OPEN_BRACKET_ROUND INT CLOSE_BRACKET_ROUND
70-
| ONES OPEN_BRACKET_ROUND INT CLOSE_BRACKET_ROUND
71-
| EYE OPEN_BRACKET_ROUND INT CLOSE_BRACKET_ROUND
69+
| specialMatrixFunction
7270
| ID
7371
| INT
7472
| FLOAT
7573
| STRING
76-
| vectorElementReference
77-
| matrixElementReference
74+
| elementReference
75+
| elementReference
7876
| vector
79-
| matrix
77+
;
78+
79+
specialMatrixFunction
80+
: (ZEROS | ONES | EYE) OPEN_BRACKET_ROUND INT CLOSE_BRACKET_ROUND
8081
;
8182

8283
break
@@ -87,20 +88,12 @@ continue
8788
: CONTINUE SEMICOLON
8889
;
8990

90-
matrix
91-
: OPEN_BRACKET_SQUARE vector (COMMA vector)* CLOSE_BRACKET_SQUARE
92-
;
93-
9491
vector
9592
: OPEN_BRACKET_SQUARE expression (COMMA expression)* CLOSE_BRACKET_SQUARE
9693
;
9794

98-
matrixElementReference
99-
: ID OPEN_BRACKET_SQUARE INT COMMA INT CLOSE_BRACKET_SQUARE
100-
;
101-
102-
vectorElementReference
103-
: ID OPEN_BRACKET_SQUARE INT CLOSE_BRACKET_SQUARE
95+
elementReference
96+
: ID OPEN_BRACKET_SQUARE INT (COMMA INT)* CLOSE_BRACKET_SQUARE
10497
;
10598

10699
assignmentOperator

0 commit comments

Comments
 (0)