[SCM] applications.git branch, master, updated. 4f44687c6448835602fccbfad27fc046538fe11b
ontologiae
ontologiae at ordinateur-de-ontologiae-3.local
Tue Apr 6 09:30:44 UTC 2010
The following commit has been merged in the master branch:
commit 44c8a4fb1765f8d0a9083b762e4c069e860cf535
Author: ontologiae <ontologiae at ordinateur-de-ontologiae-3.local>
Date: Thu Apr 1 14:28:34 2010 +0200
Java2lisaac update
diff --git a/java2lisaac/Java2Lisaac.ml/ParserJava.ml b/java2lisaac/Java2Lisaac.ml/ParserJava.ml
index 7475ddb..55a569b 100644
--- a/java2lisaac/Java2Lisaac.ml/ParserJava.ml
+++ b/java2lisaac/Java2Lisaac.ml/ParserJava.ml
@@ -1,14 +1,17 @@
#use "topfind";;
#require "xml-light";;
#require "extlib";;
-(*open Xml*)
-open ExtLib
+open Xml
+open ExtLib
+(*==========================================================================================*)
+(*================================ GRAMMAR ==========================================*)
+(*==========================================================================================*)
(* SLOT *)
type slot = Field of field | Constructor of constructor | Method of method_def
-(*|StaticBlock ?;*)
+(*StaticBlock ?*)
and
(* CONSTRUCTEUR *)
constructor = { arguments : formal_arguments ; native : string; transient_c : bool;
@@ -54,7 +57,7 @@ statement = Local_variable of (local_variable list)
| 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 *)
+| Switch of expression * ((expression * 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
@@ -93,6 +96,7 @@ and expression =
| Affect of expression * expression
+(*TODO : généraliser avec l'opérateur*)
| PlusEgal of expression * expression
| MoinsEgal of expression * expression
| MultEgal of expression * expression
@@ -131,12 +135,14 @@ and expression =
| LiteralExpre of litteral_def
| Message of string * expression * expression list (*Appel de méthode :
Nom, receveur, arguments *)
-| VarRef of definition_typ
+| VarRef of string* definition_typ
| ThisCall of expression
;;
-
+(*==========================================================================================*)
+(*================================ TYPE DECLARATION =================================*)
+(*==========================================================================================*)
type xmls = Elem of (string * (string * string) list * xmls list);;
@@ -146,11 +152,14 @@ let hash_variables = Hashtbl.create 123456;;
(* UTILITAIRES *)
+(*==========================================================================================*)
+(*================================ TOOL FUNCTION =================================*)
+(*==========================================================================================*)
let rec to_xmls = function
- | Xml.Element ( a , b , c ) -> Elem ( a , b , List.map to_xmls c )
- | Xml.PCData _ -> Elem ( "", [], []);;
+ | Element ( a , b , c ) -> Elem ( a , b , List.map to_xmls c )
+ | PCData _ -> Elem ( "", [], []);;
let visibility_str_to_type = function
| "public" -> Public
@@ -201,7 +210,9 @@ let get_typ_info = function cpl -> Hashtbl.find hash_variables cpl;;
(* /UTILITAIRES *)
-
+(*==========================================================================================*)
+(*================================ SOME VARIABLES FOR TESTS ======================*)
+(*==========================================================================================*)
(* DEF VARIABLES POUR TESTS *)
let x = Xml.parse_file "2expre.xml";;
@@ -222,8 +233,9 @@ let var = Elem( "field" , [("name","ANGLE_315");("visibility","public");("final"
Elem( "literal-number",[("kind","integer");("value","1680")], [])]);;
-
-(*==================================================== REMPLISSAGE DE L'ARBRE ====================================================*)
+(*==========================================================================================*)
+(*================================ ABSTRACT SYNTAX BUILDING =======================*)
+(*==========================================================================================*)
let rec recup_info_literal = function
| Elem("literal-number", lst, children) -> let kind = key ("kind",lst) in
@@ -283,6 +295,19 @@ let rec match_field = function
visibility_f = Private ;
litteral_def_f = LiteralNull};;
+(*Comment détecter les expressions ? Il peut y en avoir plein*)
+
+
+ (* PAS FINI !!!!!!!!! *)
+(*let rec match_statement = function
+ | Elem ("loop",["kind","for"], init :: test :: update :: block ) -> a
+ | Elem ("local-variable", ["name",nomvar] , typ :: literal ) -> a
+ | Elem ("block" , [] , expressions ) -> List.map match_statement
+ expressions
+ | Elem( "switch" , [] , var :: lstSwitch ) -> Switch ( match_expression var,
+
+
+*)
(*TODO : Gestion de l'opérateur dans assignment-expr *)
let rec match_expression = function
@@ -301,12 +326,10 @@ let rec match_expression = function
Message (method_name, match_expression
(List.hd (children target)), List.map match_expression (children
arguments) )
- | Elem("send", [("message", method_name)], arguments :: []) -> (* Pas
- de receveur *)
- Message (method_name,This, List.map match_expression (children
+ | Elem("send", [("message", method_name)], arguments :: []) ->
+ Message (method_name, This, List.map match_expression (children
arguments) )
- | Elem("var-ref", infos, fils) -> VarRef (get_typ_info ("class",(key
- ("name",infos))))
+ | Elem("var-ref", infos, fils) -> VarRef (key ("name",infos),get_typ_info ("class",(key ("name",infos))))
| Elem(a , infos, []) when is_substring (a,"literal") -> LiteralExpre ( recup_info_literal (Elem(a,infos,[])) )
| Elem("this-call", [], fils :: []) -> ThisCall (match_expression fils)
| Elem( a, i , f ) -> print_string (erreur ("match_expression",a, "new,
@@ -352,7 +375,9 @@ and match_expre_binaire = function
| Elem( a, i , f ) -> print_string (erreur ("match_expre_binaire", a, "binary-expr", i)); Null;;
-
+(*==========================================================================================*)
+(*================================ BACKEND =======================================*)
+(*==========================================================================================*)
let rec bin_expre_to_lisaac = function
@@ -379,12 +404,17 @@ let rec bin_expre_to_lisaac = function
| InfEgal ( l , r) -> bin_expre_to_lisaac l ^" <= "^bin_expre_to_lisaac r
| InfStrict ( l , r) -> bin_expre_to_lisaac l ^" < "^bin_expre_to_lisaac r
| EntreParenth ( l ) -> "( "^ bin_expre_to_lisaac l ^" ) "
- | VarRef a -> (match a with Def_typ (n, m , c) -> n)
+ | VarRef (nom,info_typ) -> nom (*(match info_typ with Def_typ (n, m , c) -> n) *)
| Message (nom, receveur, arguments) -> bin_expre_to_lisaac receveur
^"."^ nom ^"("^ (String.concat " " (List.map bin_expre_to_lisaac
arguments)) ^")"
- | This -> "this"
- | LiteralExpre (LiteralNombre a) -> a.value ;;
+ (* | NewClassName ( def_type, lst_def_typ , expre) -> *)
+ | LiteralExpre (LiteralNombre a) -> a.value
+ | This -> "Self";;
+
+let rec def_typ_to_lisaac = function
+ | Def_typ ( nom, is_primit , typs_generiq ) -> nom^"("^(String.concat "," (List.map def_typ_to_lisaac typs_generiq))
+ | Def_typ ( nom, is_primit , [] ) -> nom;;
(*let test_match_field = match_field var;;
@@ -400,17 +430,23 @@ let test_hash = ajoute_info ("class","test", typ);; *)
#trace ajoute_info;;
#trace bin_expre_to_lisaac;;
*)
-
+(*==========================================================================================*)
+(*================================ TESTS =================================*)
+(*==========================================================================================*)
ajoute_info ("class","ch", Def_typ ("ch" , false , [] ));;
ajoute_info ("class","i", Def_typ ("i" , false , [] ));;
ajoute_info ("class","str", Def_typ ("str" , false , [] ));;
-ajoute_info ("class","FIXP_SHIFT", Def_typ ("i" , true , [] ));;
-ajoute_info ("class","view_ang_y", Def_typ ("i" , true , [] ));;
-ajoute_info ("class","speed", Def_typ ("i" , true , [] ));;
-ajoute_info ("class","view_pos_x", Def_typ ("i" , true , [] ));;
+ajoute_info ("class","FIXP_SHIFT", Def_typ ("FIXP" , false , [] ));;
+ajoute_info ("class","speed", Def_typ ("speed" , false , [] ));;
+ajoute_info ("class","view_pos_x", Def_typ ("viewx" , false , [] ));;
+ajoute_info ("class","COS_LOOK", Def_typ ("coslook" , false , [] ));;
+ajoute_info ("class","view_ang_y", Def_typ ("viewy" , false , [] ));;
+
+
Hashtbl.find_all hash_variables ("class","ch");;
let expre = match_expression bin_expr;;
-bin_expre_to_lisaac expre;;
+bin_expre_to_lisaac expre;;
+
--
applications.git
More information about the Lisaac-commits
mailing list