feat: 💩 instruction type
This commit is contained in:
parent
1abd8c87d8
commit
415a0249a1
|
@ -72,51 +72,78 @@ let rec analyse_type_expression e =
|
||||||
(* Vérifie la bonne utilisation des identifiants et tranforme l'instruction
|
(* Vérifie la bonne utilisation des identifiants et tranforme l'instruction
|
||||||
en une instruction de type AstType.instruction *)
|
en une instruction de type AstType.instruction *)
|
||||||
(* Erreur si mauvaise utilisation des identifiants *)
|
(* Erreur si mauvaise utilisation des identifiants *)
|
||||||
let rec analyse_type_instruction tds i = failwith "TODO"
|
let rec analyse_type_instruction opt i =
|
||||||
(* match i with
|
match i with
|
||||||
| AstTds.Declaration (t, info, e) ->
|
| AstTds.Declaration (t, info, e) ->
|
||||||
match analyse_type_expr e with
|
begin
|
||||||
| (ne, nt) ->
|
let (ne, nt) = analyse_type_expr e in
|
||||||
if (est_compatible t nt) then
|
if (est_compatible t nt) then
|
||||||
modifier_type_info t info
|
modifier_type_info t info;
|
||||||
AstType.Declaration(info, e)
|
AstType.Declaration(info, ne)
|
||||||
else
|
else
|
||||||
Raise TypeInattendu(t, nt)
|
raise TypeInattendu(t, nt)
|
||||||
|
end
|
||||||
|
|
||||||
| AstTds.Affectation (info, e) ->
|
| AstTds.Affectation (info, e) ->
|
||||||
|
begin
|
||||||
AstType.Affectation (info, e)
|
let (ne, nt) = analyse_type_expr e in
|
||||||
|
match (info_ast_to_info info) with
|
||||||
| AstTds.Constante (n,v) ->
|
| InfoVar(_, t, _, _) ->
|
||||||
|
if est_compatible t nt then
|
||||||
|
AstType.Affectation(info, ne)
|
||||||
|
else
|
||||||
|
raise TypeInattendu(t, nt)
|
||||||
|
| _ -> failwith "wut"
|
||||||
|
end
|
||||||
|
|
||||||
| AstTds.Affichage e ->
|
| AstTds.Affichage e ->
|
||||||
|
begin
|
||||||
|
let (ne, nt) = analyse_type_expr e in
|
||||||
|
match nt with
|
||||||
|
| Int -> AstType.AffciaheInt(ne)
|
||||||
|
| Rat -> AstType.AffciaheRat(ne)
|
||||||
|
| Bool -> AstType.AffichagBool(ne)
|
||||||
|
end
|
||||||
|
|
||||||
| AstTds.Conditionnelle (c,t,e) ->
|
| AstTds.Conditionnelle (e, b1, b2) ->
|
||||||
|
begin
|
||||||
|
let (ne, nt) = analyse_type_expr e in
|
||||||
|
let nb1 = analyse_type_bloc opt b1 in
|
||||||
|
let nb2 = analyse_type_bloc opt b2 in
|
||||||
|
AstType.Conditionnelle(ne, nb1, nb2)
|
||||||
|
end
|
||||||
|
|
||||||
| AstTds.TantQue (c,b) ->
|
| AstTds.TantQue (e, b) ->
|
||||||
|
begin
|
||||||
|
let (ne, nt) = analyse_type_expr e in
|
||||||
|
let nb = analyse_type_bloc b in
|
||||||
|
AstType.Conditionnelle(ne, nb)
|
||||||
|
end
|
||||||
|
|
||||||
| AstTds.Retour (e) -> *)
|
| AstTds.Retour (e) ->
|
||||||
|
begin
|
||||||
|
match opt with
|
||||||
|
| Some(t) ->
|
||||||
|
let (ne, nt) = analyse_type_expr e in
|
||||||
|
if est_compatible t nt then
|
||||||
|
AstType.Retour(ne)
|
||||||
|
else
|
||||||
|
raise TypeInattendu(t, nt)
|
||||||
|
| None -> failwith "Pas de return dans le main"
|
||||||
|
end
|
||||||
|
|
||||||
|
(* analyse_type_bloc : AstTds.bloc -> AstType.bloc *)
|
||||||
|
|
||||||
(* analyse_tds_bloc : AstTds.bloc -> AstType.bloc *)
|
|
||||||
(* Paramètre tds : la table des symboles courante *)
|
(* Paramètre tds : la table des symboles courante *)
|
||||||
(* Paramètre li : liste d'instructions à analyser *)
|
(* Paramètre li : liste d'instructions à analyser *)
|
||||||
(* Vérifie la bonne utilisation des identifiants et tranforme le bloc
|
(* Vérifie la bonne utilisation des identifiants et tranforme le bloc
|
||||||
en un bloc de type AstType.bloc *)
|
en un bloc de type AstType.bloc *)
|
||||||
(* Erreur si mauvaise utilisation des identifiants *)
|
(* Erreur si mauvaise utilisation des identifiants *)
|
||||||
and analyse_tds_bloc tds li =
|
and analyse_type_bloc opt li =
|
||||||
(* Entrée dans un nouveau bloc, donc création d'une nouvelle tds locale
|
let nli = List.map(analyse_type_instruction opt) li in
|
||||||
pointant sur la table du bloc parent *)
|
|
||||||
let tdsbloc = creerTDSFille tds in
|
|
||||||
(* Analyse des instructions du bloc avec la tds du nouveau bloc
|
|
||||||
Cette tds est modifiée par effet de bord *)
|
|
||||||
let nli = List.map (analyse_tds_instruction tdsbloc) li in
|
|
||||||
(* afficher_locale tdsbloc ; *) (* décommenter pour afficher la table locale *)
|
|
||||||
nli
|
nli
|
||||||
|
|
||||||
|
|
||||||
(* analyse_tds_fonction : AstTds.fonction -> AstType.fonction *)
|
(* analyse_type_fonction : AstTds.fonction -> AstType.fonction *)
|
||||||
(* Paramètre tds : la table des symboles courante *)
|
(* Paramètre tds : la table des symboles courante *)
|
||||||
(* Paramètre : la fonction à analyser *)
|
(* Paramètre : la fonction à analyser *)
|
||||||
(* Vérifie la bonne utilisation des identifiants et tranforme la fonction
|
(* Vérifie la bonne utilisation des identifiants et tranforme la fonction
|
||||||
|
@ -127,8 +154,8 @@ en une fonction de type AstType.fonction *)
|
||||||
AstTds.fonction[typ * string * (typ * string) list * bloc] ->
|
AstTds.fonction[typ * string * (typ * string) list * bloc] ->
|
||||||
AstType.fonction[typ * Tds.info_ast * (typ * Tds.info_ast ) list * bloc]
|
AstType.fonction[typ * Tds.info_ast * (typ * Tds.info_ast ) list * bloc]
|
||||||
*)
|
*)
|
||||||
let analyse_tds_fonction maintds (AstTds.Fonction(t, str, l_typstr, bloc)) =
|
let analyse_type_fonction opt (AstTds.Fonction(t, str, l_typstr, bloc)) = failwith "TODO"
|
||||||
begin
|
(* begin
|
||||||
match chercherLocalement maintds str with
|
match chercherLocalement maintds str with
|
||||||
| Some _ -> raise (DoubleDeclaration str)
|
| Some _ -> raise (DoubleDeclaration str)
|
||||||
| None ->
|
| None ->
|
||||||
|
@ -152,7 +179,7 @@ let analyse_tds_fonction maintds (AstTds.Fonction(t, str, l_typstr, bloc)) =
|
||||||
let _ = ajouter tds_bloc str (info_to_info_ast (Tds.InfoFun(str, t, (List.map (fun (t, _) -> t) l_typstr)))) in
|
let _ = ajouter tds_bloc str (info_to_info_ast (Tds.InfoFun(str, t, (List.map (fun (t, _) -> t) l_typstr)))) in
|
||||||
|
|
||||||
(* On génère le nouveau bloc avec la tds locale *)
|
(* On génère le nouveau bloc avec la tds locale *)
|
||||||
let new_bloc = analyse_tds_bloc tds_bloc bloc in
|
let new_bloc = analyse_type_bloc tds_bloc bloc in
|
||||||
|
|
||||||
(* On transforme les (type * str) en (typ * info) *)
|
(* On transforme les (type * str) en (typ * info) *)
|
||||||
let nl_typinfo = List.map (
|
let nl_typinfo = List.map (
|
||||||
|
@ -169,7 +196,7 @@ let analyse_tds_fonction maintds (AstTds.Fonction(t, str, l_typstr, bloc)) =
|
||||||
(* On retourne la AstType fonction *)
|
(* On retourne la AstType fonction *)
|
||||||
AstType.Fonction(t, (info_to_info_ast info), nl_typinfo, new_bloc)
|
AstType.Fonction(t, (info_to_info_ast info), nl_typinfo, new_bloc)
|
||||||
end
|
end
|
||||||
end
|
end *)
|
||||||
|
|
||||||
(* analyser : AstTds.ast -> AstType.ast *)
|
(* analyser : AstTds.ast -> AstType.ast *)
|
||||||
(* Paramètre : le programme à analyser *)
|
(* Paramètre : le programme à analyser *)
|
||||||
|
@ -177,9 +204,8 @@ let analyse_tds_fonction maintds (AstTds.Fonction(t, str, l_typstr, bloc)) =
|
||||||
en un programme de type AstType.ast *)
|
en un programme de type AstType.ast *)
|
||||||
(* Erreur si mauvaise utilisation des identifiants *)
|
(* Erreur si mauvaise utilisation des identifiants *)
|
||||||
let analyser (AstTds.Programme(fonctions, prog)) =
|
let analyser (AstTds.Programme(fonctions, prog)) =
|
||||||
let tds = creerTDSMere () in
|
(* let nf = List.map (analyse_type_fonction Some(...)) fonctions in *)
|
||||||
let nf = List.map (analyse_tds_fonction tds) fonctions in
|
let nb = analyse_type_bloc None prog in
|
||||||
let nb = analyse_tds_bloc tds prog in
|
Programme([], nb)
|
||||||
Programme (nf,nb)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue