[SCM] Lisaac program java2lisaac branch, master, updated. df678c4154e0c040e63b5b74313d589af2727f14

ontologiae ontologiae at ordinateur-de-ontologiae.local
Tue Aug 25 18:07:04 UTC 2009


The following commit has been merged in the master branch:
commit df678c4154e0c040e63b5b74313d589af2727f14
Author: ontologiae <ontologiae at ordinateur-de-ontologiae.local>
Date:   Tue Aug 25 20:06:27 2009 +0200

    Java2Lisaac caml code, first part

diff --git a/Java2Lisaac.ml/ParserJava.ml b/Java2Lisaac.ml/ParserJava.ml
new file mode 100644
index 0000000..2f4d02a
--- /dev/null
+++ b/Java2Lisaac.ml/ParserJava.ml
@@ -0,0 +1,230 @@
+open Xml
+open ExtLib
+
+(* SLOT    *)
+type slot = Field of field | Constructor of constructor | Method of method_def
+(*|StaticBlock ?;*)
+and
+(*   CONSTRUCTEUR  *)
+constructor = { arguments : formal_arguments ;   native : string;   transient_c : bool;
+volatile_c : bool;   synchronized : bool;   static_c : bool;   final_c : bool;
+visibility_cons : visibility ; id : string;   name : string  ; le_block_de_code
+: block } 
+and
+(*   Arguments d'une méthode, d'un constructeur... *)
+formal_arguments = formal_argument list 
+and (* un argument = est-il final (??), son identifiant : ça peut servir , son nom , son type  *)
+formal_argument = { final_fa : bool;   id : string;   name_fa : string ; type_arg : definition_typ }
+and (*  Mot clé définissant la visibilité *)
+visibility =  Public  |  Private  |  Protected | Error_v
+and  (*  Champ (propriété) défini dans la classe *)
+field = {  name_f : string ; type_field : definition_typ ; transient_f : bool;  volatile_f : bool;   static_f :
+        bool;   final_f : bool;   visibility_f : visibility ; litteral_def_f : litteral_def  } (*TODO : Rajouter une expression*)
+(* TODO : définir valeur littérale *)
+and (*  DEFINITION D'UN TYPE *)
+definition_typ = Def_typ of string * bool * definition_typ list (*Nom ;
+primitive ? ; liste de type génériques*) 
+and  (*  LITTERAUX : entiers, float, chaines, caractères *)
+litteral_def = LiteralChar of char 
+| LiteralNombre of literal_number 
+| LiteralChain of string 
+| LiteralBool of bool
+| LiteralCaractere of char
+| LiteralNull
+and (*  Nombre litéraux *)
+literal_number = {  value : string ;   kind : typePrimitif; base : int;}
+and  (* TYPES PRIMITIFS JAVOUILLES  *)
+typePrimitif =  Integer  |  Long  |  Float  |  Double | Byte | Short | Boolean  
+and (* Définition d'une méthode dans la classe  *)
+method_def = { native : string;  transient_m : string;  volatile_m : string; synchronized : string;  static_m : string;  final : string;
+abstract : string;  visibility_p : visibility  ;id : string;  name : string }
+and (* Définition d'un block en java  *)
+block = Block of (statement list)
+and (*  Un Statement = Soit une expression, un if then else, un while, un do
+        while, un try catch, switch, synchronized ??, Return, Throw, break,
+        continue *)
+statement = Local_variable of (local_variable list)
+| Expression of expression
+| IfThenElse of expression * block * block
+| While of expression * block
+| DoWhile of expression * block (* Question : doit-on typer les expression et est-il possible et intéressant de le faire au niveau du xml ? *)
+| TryCatchFinaly of block * local_variable * block
+| Switch of expression * ((int * block) list) * block (* Expression de test (entière), la liste des cases, et le block de défaut *)
+| Synchronized of expression * block (* C'est quoi ça ??*)
+| Return of expression
+| Throw of expression
+| Break
+| Continue 
+| Rien (* Block vide  *)
+| For of expression * expression * expression (* pose problème pour le 1er et le
+dernier  *)
+| ForEach of definition_typ * local_variable * expression
+(* Manque le for et For Each !!  *)
+and
+(* VARIABLE LOCALES    *)
+local_variable = { final_l : bool;   continued : string (*c quoi ??*);  id : definition_typ (*c quoi ?? Le type ??*);  name : string ; definition : litteral_def } 
+
+
+
+(*  EXPRESSIONS *)
+and expression =
+        Plus of expression * expression
+|       Moins of expression * expression
+|       Mult of expression * expression
+|       Div of expression * expression
+|       Modulo of expression * expression
+|       Puissance of expression * expression
+
+|       EtBin of expression * expression
+|       OuBin of expression * expression
+|       EtLogic of expression * expression
+|       OuLogic of expression * expression
+
+|       DecG of expression * expression
+|       DecD of expression * expression
+|       DecDZ of expression * expression
+|       DecGZ of expression * expression
+
+|       Affect of expression * expression
+
+|       PlusEgal of expression * expression
+|       MoinsEgal of expression * expression
+|       MultEgal of expression * expression
+|       DivEgal of expression * expression
+|       ModEgal of expression * expression
+|       PuissEgal of expression * expression
+|       EtLogicEgal of expression * expression
+|       OuLogicEgal of expression * expression
+|       DecGEgal of expression * expression
+|       DecDEgal of expression * expression
+|       DecDZEgal of expression * expression
+|       InfEgal of expression * expression
+|       SupEgal of expression * expression
+|       InfStrict of expression * expression
+|       SupStrict of expression * expression
+
+|       EgalLogic of expression * expression
+|       Different of expression * expression
+|       PlusPlusPre of expression
+|       MoinMoinsPre of expression
+|       PlusPlusPost of expression 
+|       MoinMoinsPost of expression 
+|       Minus of expression
+|       Not of expression
+
+|       EntreParenth of expression
+|       CastType of definition_typ * expression
+|       NewClassName of string list
+|       Null
+|       Super
+|       This
+|       False
+|       True
+;;
+
+
+let x = Xml.parse_file "output2.xml";;
+
+
+type xmls = Elem of (string * (string * string) list * xmls list);;
+let rec to_xmls = function
+        | Element ( a , b , c ) -> Elem ( a , b , List.map to_xmls c )
+        | PCData _ -> Elem ( "", [], []);;
+
+
+let typ = Def_typ ("UnType" , false , [] );;
+let champ = { name_f="jk" ; type_field=typ ; transient_f=false ; volatile_f= false ; static_f=false ; final_f=false ; visibility_f=Private ; litteral_def_f=LiteralBool(true) };; 
+
+let ch = [("name", "UNE_VARIABLE");("visibility", "Private");("final","true");("static","true")];;
+
+let lit_int= Elem ("literal-number", [("kind","integer");("value","1")],[]) ;;
+let lit_str= Elem ("literal-string", [("kind","string");("value","truc")],[]) ;;
+let lit_ch=  Elem ("literal-string", [("kind","string");("value","truc")],[]) ;;
+
+let var = Elem( "field" , [("name","ANGLE_315");("visibility","public");("final","true");("static","true")], [
+                Elem( "type", [("primitive","true");("name","int")], []);
+                Elem( "literal-number",[("kind","integer");("value","1680")], [])]);; 
+
+let visibility_str_to_type = function
+        | "public" -> Public
+        | "private" -> Private
+        | "protected" -> Protected
+        | _ -> Public;; 
+
+let is_true = function
+        | "true" -> true;
+        | "false" -> false;
+        | _ -> false;; 
+
+
+let rec key = function
+        | vsearched, (k,v)::q -> if k=vsearched then v else key (vsearched,q) 
+        | _ , [] -> "";; 
+
+
+let rec concat_couple = function 
+        | (a,b)::q -> a^"="^b^";"^(concat_couple q)
+        | [] -> "" ;;
+
+
+let erreur = function balis , balis_autorisee ,  lstNoeud -> "ERREUR DE
+GRAMMAIRE : Balise attendue ="^balis^" ; Balise autorisées : "^balis_autorisee^"
+; Attributs du noeud courants ; "^(concat_couple lstNoeud);;
+
+let children = function Elem(  a ,b , f ) -> f;;
+
+
+let rec recup_info_literal = function
+        | Elem("literal-number", lst, children) -> let kind = key ("kind",lst) in
+        (match kind with "integer" -> LiteralNombre ({ value= (key("value", lst)) ;   kind=Integer; base=2} ) (* to int ?? *)
+        | "float" -> LiteralNombre { value = (key ("value", lst)) ; kind = Float
+        ; base = 2 }
+        | "short" -> LiteralNombre { value = (key ("value", lst)) ; kind = Short
+        ; base = 2 }
+        | "long" -> LiteralNombre { value = (key ("value", lst)) ; kind = Long
+        ; base = 2 }
+        | "double" -> LiteralNombre { value = (key ("value", lst)) ; kind = Double
+        ; base = 2 }
+        | "byte" -> LiteralNombre { value = (key ("value", lst)) ; kind = Byte
+        ; base = 2 } )
+        | Elem("literal-string", lst, children) -> let kind = key ("kind",lst) in
+        (match kind with "string" -> LiteralChain (key ("value", lst)) (* TODO : gérer les &quot; qui restent*)
+        | _ -> LiteralNull)
+        |  Elem("literal-char", lst, children) -> let kind = key ("kind",lst) in
+        (match kind with "char" -> LiteralChar (String.get (key ("value", lst)) 1)
+        | _ -> LiteralNull)
+        |  Elem("literal-bool", lst, children) -> let kind = key ("kind",lst) in
+        (match kind with "char" ->  LiteralBool  (is_true (key ("value", lst)))
+        | _ -> LiteralNull )
+        | Elem ( b , t , chil) -> print_string (erreur (b, "literal", t)); LiteralNull;; 
+
+
+
+let rec prend_balise = function
+        | Elem(n,i,f)::q, recherche -> if String.find (n, recherche) then Elem(n,i,f) else
+                prend_balise (q, recherche)
+        | [], recherche ->   Elem("FAUX",[],[]) ;; 
+
+let rec recup_info_type_field = function
+        | Elem("type", infos, fils) ->  Def_typ ( key("name",infos) ,  is_true (key("primitive",infos)) , [] ) (*On verra après pour savoir comment gérer les types génériques*)
+        |  Elem ( a , infos , fils) -> print_string "ERREUR de grammaire : balise type attendu...";  Def_typ ( "", false , [] );; 
+
+let rec match_field = function
+        | Elem ( "field", infos, fils) -> { name_f = key("name",infos) ;
+        type_field = recup_info_type_field (prend_balise (fils,"type")) ; 
+        transient_f =is_true (key("transient",infos)) ; 
+        volatile_f = is_true (key("volatile",infos)) ;
+        static_f = is_true (key("static",infos)) ;
+        final_f = is_true (key("final",infos)) ; 
+        visibility_f = visibility_str_to_type (key("visibility",infos)) ;
+        litteral_def_f = recup_info_literal (prend_balise (fils, "literal-number"))} (* FAUX *)
+
+        | Elem ( a , infos , fils) -> print_string "ERREUR de grammaire : balise field attendu...";
+        { name_f = "" ; type_field = Def_typ ( "", false , [] ) ; transient_f = false ;
+        volatile_f = false ;
+        static_f = false ;
+        final_f = false ; 
+        visibility_f = Private ;
+        litteral_def_f = LiteralNull};;   
+
+

-- 
Lisaac program java2lisaac



More information about the Lisaac-commits mailing list