Skip to content

Commit 5b97bc5

Browse files
authored
Fix eye function (#3)
1 parent a9308cb commit 5b97bc5

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

semantic_listener.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ def exitSpecialMatrixFunction(self, ctx: MyParser.SpecialMatrixFunctionContext):
170170
type_dimentions.append(int(dim.getText()))
171171
else:
172172
type_dimentions.append(None)
173-
self.expr_type[ctx] = (Type.INT, *type_dimentions)
173+
if ctx.getChild(0).symbol.type == MyParser.EYE:
174+
assert len(type_dimentions) == 1
175+
self.expr_type[ctx] = (Type.INT, type_dimentions[0], type_dimentions[0])
176+
else:
177+
self.expr_type[ctx] = (Type.INT, *type_dimentions)
174178

175179
def exitVector(self, ctx: MyParser.VectorContext):
176180
elements = ctx.children[1::2]

tests/ast/input_3.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
a = 2 * (2 + 2) + 2 * 2;
22
b = 3 * -3;
3-
C = 2 .+ 2 .* ones(3)';
3+
C = 2 .+ 2 .* eye(3)';

tests/ast/output_3.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
| | .*
2323
| | | 2
2424
| | | transpose
25-
| | | | ones
25+
| | | | eye
2626
| | | | | 3

tests/semantic/input_special_matrix.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ C = zeros(2, n);
99
m = 3.14;
1010

1111
D = eye(m);
12+
13+
print eye(3) .+ ones(3, 3) .+ zeros(3, 3);

0 commit comments

Comments
 (0)