feat: ca avance
This commit is contained in:
parent
3b73128050
commit
33ccff335a
34
src/ast.ml
34
src/ast.ml
|
@ -33,8 +33,6 @@ type affectable =
|
||||||
type expression =
|
type expression =
|
||||||
(* Appel de fonction représenté par le nom de la fonction et la liste des paramètres réels *)
|
(* Appel de fonction représenté par le nom de la fonction et la liste des paramètres réels *)
|
||||||
| AppelFonction of string * expression list
|
| AppelFonction of string * expression list
|
||||||
(* Accès à un identifiant représenté par son nom *)
|
|
||||||
| Ident of string
|
|
||||||
(* Booléen *)
|
(* Booléen *)
|
||||||
| Booleen of bool
|
| Booleen of bool
|
||||||
(* Entier *)
|
(* Entier *)
|
||||||
|
@ -87,16 +85,25 @@ end
|
||||||
module AstTds =
|
module AstTds =
|
||||||
struct
|
struct
|
||||||
|
|
||||||
|
type affectable =
|
||||||
|
(* Dé-référencement d'un affectable *)
|
||||||
|
| Dref of affectable
|
||||||
|
(* Identifiant *)
|
||||||
|
| Ident of Tds.info_ast
|
||||||
|
|
||||||
(* Expressions existantes dans notre langage *)
|
(* Expressions existantes dans notre langage *)
|
||||||
(* ~ expression de l'AST syntaxique où les noms des identifiants ont été
|
(* ~ expression de l'AST syntaxique où les noms des identifiants ont été
|
||||||
remplacés par les informations associées aux identificateurs *)
|
remplacés par les informations associées aux identificateurs *)
|
||||||
type expression =
|
type expression =
|
||||||
| AppelFonction of Tds.info_ast * expression list
|
| AppelFonction of Tds.info_ast * expression list
|
||||||
| Ident of Tds.info_ast (* le nom de l'identifiant est remplacé par ses informations *)
|
|
||||||
| Booleen of bool
|
| Booleen of bool
|
||||||
| Entier of int
|
| Entier of int
|
||||||
| Unaire of AstSyntax.unaire * expression
|
| Unaire of AstSyntax.unaire * expression
|
||||||
| Binaire of AstSyntax.binaire * expression * expression
|
| Binaire of AstSyntax.binaire * expression * expression
|
||||||
|
| Affectable of affectable
|
||||||
|
| Null
|
||||||
|
| NewType of typ
|
||||||
|
| Adresse of Tds.info_ast
|
||||||
|
|
||||||
(* instructions existantes dans notre langage *)
|
(* instructions existantes dans notre langage *)
|
||||||
(* ~ instruction de l'AST syntaxique où les noms des identifiants ont été
|
(* ~ instruction de l'AST syntaxique où les noms des identifiants ont été
|
||||||
|
@ -105,7 +112,7 @@ struct
|
||||||
type bloc = instruction list
|
type bloc = instruction list
|
||||||
and instruction =
|
and instruction =
|
||||||
| Declaration of typ * Tds.info_ast * expression (* le nom de l'identifiant est remplacé par ses informations *)
|
| Declaration of typ * Tds.info_ast * expression (* le nom de l'identifiant est remplacé par ses informations *)
|
||||||
| Affectation of Tds.info_ast * expression (* le nom de l'identifiant est remplacé par ses informations *)
|
| Affectation of affectable * expression (* le nom de l'identifiant est remplacé par ses informations *)
|
||||||
| Affichage of expression
|
| Affichage of expression
|
||||||
| Conditionnelle of expression * bloc * bloc
|
| Conditionnelle of expression * bloc * bloc
|
||||||
| TantQue of expression * bloc
|
| TantQue of expression * bloc
|
||||||
|
@ -135,15 +142,24 @@ type unaire = Numerateur | Denominateur
|
||||||
(* Opérateurs binaires existants dans Rat - résolution de la surcharge *)
|
(* Opérateurs binaires existants dans Rat - résolution de la surcharge *)
|
||||||
type binaire = Fraction | PlusInt | PlusRat | MultInt | MultRat | EquInt | EquBool | Inf
|
type binaire = Fraction | PlusInt | PlusRat | MultInt | MultRat | EquInt | EquBool | Inf
|
||||||
|
|
||||||
|
type affectable =
|
||||||
|
(* Dé-référencement d'un affectable *)
|
||||||
|
| Dref of affectable
|
||||||
|
(* Identifiant *)
|
||||||
|
| Ident of Tds.info_ast
|
||||||
|
|
||||||
(* Expressions existantes dans Rat *)
|
(* Expressions existantes dans Rat *)
|
||||||
(* = expression de AstTds *)
|
(* = expression de AstTds *)
|
||||||
type expression =
|
type expression =
|
||||||
| AppelFonction of Tds.info_ast * expression list
|
| AppelFonction of Tds.info_ast * expression list
|
||||||
| Ident of Tds.info_ast
|
|
||||||
| Booleen of bool
|
| Booleen of bool
|
||||||
| Entier of int
|
| Entier of int
|
||||||
| Unaire of unaire * expression
|
| Unaire of unaire * expression
|
||||||
| Binaire of binaire * expression * expression
|
| Binaire of binaire * expression * expression
|
||||||
|
| Affectable of affectable
|
||||||
|
| Null
|
||||||
|
| NewType of typ
|
||||||
|
| Adresse of Tds.info_ast
|
||||||
|
|
||||||
(* instructions existantes Rat *)
|
(* instructions existantes Rat *)
|
||||||
(* = instruction de AstTds + informations associées aux identificateurs, mises à jour *)
|
(* = instruction de AstTds + informations associées aux identificateurs, mises à jour *)
|
||||||
|
@ -151,7 +167,7 @@ type expression =
|
||||||
type bloc = instruction list
|
type bloc = instruction list
|
||||||
and instruction =
|
and instruction =
|
||||||
| Declaration of Tds.info_ast * expression
|
| Declaration of Tds.info_ast * expression
|
||||||
| Affectation of Tds.info_ast * expression
|
| Affectation of affectable * expression
|
||||||
| AffichageInt of expression
|
| AffichageInt of expression
|
||||||
| AffichageRat of expression
|
| AffichageRat of expression
|
||||||
| AffichageBool of expression
|
| AffichageBool of expression
|
||||||
|
@ -202,9 +218,3 @@ type programme = Programme of fonction list * bloc
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
(* Conversion des affectables *)
|
|
||||||
let rec string_of_affectable a =
|
|
||||||
match a with
|
|
||||||
| AstSyntax.Dref(n) -> (string_of_affectable n)
|
|
||||||
| AstSyntax.Ident(n) -> n ^ " "
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
(* Compilateur créant l'AST *)
|
(* Compilateur créant l'AST *)
|
||||||
(* module CompilateurRat = Compilateur (PasseTdsNop) (PasseNop) (PasseNop) (PasseCodeNopNop) *)
|
module CompilateurRat = Compilateur (PasseTdsNop) (PasseNop) (PasseNop) (PasseCodeNopNop)
|
||||||
|
|
||||||
|
|
||||||
(* + passe de résolution des identifiants *)
|
(* + passe de résolution des identifiants *)
|
||||||
|
@ -54,11 +54,11 @@ module CompilateurRat = Compilateur (PasseTdsRat) (PasseTypeRat) (PassePlacement
|
||||||
|
|
||||||
|
|
||||||
(* + passe de génération de code -> compilateur complet *)
|
(* + passe de génération de code -> compilateur complet *)
|
||||||
open PasseTdsRat
|
(* open PasseTdsRat
|
||||||
open PasseTypeRat
|
open PasseTypeRat
|
||||||
open PassePlacementRat
|
open PassePlacementRat
|
||||||
open PasseCodeRatToTam
|
open PasseCodeRatToTam
|
||||||
module CompilateurRat = Compilateur (PasseTdsRat) (PasseTypeRat) (PassePlacementRat) (PasseCodeRatToTam)
|
module CompilateurRat = Compilateur (PasseTdsRat) (PasseTypeRat) (PassePlacementRat) (PasseCodeRatToTam) *)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -70,14 +70,14 @@ is :
|
||||||
| i1=i li=is {i1::li}
|
| i1=i li=is {i1::li}
|
||||||
|
|
||||||
i :
|
i :
|
||||||
| t=typ n=ID EQUAL e1=e PV {Declaration (t,n,e1)}
|
| t=typ n=ID EQUAL exp=e PV {Declaration (t,n,exp)}
|
||||||
| n=ID EQUAL e1=e PV {Affectation (n,e1)}
|
| n=ID EQUAL exp=e PV {Affectation (Ident(n),exp)}
|
||||||
| CONST n=ID EQUAL e=ENTIER PV {Constante (n,e)}
|
| CONST n=ID EQUAL e=ENTIER PV {Constante (n,e)}
|
||||||
| PRINT e1=e PV {Affichage (e1)}
|
| PRINT exp=e PV {Affichage (exp)}
|
||||||
| IF exp=e li1=bloc ELSE li2=bloc {Conditionnelle (exp,li1,li2)}
|
| IF exp=e li1=bloc ELSE li2=bloc {Conditionnelle (exp,li1,li2)}
|
||||||
| WHILE exp=e li=bloc {TantQue (exp,li)}
|
| WHILE exp=e li=bloc {TantQue (exp,li)}
|
||||||
| RETURN exp=e PV {Retour (exp)}
|
| RETURN exp=e PV {Retour (exp)}
|
||||||
| a1=a EQUAL exp=e1 {Affectation(Deref(a1), e1)}
|
| aff=a EQUAL exp=e {Affectation (aff, exp)}
|
||||||
|
|
||||||
dp :
|
dp :
|
||||||
| {[]}
|
| {[]}
|
||||||
|
@ -87,7 +87,7 @@ typ :
|
||||||
| BOOL {Bool}
|
| BOOL {Bool}
|
||||||
| INT {Int}
|
| INT {Int}
|
||||||
| RAT {Rat}
|
| RAT {Rat}
|
||||||
| t1=typ MULT {Deref t1}
|
| t1=typ MULT {Pointeur (t1)}
|
||||||
|
|
||||||
e :
|
e :
|
||||||
| CALL n=ID PO lp=cp PF {AppelFonction (n,lp)}
|
| CALL n=ID PO lp=cp PF {AppelFonction (n,lp)}
|
||||||
|
@ -103,14 +103,14 @@ e :
|
||||||
| PO e1=e INF e2=e PF {Binaire (Inf,e1,e2)}
|
| PO e1=e INF e2=e PF {Binaire (Inf,e1,e2)}
|
||||||
| PO exp=e PF {exp}
|
| PO exp=e PF {exp}
|
||||||
| a1=a {Affectable a1}
|
| a1=a {Affectable a1}
|
||||||
| NULL { ??? }
|
| NULL {Null}
|
||||||
| PO NEW t1=typ PF { ??? }
|
| PO NEW t1=typ PF {NewType (t1)}
|
||||||
| AMP n=ID { Deref n }
|
| AMP n=ID {Adresse (n)}
|
||||||
|
|
||||||
cp :
|
cp :
|
||||||
| {[]}
|
| {[]}
|
||||||
| e1=e le=cp {e1::le}
|
| e1=e le=cp {e1::le}
|
||||||
|
|
||||||
a :
|
a :
|
||||||
| n=ID {Ident n}
|
| n=ID {Ident (n)}
|
||||||
| PO MULT a1=a PF {Deref a1}
|
| PO MULT a1=a PF {Dref (a1)}
|
|
@ -21,9 +21,9 @@ let rec analyse_code_expression e =
|
||||||
"CALL (ST) " ^ nom ^ "\n"
|
"CALL (ST) " ^ nom ^ "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
| Ident(i) ->
|
(* | Ident(i) ->
|
||||||
let InfoVar(_,t,base,reg) = info_ast_to_info i in
|
let InfoVar(_,t,base,reg) = info_ast_to_info i in
|
||||||
"LOAD (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n"
|
"LOAD (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n" *)
|
||||||
|
|
||||||
| Booleen(b) ->
|
| Booleen(b) ->
|
||||||
if b then
|
if b then
|
||||||
|
|
|
@ -6,11 +6,38 @@ struct
|
||||||
open Exceptions
|
open Exceptions
|
||||||
open Ast
|
open Ast
|
||||||
open AstTds
|
open AstTds
|
||||||
|
open PrinterAst
|
||||||
|
|
||||||
type t1 = Ast.AstSyntax.programme
|
type t1 = Ast.AstSyntax.programme
|
||||||
type t2 = Ast.AstTds.programme
|
type t2 = Ast.AstTds.programme
|
||||||
|
|
||||||
|
|
||||||
|
let rec analyse_tds_affectable tds a modif =
|
||||||
|
match a with
|
||||||
|
| AstSyntax.Dref new_aff ->
|
||||||
|
let x = analyse_tds_affectable tds new_aff true in
|
||||||
|
AstTds.Dref(x)
|
||||||
|
|
||||||
|
| AstSyntax.Ident n ->
|
||||||
|
begin
|
||||||
|
match (chercherGlobalement tds n) with
|
||||||
|
| None -> raise (IdentifiantNonDeclare n)
|
||||||
|
| Some info ->
|
||||||
|
begin
|
||||||
|
match (info_ast_to_info info) with
|
||||||
|
| InfoVar _ -> AstTds.Ident(info)
|
||||||
|
| InfoConst _ ->
|
||||||
|
begin
|
||||||
|
if modif then
|
||||||
|
failwith "bah non en fait"
|
||||||
|
else
|
||||||
|
AstTds.Ident(info)
|
||||||
|
end
|
||||||
|
| InfoFun _ -> failwith "t chelou bro"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
(* analyse_tds_expression : AstSyntax.expression -> AstTds.expression *)
|
(* analyse_tds_expression : AstSyntax.expression -> AstTds.expression *)
|
||||||
(* Paramètre tds : la table des symboles courante *)
|
(* Paramètre tds : la table des symboles courante *)
|
||||||
(* Paramètre e : l'expression à analyser *)
|
(* Paramètre e : l'expression à analyser *)
|
||||||
|
@ -34,21 +61,7 @@ let rec analyse_tds_expression tds e =
|
||||||
(* L'identifiant ne fait pas référence à une fonction, on lève ue exception *)
|
(* L'identifiant ne fait pas référence à une fonction, on lève ue exception *)
|
||||||
| _ -> raise (MauvaiseUtilisationIdentifiant str)
|
| _ -> raise (MauvaiseUtilisationIdentifiant str)
|
||||||
end
|
end
|
||||||
| AstSyntax.Ident(str) ->
|
|
||||||
begin
|
|
||||||
match chercherGlobalement tds str with
|
|
||||||
(* L'identifiant n'est pas déclaré *)
|
|
||||||
| None -> raise (IdentifiantNonDeclare str)
|
|
||||||
| Some info ->
|
|
||||||
match (info_ast_to_info info) with
|
|
||||||
| InfoVar(_, _, _, _) ->
|
|
||||||
AstTds.Ident(info)
|
|
||||||
| InfoConst(_, v) ->
|
|
||||||
AstTds.Entier(v)
|
|
||||||
|
|
||||||
(** L'identifiant fait référence a une fonction lors de l'association a une varibale, on lève une exception *)
|
|
||||||
| _ -> raise (MauvaiseUtilisationIdentifiant str)
|
|
||||||
end
|
|
||||||
| AstSyntax.Booleen(b) ->
|
| AstSyntax.Booleen(b) ->
|
||||||
begin
|
begin
|
||||||
AstTds.Booleen(b)
|
AstTds.Booleen(b)
|
||||||
|
@ -68,7 +81,20 @@ let rec analyse_tds_expression tds e =
|
||||||
let new_expr_2 = analyse_tds_expression tds expr_2 in
|
let new_expr_2 = analyse_tds_expression tds expr_2 in
|
||||||
AstTds.Binaire(b, new_expr_1, new_expr_2)
|
AstTds.Binaire(b, new_expr_1, new_expr_2)
|
||||||
end
|
end
|
||||||
|
| AstSyntax.Affectable(a) -> AstTds.Affectable(analyse_tds_affectable tds a false)
|
||||||
|
| AstSyntax.Null -> AstTds.Null
|
||||||
|
| AstSyntax.NewType(t) -> AstTds.NewType(t)
|
||||||
|
| AstSyntax.Adresse(n) ->
|
||||||
|
let info = chercherGlobalement tds n in
|
||||||
|
match info with
|
||||||
|
| None ->
|
||||||
|
raise (IdentifiantNonDeclare n)
|
||||||
|
| Some i ->
|
||||||
|
begin
|
||||||
|
match (info_ast_to_info i) with
|
||||||
|
| InfoVar _ -> AstTds.Adresse(i)
|
||||||
|
| _ -> raise (MauvaiseUtilisationIdentifiant(n))
|
||||||
|
end
|
||||||
|
|
||||||
(* analyse_tds_instruction : AstSyntax.instruction -> tds -> AstTds.instruction *)
|
(* analyse_tds_instruction : AstSyntax.instruction -> tds -> AstTds.instruction *)
|
||||||
(* Paramètre tds : la table des symboles courante *)
|
(* Paramètre tds : la table des symboles courante *)
|
||||||
|
@ -101,27 +127,33 @@ let rec analyse_tds_instruction tds i =
|
||||||
il a donc déjà été déclaré dans le bloc courant *)
|
il a donc déjà été déclaré dans le bloc courant *)
|
||||||
raise (DoubleDeclaration n)
|
raise (DoubleDeclaration n)
|
||||||
end
|
end
|
||||||
| AstSyntax.Affectation (n,e) ->
|
| AstSyntax.Affectation (aff, e) ->
|
||||||
begin
|
begin
|
||||||
match chercherGlobalement tds (string_of_affectable n) with
|
let ne = analyse_tds_expression tds e in
|
||||||
| None ->
|
let n_a = analyse_tds_affectable tds a true in
|
||||||
(* L'identifiant n'est pas trouvé dans la tds globale. *)
|
match aff with
|
||||||
raise (IdentifiantNonDeclare (string_of_affectable n))
|
| Dref a ->
|
||||||
| Some info ->
|
Affectation (n_a, ne)
|
||||||
(* L'identifiant est trouvé dans la tds globale,
|
|
||||||
il a donc déjà été déclaré. L'information associée est récupérée. *)
|
| Ident(n) ->
|
||||||
begin
|
begin
|
||||||
match info_ast_to_info info with
|
match chercherGlobalement tds n with
|
||||||
| InfoVar _ ->
|
| None ->
|
||||||
(* Vérification de la bonne utilisation des identifiants dans l'expression *)
|
(* L'identifiant n'est pas trouvé dans la tds globale. *)
|
||||||
(* et obtention de l'expression transformée *)
|
raise (IdentifiantNonDeclare n)
|
||||||
let ne = analyse_tds_expression tds e in
|
| Some info ->
|
||||||
(* Renvoie de la nouvelle affectation où le nom a été remplacé par l'information
|
(* L'identifiant est trouvé dans la tds globale,
|
||||||
et l'expression remplacée par l'expression issue de l'analyse *)
|
il a donc déjà été déclaré. L'information associée est récupérée. *)
|
||||||
Affectation (info, ne)
|
begin
|
||||||
| _ ->
|
match info_ast_to_info info with
|
||||||
(* Modification d'une constante ou d'une fonction *)
|
| InfoVar _ ->
|
||||||
raise (MauvaiseUtilisationIdentifiant (string_of_affectable n))
|
(* Renvoie de la nouvelle affectation où le nom a été remplacé par l'information
|
||||||
|
et l'expression remplacée par l'expression issue de l'analyse *)
|
||||||
|
Affectation (n_a, ne)
|
||||||
|
| _ ->
|
||||||
|
(* Modification d'une constante ou d'une fonction *)
|
||||||
|
raise (MauvaiseUtilisationIdentifiant n)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
| AstSyntax.Constante (n,v) ->
|
| AstSyntax.Constante (n,v) ->
|
||||||
|
|
|
@ -12,6 +12,41 @@ struct
|
||||||
type t2 = Ast.AstType.programme
|
type t2 = Ast.AstType.programme
|
||||||
|
|
||||||
|
|
||||||
|
let rec analyse_type_affectable a =
|
||||||
|
match a with
|
||||||
|
| AstTds.Dref(a) ->
|
||||||
|
begin
|
||||||
|
match (analyse_type_affectable a) with
|
||||||
|
| (na, Pointeur t) -> (AstType.Dref(na), t)
|
||||||
|
| _ -> failwith "jsp koi mettre ici"
|
||||||
|
end
|
||||||
|
| AstTds.Ident(info) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info info with
|
||||||
|
| InfoVar(_, t, _, _) -> (AstType.Ident(info), t)
|
||||||
|
| InfoConst _ -> (AstType.Ident(info), Int)
|
||||||
|
| InfoFun _ -> failwith "c chelou frr"
|
||||||
|
end
|
||||||
|
|
||||||
|
(*
|
||||||
|
let rec analyse_type_affectable (aff:AstTds.affectable) : (affectable*typ) =
|
||||||
|
match aff with
|
||||||
|
| AstTds.Ident info ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info info with
|
||||||
|
| InfoVar (_,t,_,_) -> (Ident info, t)
|
||||||
|
| InfoConst _ -> (Ident info, Int)
|
||||||
|
| _ -> failwith ("Erreur interne : symbole non reconnnu")
|
||||||
|
end
|
||||||
|
| AstTds.Valeur aff ->
|
||||||
|
begin
|
||||||
|
match analyse_type_affectable aff with
|
||||||
|
| (naff, Pointeur t) -> (Valeur(naff, t),t)
|
||||||
|
| _ -> raise PasUnPointeur
|
||||||
|
end
|
||||||
|
*)
|
||||||
|
|
||||||
|
|
||||||
(* analyse_tds_expression : AstTds.expression -> (AstType.expression, type) *)
|
(* analyse_tds_expression : AstTds.expression -> (AstType.expression, type) *)
|
||||||
(* Paramètre tds : la table des symboles courante *)
|
(* Paramètre tds : la table des symboles courante *)
|
||||||
(* Paramètre e : l'expression à analyser *)
|
(* Paramètre e : l'expression à analyser *)
|
||||||
|
@ -60,18 +95,22 @@ let rec analyse_type_expression e =
|
||||||
| _, _, _ -> raise (TypeBinaireInattendu(b, t1, t2))
|
| _, _, _ -> raise (TypeBinaireInattendu(b, t1, t2))
|
||||||
end
|
end
|
||||||
|
|
||||||
| AstTds.Ident(info) ->
|
|
||||||
begin
|
|
||||||
match (info_ast_to_info info) with
|
|
||||||
| InfoVar(_, t, _, _) -> (AstType.Ident(info), t)
|
|
||||||
| InfoConst(_, _) -> (AstType.Ident(info), Int)
|
|
||||||
| _ -> failwith "un truc chelou encore"
|
|
||||||
end
|
|
||||||
|
|
||||||
| AstTds.Booleen(b) -> (AstType.Booleen(b), Bool)
|
| AstTds.Booleen(b) -> (AstType.Booleen(b), Bool)
|
||||||
|
|
||||||
| AstTds.Entier(i) -> (AstType.Entier(i), Int)
|
| AstTds.Entier(i) -> (AstType.Entier(i), Int)
|
||||||
|
|
||||||
|
| AstTds.Affectable(a) ->
|
||||||
|
let (n_a, n_t) = analyse_type_affectable a in
|
||||||
|
(AstType.Affectable(n_a), n_t)
|
||||||
|
|
||||||
|
| AstTds.Null -> (AstType.Null, Pointeur(Undefined))
|
||||||
|
|
||||||
|
| AstTds.NewType(t) -> (AstType.NewType(t), Pointeur(t))
|
||||||
|
|
||||||
|
| AstTds.Adresse(info) ->
|
||||||
|
let _ = modifier_type_info Int info in
|
||||||
|
(AstType.Adresse(info), Int)
|
||||||
|
|
||||||
(* analyse_tds_instruction : AstTds.instruction -> tds -> AstType.instruction *)
|
(* analyse_tds_instruction : AstTds.instruction -> tds -> AstType.instruction *)
|
||||||
(* Paramètre tds : la table des symboles courante *)
|
(* Paramètre tds : la table des symboles courante *)
|
||||||
(* Paramètre i : l'instruction à analyser *)
|
(* Paramètre i : l'instruction à analyser *)
|
||||||
|
@ -89,17 +128,27 @@ let rec analyse_type_instruction opt i =
|
||||||
raise (TypeInattendu(nt, t))
|
raise (TypeInattendu(nt, t))
|
||||||
|
|
||||||
|
|
||||||
| AstTds.Affectation (info, e) ->
|
| AstTds.Affectation (aff, e) ->
|
||||||
begin
|
let (ne, nt) = analyse_type_expression e in
|
||||||
let (ne, nt) = analyse_type_expression e in
|
begin
|
||||||
match (info_ast_to_info info) with
|
match aff with
|
||||||
| InfoVar(_, t, _, _) ->
|
| Dref a ->
|
||||||
if est_compatible t nt then
|
begin
|
||||||
AstType.Affectation(info, ne)
|
match (analyse_type_affectable a) with
|
||||||
else
|
| (na, Pointeur t) -> AstType.Affectation(na, ne)
|
||||||
raise (TypeInattendu(nt, t))
|
| _ -> failwith "jsp koi mettre ici"
|
||||||
| _ -> failwith "wut"
|
end
|
||||||
end
|
| AstTds.Ident info ->
|
||||||
|
begin
|
||||||
|
match (info_ast_to_info info) with
|
||||||
|
| InfoVar(_, t, _, _) ->
|
||||||
|
if est_compatible t nt then
|
||||||
|
AstType.Affectation(AstType.Ident(info), ne)
|
||||||
|
else
|
||||||
|
raise (TypeInattendu(nt, t))
|
||||||
|
| _ -> failwith "wut"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
| AstTds.Affichage e ->
|
| AstTds.Affichage e ->
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -50,11 +50,16 @@ struct
|
||||||
| Equ -> "= "
|
| Equ -> "= "
|
||||||
| Inf -> "< "
|
| Inf -> "< "
|
||||||
|
|
||||||
|
(* Conversion des affectables *)
|
||||||
|
let rec string_of_affectable a =
|
||||||
|
match a with
|
||||||
|
| AstSyntax.Dref(n) -> (string_of_affectable n)
|
||||||
|
| AstSyntax.Ident(n) -> n ^ " "
|
||||||
|
|
||||||
(* Conversion des expressions *)
|
(* Conversion des expressions *)
|
||||||
let rec string_of_expression e =
|
let rec string_of_expression e =
|
||||||
match e with
|
match e with
|
||||||
| AppelFonction (n,le) -> "call "^n^"("^((List.fold_right (fun i tq -> (string_of_expression i)^tq) le ""))^") "
|
| AppelFonction (n,le) -> "call "^n^"("^((List.fold_right (fun i tq -> (string_of_expression i)^tq) le ""))^") "
|
||||||
| Ident n -> n^" "
|
|
||||||
| Booleen b -> if b then "true " else "false "
|
| Booleen b -> if b then "true " else "false "
|
||||||
| Entier i -> (string_of_int i)^" "
|
| Entier i -> (string_of_int i)^" "
|
||||||
| Unaire (op,e1) -> (string_of_unaire op) ^ (string_of_expression e1)^" "
|
| Unaire (op,e1) -> (string_of_unaire op) ^ (string_of_expression e1)^" "
|
||||||
|
|
|
@ -346,5 +346,4 @@ let%test _ =
|
||||||
match info_ast_to_info ia with
|
match info_ast_to_info ia with
|
||||||
| InfoVar ("x", Rat, 10 , "LB") -> true
|
| InfoVar ("x", Rat, 10 , "LB") -> true
|
||||||
| _ -> false
|
| _ -> false
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue