From 3a44f6b614bc1c85f482b7064351a958d6307650 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 25 Nov 2018 04:03:32 +0100 Subject: Lvalues --- source/mod_student/typechecker.ml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source/mod_student/typechecker.ml') diff --git a/source/mod_student/typechecker.ml b/source/mod_student/typechecker.ml index d261f1e..eb5c2a4 100644 --- a/source/mod_student/typechecker.ml +++ b/source/mod_student/typechecker.ml @@ -72,7 +72,7 @@ module Make() = struct check_expression env TP_Int index; begin match infer_expression env expr with - | (TP_Array _) as tp -> tp + | TP_Array tp -> tp | TP_Int -> ErrorReporter.report_expected_array ~loc ~actual:TP_Int | TP_Bool -> ErrorReporter.report_expected_array ~loc ~actual:TP_Bool end @@ -214,10 +214,21 @@ module Make() = struct let infer_lvalue env = function | LVALUE_Id {id;loc;_} -> - failwith "not yet implemented" + begin + match TypingEnvironment.lookup id env with + | None -> ErrorReporter.report_unknown_identifier ~loc ~id + | Some ENVTP_Fn _ -> ErrorReporter.report_identifier_is_not_variable ~loc ~id + | Some ENVTP_Var tp ->tp + end | LVALUE_Index {index; sub; loc} -> - failwith "not yet implemented" + check_expression env TP_Int index; + begin + match infer_expression env sub with + | TP_Int -> ErrorReporter.report_expected_array ~loc ~actual:TP_Int + | TP_Bool -> ErrorReporter.report_expected_array ~loc ~actual:TP_Bool + | TP_Array tp -> tp + end (* --------------------------------------------------- *) -- cgit 1.4.1