diff options
author | Paweł Dybiec <pdybiec@stud.cs.uni.wroc.pl> | 2018-11-25 04:03:32 +0100 |
---|---|---|
committer | Paweł Dybiec <pdybiec@stud.cs.uni.wroc.pl> | 2018-11-25 04:03:32 +0100 |
commit | 3a44f6b614bc1c85f482b7064351a958d6307650 (patch) | |
tree | 7f2accaf4aee562a780988bc33348b3c6db8dea1 /source/mod_student | |
parent | MultiVarDecl (diff) |
Lvalues
Diffstat (limited to 'source/mod_student')
-rw-r--r-- | source/mod_student/typechecker.ml | 17 |
1 files changed, 14 insertions, 3 deletions
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 (* --------------------------------------------------- *) |