1 (* interface between isac math engine and java:
2 java -> sml: strings on stdin
3 sml -> java: xml on stdout
5 WN071004 The xml still reflects the insecurity during the first
6 implementation phase, how the communication via stdin/out could
7 correctly relate multiple sml-calculations and java-calculations.
9 Since this insecurity turned out unjustified, the xml can be
10 simplified in several ways:
11 # omit the CALCID; the relation is done by
12 "@@@@@begin@@@@@\n "^string_of_int uI
13 # omit the distinctions APPENDFORMULA, REPLACEFORMULA, ...
14 WN071004 these 2 simplifications are begun with CALCMESSAGE
22 (** add and delete users -----------------------------------------------
23 FIXXME.8.03 addUser: clear code, because only CalcTrees distinguished**)
24 fun adduserOK2xml (cI:calcID) (uI:iterID) =
25 writeln ("@@@@@begin@@@@@\n "^string_of_int uI^" \n" ^
27 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
28 " <USERID> "^string_of_int uI^" </USERID>\n" ^
31 fun adduserOK2xml (calcid : calcID) (userid : iterID) =
32 XML.Elem (("ADDUSER", []),
33 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
34 XML.Elem (("USERID", []), [XML.Text (string_of_int userid)])])
35 fun deluserOK2xml (cI:calcID) (uI:iterID) =
36 writeln ("@@@@@begin@@@@@\n "^string_of_int uI^" \n" ^
38 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
39 " <USERID> "^string_of_int uI^" </USERID>\n" ^
42 (*---------------------------------------------------------------------*)
44 fun calctreeOK2xml (*uI:iterID*) (cI:calcID) =
45 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
47 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
50 fun calctreeOK2xml (calcid : calcID) =
51 XML.Elem (("CALCTREE", []),
52 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)])])
53 fun deconstructcalctreeOK2xml (*uI:userID*) (cI:calcID) =
54 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
56 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
60 fun iteratorOK2xml (cI:calcID) (p:pos')=
61 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
63 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
64 pos'2xml i ("POSITION", p) ^
67 fun iteratorERROR2xml (cI:calcID) =
68 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
70 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
71 " <ERROR> pos does not exist </ERROR>\n" ^
74 fun iteratorOK2xml (calcid : calcID) (p : pos')=
75 XML.Elem (("CALCITERATOR", []),
76 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
77 xml_of_pos "POSITION" p])
78 fun iteratorERROR2xml (calcid : calcID) =
79 XML.Elem (("CALCITERATOR", []),
80 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
81 XML.Elem (("ERROR", []), [XML.Text " pos does not exist "])])
83 fun sysERROR2xml (cI:calcID) "" =
84 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
86 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
87 " <ERROR> in kernel </ERROR>\n" ^
90 | sysERROR2xml (cI:calcID) str =
91 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
93 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
94 " <ERROR> "^str^" </ERROR>\n" ^
97 fun sysERROR2xmlTODO (calcid : calcID) str =
98 XML.Elem (("SYSERROR", []),
99 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
100 XML.Elem (("ERROR", []), [XML.Text (if str = "" then " ERROR in kernel " else str)])])
102 fun refformulaOK2xml (cI:calcID) p (Form t) =
103 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
105 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
107 pos'2xml (2*i) ("POSITION", p) ^
109 term2xml (2*i) t ^ "\n" ^
111 " </CALCFORMULA>\n" ^
114 | refformulaOK2xml (cI:calcID) p (ModSpec modspec) =
115 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
117 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
118 pos'calchead2xml i (p, modspec)^
121 fun refformulaOK2xml (calcid : calcID) p (Form t) =
122 XML.Elem (("REFFORMULA", []),
123 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
124 XML.Elem (("CALCFORMULA", []), [
125 xml_of_pos "POSITION" p,
126 XML.Elem (("FORMULA", []), [xml_of_term t])])])
127 | refformulaOK2xml (calcid : calcID) p (ModSpec modspec) =
128 XML.Elem (("REFFORMULA", []),
129 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
130 XML.Elem (("ERROR", []), [XML.Text " pos does not exist "])])
132 fun refformulaERROR2xml (cI:calcID) = (*FIXME.WN.29.8.03 unused*)
133 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
135 " <ERROR> object is not a formula </ERROR>\n" ^
139 (* val (cI, tac) = (cI, ta);
141 fun gettacticOK2xml (cI:calcID) tac =
142 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
144 " <CALCID> "^string_of_int cI^" </CALCID>\n"^
148 fun gettacticERROR2xml (cI:calcID) str =
149 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
151 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
152 " <ERROR> "^str^" </ERROR>\n" ^
156 fun applicabletacticsOK cI tacs =
157 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
158 "<APPLICABLETACTICS>\n" ^
159 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
163 "</APPLICABLETACTICS>\n" ^
166 fun getasmsOK2xml (cI:calcID) terms =
167 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
168 "<GETASSUMPTIONS>\n" ^
169 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
171 formulae2xml (i+i) terms ^
173 "</GETASSUMPTIONS>\n" ^
175 (* getasmsOK2xml 333 [str2term "1+1=2", str2term "1+1+1=3"];
178 (*WN0502 @see ME/ctree: type asms: illdesigned, thus not used*)
179 fun getaccuasmsOK2xml cI asms =
180 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
181 "<GETACCUMULATEDASMS>\n" ^
182 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
184 formulae2xml (i+i) asms^
186 "</GETACCUMULATEDASMS>\n" ^
188 (* getaccuasmsOK2xml 333 [(([1],Res), str2term "1+1=2"),
189 (([2],Res), str2term "1+1+1=3")];
190 getaccuasmsOK2xml 333 [str2term "1+1=2", str2term "1+1+1=3"];
193 fun getintervalOK (cI:calcID) fs =
194 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
195 "<GETELEMENTSFROMTO>\n" ^
196 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
198 posterms2xml (2*i) fs^
200 "</GETELEMENTSFROMTO>\n" ^
202 fun getintervalOK (calcid : calcID) fs =
203 XML.Elem (("GETELEMENTSFROMTO", []),
204 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
205 XML.Elem (("FORMHEADS", []), map xml_of_posterm fs)])
207 fun matchpbl2xml (cI:calcID) (model_ok, pI, hdl, pbl, pre) =
208 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
210 " <GUH> " ^ pblID2guh pI ^ " </GUH>\n" ^
211 " <STATUS> " ^ (if model_ok
213 else "incorrect") ^ " </STATUS>\n" ^
215 term2xml i hdl ^ "\n" ^
217 model2xml i pbl pre ^
221 fun matchmet2xml (cI:calcID) (model_ok, pI, scr, pbl, pre) =
222 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
224 " <GUH> " ^ metID2guh pI ^ " </GUH>\n" ^
225 " <STATUS> " ^ (if model_ok
227 else "incorrect") ^ " </STATUS>\n" ^
229 model2xml i pbl pre ^
234 fun tryrefineOK2xml (cI:calcID) (ModSpec modspec) =
235 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
237 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
238 modspec2xml i modspec ^
242 fun appendformulaOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
243 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
244 "<APPENDFORMULA>\n" ^
245 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
247 pos'2xml (2*i) ("UNCHANGED", old) ^
248 pos'2xml (2*i) ("DELETED", del) ^
249 pos'2xml (2*i) ("GENERATED", new) ^
250 " </CALCCHANGED>\n" ^
251 "</APPENDFORMULA>\n" ^
253 (* appendformulaOK2xml 1 ([2],Frm) ([3],Pbl) ([4],Res);
255 fun appendformulaERROR2xml (cI:calcID) msg =
256 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
257 "<CALCMESSAGE> "^ msg ^" </CALCMESSAGE>\n" ^
260 fun replaceformulaOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
261 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
262 "<REPLACEFORMULA>\n" ^
263 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
265 pos'2xml (2*i) ("UNCHANGED", old) ^
266 pos'2xml (2*i) ("DELETED", del) ^
267 pos'2xml (2*i) ("GENERATED", new) ^
268 " </CALCCHANGED>\n" ^
269 "</REPLACEFORMULA>\n" ^
271 fun replaceformulaERROR2xml (cI:calcID) msg =
272 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
273 "<CALCMESSAGE> "^ msg ^" </CALCMESSAGE>\n" ^
276 fun message2xml (cI:calcID) e =
277 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
279 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
280 " <STRING> "^e^" </STRING>\n" ^
284 fun setnexttactic2xml (*uI:iterID*) (cI:calcID) e =
285 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
286 "<SETNEXTTACTIC>\n" ^
287 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
288 " <MESSAGE> "^e^" </MESSAGE>\n" ^
289 "</SETNEXTTACTIC>\n" ^
292 fun fetchproposedtacticOK2xml (cI:calcID) tac _ =
293 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
295 " <CALCID> "^string_of_int cI^" </CALCID>\n"^
300 fun fetchproposedtacticOK2xml (cI:calcID) tac (errpatIDs: errpatID list) =
301 writeln ("@@@@@begin@@@@@\n " ^ string_of_int cI ^ " \n" ^
303 " <CALCID> " ^ string_of_int cI ^ " </CALCID>\n" ^
304 " <TACTICERRORPATTERNS>\n" ^
305 id2xml (2*i) errpatIDs ^
307 " </TACTICERRORPATTERNS>\n" ^
311 fun fetchproposedtacticERROR2xml (*uI:userID*) (cI:calcID) e =
312 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
314 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
315 " <ERROR> "^ e ^" </ERROR>\n" ^
319 (*. UNCHANGED: the pos' of the active formula autocalculate has been applied at
320 DELETED: last pos' of the succesional sequence of formulae prob. deleted
321 GENERATED: the pos' of the new active formula
323 fun autocalculateOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
324 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
326 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
328 pos'2xml (2*i) ("UNCHANGED", old) ^
329 pos'2xml (2*i) ("DELETED", del) ^
330 pos'2xml (2*i) ("GENERATED", new) ^
331 " </CALCCHANGED>\n" ^
334 (* autocalculate2xml 11 22 (Rewrite ("rmult_commute","?m *?n =?n *?m"));
336 fun autocalculateERROR2xml (cI:calcID) e =
337 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
338 "<CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
341 fun interStepsOK (cI:calcID) (old:pos') (del:pos') (new:pos') =
342 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
344 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
346 pos'2xml (2*i) ("UNCHANGED", old) ^
347 pos'2xml (2*i) ("DELETED", del) ^
348 pos'2xml (2*i) ("GENERATED", new) ^
349 " </CALCCHANGED>\n" ^
352 fun interStepsERROR (cI:calcID) e =
353 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
354 " <CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
357 fun calcMessage2xml (cI:calcID) e =
358 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
359 " <CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
362 fun modifycalcheadOK2xml (cI:calcID) (chd as (complete,p_,_,_,_,_):ocalhd) =
363 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
364 "<MODIFYCALCHEAD>\n" ^
365 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
366 " <STATUS> "^(if complete then "complete"
367 else "incomplete")^ "</STATUS>\n"^
369 "</MODIFYCALCHEAD>\n" ^
372 (* val (cI, contthy) = (cI, (context_thy (pt,pos) tac));
374 fun contextthyOK2xml cI contthy =
375 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
377 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
378 contthy2xml i contthy ^
382 fun contextthyNO2xml guh =
383 writeln (datatypes.contextthyNO2xml 0 guh);
386 fun findFillpatterns2xml (cI:calcID) pattIDs =
387 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
388 "<FINDFILLPATTERNS>\n" ^
389 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
391 "</FINDFILLPATTERNS>\n" ^