@@ -15,7 +15,6 @@ class SemanticListener(MyParserListener):
1515 """Checks break and continue statements, variable declarations,types and assignments."""
1616
1717 def __init__ (self ):
18- # super().__init__()
1918 self .nested_loop_counter = 0
2019 self .variables : dict [str , Type | None ] = {}
2120 self .expr_type : dict [
@@ -114,11 +113,24 @@ def exitMinusExpression(self, ctx: MyParser.MinusExpressionContext):
114113 def exitSingleExpression (self , ctx : MyParser .SingleExpressionContext ):
115114 self .expr_type [ctx ] = self .expr_type [ctx .getChild (0 )]
116115
117- def enterSpecialMatrixFunction (self , ctx : MyParser .SpecialMatrixFunctionContext ):
118- pass
119-
120116 def exitSpecialMatrixFunction (self , ctx : MyParser .SpecialMatrixFunctionContext ):
121- pass
117+ dimentions = ctx .children [2 ::2 ]
118+ for dim in dimentions :
119+ if self .expr_type [dim ] != Type .INT :
120+ ctx .parser .notifyErrorListeners (
121+ "Matrix dimentions must be integers" , ctx .getChild (0 ).getSymbol ()
122+ )
123+ self .expr_type [ctx ] = None
124+ break
125+ type_dimentions = []
126+ for dim in dimentions :
127+ if isinstance (dim , MyParser .SingleExpressionContext ) and isinstance (
128+ dim .getChild (0 ), MyParser .IntContext
129+ ):
130+ type_dimentions .append (int (dim .getText ()))
131+ else :
132+ type_dimentions .append (None )
133+ self .expr_type [ctx ] = (Type .INT , * type_dimentions )
122134
123135 def exitVector (self , ctx : MyParser .VectorContext ):
124136 elements = ctx .children [1 ::2 ]
0 commit comments