feat: ajout du travail du TP2
This commit is contained in:
parent
8e42fa63d1
commit
d7bc456f99
|
@ -17,7 +17,41 @@ struct
|
|||
(* Vérifie la bonne utilisation des identifiants et tranforme l'expression
|
||||
en une expression de type AstTds.expression *)
|
||||
(* Erreur si mauvaise utilisation des identifiants *)
|
||||
let analyse_tds_expression tds e = (AstTds.Booleen true) (* failwith "todo"*)
|
||||
let rec analyse_tds_expression tds e =
|
||||
match e with
|
||||
| AstSyntax.AppelFonction(str, l_expr) ->
|
||||
begin
|
||||
match chercherGlobalement tds str with
|
||||
| None -> raise (IdentifiantNonDeclare str)
|
||||
| Some info -> (* TODO déréférencer le info *)
|
||||
let nl_expr = List.map (fun e -> analyse_tds_expression tds e) l_expr in
|
||||
AstTds.AppelFonction(info, nl_expr)
|
||||
end
|
||||
| AstSyntax.Ident(str) ->
|
||||
begin
|
||||
match chercherGlobalement tds str with
|
||||
| None -> raise (IdentifiantNonDeclare str)
|
||||
| Some info -> AstTds.Ident(info)
|
||||
end
|
||||
| AstSyntax.Booleen(b) ->
|
||||
begin
|
||||
AstTds.Booleen(b)
|
||||
end
|
||||
| AstSyntax.Entier(i) ->
|
||||
begin
|
||||
AstTds.Entier(i)
|
||||
end
|
||||
| AstSyntax.Unaire(u, expr) ->
|
||||
begin
|
||||
let new_expr = analyse_tds_expression tds expr in
|
||||
AstTds.Unaire (u, new_expr)
|
||||
end
|
||||
| AstSyntax.Binaire(b, expr_1, expr_2) ->
|
||||
begin
|
||||
let new_expr_1 = analyse_tds_expression tds expr_1 in
|
||||
let new_expr_2 = analyse_tds_expression tds expr_2 in
|
||||
AstTds.Binaire(b, new_expr_1, new_expr_2)
|
||||
end
|
||||
|
||||
|
||||
(* analyse_tds_instruction : AstSyntax.instruction -> tds -> AstTds.instruction *)
|
||||
|
@ -140,8 +174,30 @@ and analyse_tds_bloc tds li =
|
|||
(* Vérifie la bonne utilisation des identifiants et tranforme la fonction
|
||||
en une fonction de type AstTds.fonction *)
|
||||
(* Erreur si mauvaise utilisation des identifiants *)
|
||||
let analyse_tds_fonction maintds (AstSyntax.Fonction(t,n,lp,li)) =
|
||||
failwith "TO DO"
|
||||
(*
|
||||
tds ->
|
||||
AstSyntax.fonction[typ * string * (typ * string) list * bloc] ->
|
||||
AstTds.fonction[typ * Tds.info_ast * (typ * Tds.info_ast ) list * bloc]
|
||||
*)
|
||||
let analyse_tds_fonction maintds (AstSyntax.Fonction(t, str, l_typstr, bloc)) =
|
||||
begin
|
||||
match chercherLocalement maintds str with
|
||||
| Some _ -> raise (DoubleDeclaration str)
|
||||
| None ->
|
||||
begin
|
||||
let info = Tds.InfoVar(str, Undefined, 0, "") in
|
||||
let tds_bloc = List.fold_right (
|
||||
fun (_, nom) qres ->
|
||||
ajouter qres nom (info_to_info_ast (Tds.InfoVar(nom, Undefined, 0, "")))
|
||||
) l_typstr (creerTDSFille maintds) in
|
||||
let new_bloc = analyse_tds_bloc tds_bloc bloc in
|
||||
let nl_typinfo = List.map (
|
||||
fun (t, str2) ->
|
||||
( t, info_to_info_ast (Tds.InfoVar(str2, Undefined, 0, "")) )
|
||||
) l_typstr in
|
||||
AstTds.Fonction(t, (info_to_info_ast info), nl_typinfo, new_bloc)
|
||||
end
|
||||
end
|
||||
|
||||
(* analyser : AstSyntax.ast -> AstTds.ast *)
|
||||
(* Paramètre : le programme à analyser *)
|
||||
|
|
|
@ -45,6 +45,7 @@ let ajouter tds nom info =
|
|||
|
||||
(* Recherche les informations d'un identificateur dans la tds locale *)
|
||||
(* Ne cherche que dans la tds de plus bas niveau *)
|
||||
(* tds -> string -> info_ast option = <fun> *)
|
||||
let chercherLocalement tds nom =
|
||||
match tds with
|
||||
| Nulle -> None
|
||||
|
|
212
src/testTDS.ml
212
src/testTDS.ml
|
@ -8,116 +8,115 @@ exception ErreurNonDetectee;;
|
|||
(* Sans fonction *)
|
||||
(* ------------------------------ *)
|
||||
|
||||
(*
|
||||
let%test_unit "testAffectation1" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation1.rat" in ()
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation1.rat" in ()
|
||||
|
||||
let%test_unit "testAffectation2"=
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation2.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation2.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
|
||||
let%test_unit "testAffectation3" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation3.rat" in ()
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation3.rat" in ()
|
||||
|
||||
let%test_unit "testAffectation4" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation4.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| MauvaiseUtilisationIdentifiant("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testAffectation4.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| MauvaiseUtilisationIdentifiant("x") -> ()
|
||||
|
||||
let%test_unit "testUtilisation1" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation1.rat" in ()
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation1.rat" in ()
|
||||
|
||||
let%test_unit "testUtilisation2" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation2.rat" in ()
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation2.rat" in ()
|
||||
|
||||
let%test_unit "testUtilisation3" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation3.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation3.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
|
||||
let%test_unit "testUtilisation10" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation10.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation10.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("x") -> ()
|
||||
|
||||
let%test_unit "testUtilisation11" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation11.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation11.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
|
||||
let%test_unit "testUtilisation12" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation12.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation12.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
|
||||
let%test_unit "testUtilisation13" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation13.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation13.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
|
||||
let%test_unit "testUtilisation14" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation14.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation14.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
|
||||
let%test_unit "testUtilisation15" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation15.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation15.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("z") -> ()
|
||||
|
||||
let%test_unit "testUtilisation16" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation16.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation16.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
|
||||
let%test_unit "testUtilisation17" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation17.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation17.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
|
||||
let%test_unit "testUtilisation18" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation18.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation18.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
|
||||
let%test_unit "testUtilisation19" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation19.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testUtilisation19.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("y") -> ()
|
||||
|
||||
let%test_unit "testRecursiviteVariable" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testRecursiviteVariable.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testRecursiviteVariable.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| IdentifiantNonDeclare("x") -> ()
|
||||
|
||||
(* Fichiers de tests de la génération de code -> doivent passer la TDS *)
|
||||
|
||||
|
@ -158,54 +157,53 @@ let%test_unit "code_testif2" =
|
|||
let _ = compiler "../../fichiersRat/src-rat-tam-test/testif2.rat" in ()
|
||||
|
||||
let%test_unit "code_factiter" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tam-test/factiter.rat" in ()
|
||||
*)
|
||||
let _ = compiler "../../fichiersRat/src-rat-tam-test/factiter.rat" in ()
|
||||
|
||||
|
||||
(* ------------------------------ *)
|
||||
(* Avec fonction *)
|
||||
(* ------------------------------ *)
|
||||
|
||||
(*
|
||||
let%test_unit "testDoubleDeclarationVariable1" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable1.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable1.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
|
||||
let%test_unit "testDoubleDeclarationVariable2" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable2.rat" in ()
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable2.rat" in ()
|
||||
|
||||
let%test_unit "testDoubleDeclarationVariable3" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable3.rat" in ()
|
||||
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable3.rat" in ()
|
||||
|
||||
let%test_unit "testDoubleDeclarationVariable4" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable4.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable4.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
|
||||
let%test_unit "testDoubleDeclarationVariable5" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable5.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable5.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
|
||||
let%test_unit "testDoubleDeclarationVariable6" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable6.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable6.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
|
||||
let%test_unit "testDoubleDeclarationVariable7" =
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable7.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
try
|
||||
let _ = compiler "../../fichiersRat/src-rat-tds-test/testDoubleDeclarationVariable7.rat"
|
||||
in raise ErreurNonDetectee
|
||||
with
|
||||
| DoubleDeclaration("x") -> ()
|
||||
|
||||
let%test_unit "testAffectation5" =
|
||||
try
|
||||
|
@ -356,5 +354,3 @@ let%test_unit "code_testfuns" =
|
|||
|
||||
let%test_unit "code_complique" =
|
||||
let _ = compiler "../../fichiersRat/src-rat-tam-test/complique.rat" in ()
|
||||
|
||||
*)
|
||||
|
|
Loading…
Reference in a new issue