author | wenzelm |
Wed, 13 Jul 2005 16:07:25 +0200 | |
changeset 16804 | 3c339e1c069b |
parent 16548 | aa36ae6b955e |
child 16840 | 3d5aad11bc24 |
permissions | -rw-r--r-- |
15789
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15688
diff
changeset
|
1 |
(* ID: $Id$ |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15688
diff
changeset
|
2 |
Author: Claire Quigley |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15688
diff
changeset
|
3 |
Copyright 2004 University of Cambridge |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15688
diff
changeset
|
4 |
*) |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15688
diff
changeset
|
5 |
|
15642 | 6 |
(*use "Translate_Proof";*) |
7 |
(* Parsing functions *) |
|
8 |
||
9 |
(* Auxiliary functions *) |
|
10 |
||
15684
5ec4d21889d6
Reconstruction code, now packaged to avoid name clashes
paulson
parents:
15642
diff
changeset
|
11 |
structure Recon_Parse = |
5ec4d21889d6
Reconstruction code, now packaged to avoid name clashes
paulson
parents:
15642
diff
changeset
|
12 |
struct |
5ec4d21889d6
Reconstruction code, now packaged to avoid name clashes
paulson
parents:
15642
diff
changeset
|
13 |
|
16804 | 14 |
open ReconPrelim ReconTranslateProof; |
15642 | 15 |
|
16 |
exception NOPARSE_WORD |
|
17 |
exception NOPARSE_NUM |
|
18 |
fun to_upper s = String.translate (Char.toString o Char.toUpper) s; |
|
19 |
||
20 |
fun string2int s = |
|
16804 | 21 |
(case Int.fromString s of SOME i => i |
22 |
| NONE => raise ASSERTION "string -> int failed"); |
|
23 |
||
15642 | 24 |
|
25 |
(* Parser combinators *) |
|
26 |
||
27 |
exception Noparse; |
|
28 |
exception SPASSError of string; |
|
16478 | 29 |
exception VampError of string; |
30 |
||
15642 | 31 |
|
15688 | 32 |
fun (parser1 ++ parser2) input = |
15642 | 33 |
let |
34 |
val (result1, rest1) = parser1 input |
|
35 |
val (result2, rest2) = parser2 rest1 |
|
36 |
in |
|
37 |
((result1, result2), rest2) |
|
38 |
end; |
|
39 |
||
40 |
fun many parser input = |
|
41 |
let (* Tree * token list*) |
|
42 |
val (result, next) = parser input |
|
43 |
val (results, rest) = many parser next |
|
44 |
in |
|
45 |
((result::results), rest) |
|
46 |
end |
|
47 |
handle Noparse => ([], input) |
|
48 |
| NOPARSE_WORD => ([], input) |
|
49 |
| NOPARSE_NUM => ([], input); |
|
50 |
||
51 |
||
52 |
||
15688 | 53 |
fun (parser >> treatment) input = |
15642 | 54 |
let |
55 |
val (result, rest) = parser input |
|
56 |
in |
|
57 |
(treatment result, rest) |
|
58 |
end; |
|
59 |
||
15688 | 60 |
fun (parser1 || parser2) input = parser1 input |
15642 | 61 |
handle Noparse => parser2 input; |
62 |
||
63 |
infixr 8 ++; infixr 7 >>; infixr 6 ||; |
|
64 |
||
65 |
fun some p [] = raise Noparse |
|
66 |
| some p (h::t) = if p h then (h, t) else raise Noparse; |
|
67 |
||
68 |
fun a tok = some (fn item => item = tok); |
|
69 |
||
70 |
fun finished input = if input = [] then (0, input) else raise Noparse; |
|
71 |
||
72 |
||
73 |
||
74 |
||
75 |
||
76 |
(* Parsing the output from gandalf *) |
|
77 |
datatype token = Word of string |
|
78 |
| Number of int |
|
79 |
| Other of string |
|
80 |
||
81 |
||
82 |
exception NOCUT |
|
83 |
fun is_prefix [] l = true |
|
84 |
| is_prefix (h::t) [] = false |
|
85 |
| is_prefix (h::t) (h'::t') = (h = h') andalso is_prefix t t' |
|
86 |
fun remove_prefix [] l = l |
|
87 |
| remove_prefix (h::t) [] = raise (ASSERTION "can't remove prefix") |
|
88 |
| remove_prefix (h::t) (h'::t') = remove_prefix t t' |
|
89 |
fun ccut t [] = raise NOCUT |
|
90 |
| ccut t s = |
|
91 |
if is_prefix t s then ([], remove_prefix t s) else |
|
92 |
let val (a, b) = ccut t (tl s) in ((hd s)::a, b) end |
|
93 |
fun cut t s = |
|
94 |
let |
|
95 |
val t' = explode t |
|
96 |
val s' = explode s |
|
97 |
val (a, b) = ccut t' s' |
|
98 |
in |
|
99 |
(implode a, implode b) |
|
100 |
end |
|
101 |
||
102 |
fun cut_exists t s |
|
103 |
= let val (a, b) = cut t s in true end handle NOCUT => false |
|
104 |
||
105 |
fun cut_before t s = let val (a, b) = cut t s in (a, t ^ b) end |
|
106 |
fun cut_after t s = let val (a, b) = cut t s in (a ^ t, b) end |
|
107 |
||
108 |
||
15684
5ec4d21889d6
Reconstruction code, now packaged to avoid name clashes
paulson
parents:
15642
diff
changeset
|
109 |
fun kill_lines 0 = Library.I |
15642 | 110 |
| kill_lines n = kill_lines (n - 1) o snd o cut_after "\n"; |
111 |
||
112 |
(*fun extract_proof s |
|
113 |
= if cut_exists "EMPTY CLAUSE DERIVED" s then |
|
114 |
(kill_lines 6 |
|
115 |
o snd o cut_after "EMPTY CLAUSE DERIVED" |
|
116 |
o fst o cut_after "contradiction.\n") s |
|
117 |
else |
|
118 |
raise (GandalfError "Couldn't find a proof.") |
|
119 |
*) |
|
120 |
||
121 |
val proofstring = |
|
122 |
"0:00:00.00 for the reduction.\ |
|
123 |
\\ |
|
124 |
\Here is a proof with depth 3, length 7 :\ |
|
125 |
\1[0:Inp] || -> P(xa)*.\ |
|
126 |
\2[0:Inp] || -> Q(xb)*.\ |
|
127 |
\3[0:Inp] || R(U)* -> .\ |
|
128 |
\4[0:Inp] || Q(U) P(V) -> R(x(V,U))*.\ |
|
129 |
\9[0:Res:4.2,3.0] || Q(U)*+ P(V)* -> .\ |
|
130 |
\11[0:Res:2.0,9.0] || P(U)* -> .\ |
|
131 |
\12[0:Res:1.0,11.0] || -> .\ |
|
132 |
\Formulae used in the proof :\ |
|
133 |
\\ |
|
134 |
\--------------------------SPASS-STOP------------------------------" |
|
135 |
||
16418 | 136 |
fun extract_proof s |
137 |
= if cut_exists "Here is a proof with" s then |
|
138 |
(kill_lines 0 |
|
139 |
o snd o cut_after ":" |
|
140 |
o snd o cut_after "Here is a proof with" |
|
141 |
o fst o cut_after " || -> .") s |
|
142 |
else if cut_exists "%================== Proof: ======================" s then |
|
143 |
(kill_lines 0 |
|
144 |
o snd o cut_after "%================== Proof: ======================" |
|
145 |
o fst o cut_before "============== End of proof. ==================") s |
|
146 |
else |
|
147 |
raise SPASSError "Couldn't find a proof." |
|
15642 | 148 |
|
16418 | 149 |
(*fun extract_proof s |
15642 | 150 |
= if cut_exists "Here is a proof with" s then |
151 |
(kill_lines 0 |
|
152 |
o snd o cut_after ":" |
|
153 |
o snd o cut_after "Here is a proof with" |
|
154 |
o fst o cut_after " || -> .") s |
|
155 |
else |
|
156 |
raise SPASSError "Couldn't find a proof." |
|
16418 | 157 |
*) |
15642 | 158 |
|
159 |
||
16478 | 160 |
|
161 |
||
162 |
||
15642 | 163 |
fun several p = many (some p) |
15684
5ec4d21889d6
Reconstruction code, now packaged to avoid name clashes
paulson
parents:
15642
diff
changeset
|
164 |
fun collect (h, t) = h ^ (Utils.itlist (fn s1 => fn s2 => s1 ^ s2) t "") |
15642 | 165 |
|
166 |
fun lower_letter s = ("a" <= s) andalso (s <= "z") |
|
167 |
fun upper_letter s = ("A" <= s) andalso (s <= "Z") |
|
168 |
fun digit s = ("0" <= s) andalso (s <= "9") |
|
169 |
fun letter s = lower_letter s orelse upper_letter s |
|
170 |
fun alpha s = letter s orelse (s = "_") |
|
171 |
fun alphanum s = alpha s orelse digit s |
|
172 |
fun space s = (s = " ") orelse (s = "\n") orelse (s = "\t") |
|
173 |
(* FIX this is stopping it picking up numbers *) |
|
174 |
val word = (some alpha ++ several alphanum) >> (Word o collect) |
|
175 |
val number = |
|
176 |
(some digit ++ several digit) >> (Number o string2int o collect) |
|
177 |
val other = some (K true) >> Other |
|
178 |
||
179 |
val token = (word || number || other) ++ several space >> fst |
|
180 |
val tokens = (several space ++ many token) >> snd |
|
181 |
val alltokens = (tokens ++ finished) >> fst |
|
182 |
||
183 |
(* val lex = fst ( alltokens ( (map str) explode))*) |
|
184 |
fun lex s = alltokens (explode s) |
|
185 |
||
16478 | 186 |
|
187 |
(*********************************************************) |
|
188 |
(* Temporary code to "parse" Vampire proofs *) |
|
189 |
(*********************************************************) |
|
190 |
||
191 |
fun num_int (Number n) = n |
|
192 |
| num_int _ = raise VampError "Not a number" |
|
193 |
||
194 |
fun takeUntil ch [] res = (res, []) |
|
195 |
| takeUntil ch (x::xs) res = if x = ch |
|
196 |
then |
|
197 |
(res, xs) |
|
198 |
else |
|
199 |
takeUntil ch xs (res@[x]) |
|
200 |
||
201 |
fun linenums [] nums = nums |
|
202 |
| linenums (x::xs) nums = let val (fst, rest ) = takeUntil (Other "%") (x::xs) [] |
|
203 |
in |
|
204 |
if rest = [] |
|
205 |
then |
|
206 |
nums |
|
207 |
else |
|
16520 | 208 |
let val first = hd rest |
209 |
||
16478 | 210 |
in |
16520 | 211 |
if (first = (Other "*") ) |
212 |
then |
|
213 |
||
214 |
linenums rest ((num_int (hd (tl rest)))::nums) |
|
215 |
else |
|
216 |
linenums rest ((num_int first)::nums) |
|
16478 | 217 |
end |
218 |
end |
|
219 |
||
16520 | 220 |
|
221 |
(* This relies on a Vampire proof line starting "% Number" or "% * Number"*) |
|
222 |
(* Check this is right *) |
|
223 |
||
224 |
fun get_linenums proofstr = let (*val s = extract_proof proofstr*) |
|
225 |
val tokens = #1(lex proofstr) |
|
16478 | 226 |
|
227 |
in |
|
228 |
rev (linenums tokens []) |
|
229 |
end |
|
230 |
||
231 |
(************************************************************) |
|
232 |
(************************************************************) |
|
233 |
||
234 |
||
235 |
(**************************************************) |
|
236 |
(* Code to parse SPASS proofs *) |
|
237 |
(**************************************************) |
|
238 |
||
15642 | 239 |
datatype Tree = Leaf of string |
240 |
| Branch of Tree * Tree |
|
241 |
||
242 |
||
243 |
fun number ((Number n)::rest) = (n, rest) |
|
244 |
| number _ = raise NOPARSE_NUM |
|
245 |
fun word ((Word w)::rest) = (w, rest) |
|
246 |
| word _ = raise NOPARSE_WORD |
|
247 |
||
248 |
fun other_char ( (Other p)::rest) = (p, rest) |
|
249 |
| other_char _ =raise NOPARSE_WORD |
|
250 |
||
251 |
val number_list = |
|
252 |
(number ++ many number) |
|
253 |
>> (fn (a, b) => (a::b)) |
|
254 |
||
255 |
val term_num = |
|
256 |
(number ++ (a (Other ".")) ++ number) >> (fn (a, (_, c)) => (a, c)) |
|
257 |
||
16548
aa36ae6b955e
Temporarily removed Rewrite from the translation code so that parsing with work on lists of numbers.
quigley
parents:
16520
diff
changeset
|
258 |
|
aa36ae6b955e
Temporarily removed Rewrite from the translation code so that parsing with work on lists of numbers.
quigley
parents:
16520
diff
changeset
|
259 |
val term_num_list = (term_num ++ many (a (Other ",") ++ term_num >> snd) |
aa36ae6b955e
Temporarily removed Rewrite from the translation code so that parsing with work on lists of numbers.
quigley
parents:
16520
diff
changeset
|
260 |
>> (fn (a, b) => (a::b))) |
aa36ae6b955e
Temporarily removed Rewrite from the translation code so that parsing with work on lists of numbers.
quigley
parents:
16520
diff
changeset
|
261 |
|
15642 | 262 |
val axiom = (a (Word "Inp")) |
263 |
>> (fn (_) => Axiom) |
|
264 |
||
265 |
||
266 |
val binary = (a (Word "Res")) ++ (a (Other ":")) |
|
267 |
++ term_num ++ (a (Other ",")) |
|
268 |
++ term_num |
|
269 |
>> (fn (_, (_, (c, (_, e)))) => Binary (c, e)) |
|
270 |
||
271 |
||
272 |
||
273 |
val factor = (a (Word "Fac")) ++ (a (Other ":")) |
|
274 |
++ term_num ++ (a (Other ",")) |
|
275 |
++ term_num |
|
276 |
>> (fn (_, (_, (c, (_, e)))) => Factor ((fst c), (snd c),(snd e))) |
|
277 |
||
278 |
val para = (a (Word "SPm")) ++ (a (Other ":")) |
|
279 |
++ term_num ++ (a (Other ",")) |
|
280 |
++ term_num |
|
281 |
>> (fn (_, (_, (c, (_, e)))) => Para (c, e)) |
|
282 |
||
16357 | 283 |
val super_l = (a (Word "SpL")) ++ (a (Other ":")) |
284 |
++ term_num ++ (a (Other ",")) |
|
285 |
++ term_num |
|
286 |
>> (fn (_, (_, (c, (_, e)))) => Super_l (c, e)) |
|
287 |
||
288 |
||
289 |
val super_r = (a (Word "SpR")) ++ (a (Other ":")) |
|
290 |
++ term_num ++ (a (Other ",")) |
|
291 |
++ term_num |
|
292 |
>> (fn (_, (_, (c, (_, e)))) => Super_r (c, e)) |
|
293 |
||
294 |
||
295 |
val aed = (a (Word "AED")) ++ (a (Other ":")) ++ term_num |
|
296 |
>> (fn (_, (_, c)) => Obvious ((fst c),(snd c))) |
|
297 |
||
15642 | 298 |
val rewrite = (a (Word "Rew")) ++ (a (Other ":")) |
16548
aa36ae6b955e
Temporarily removed Rewrite from the translation code so that parsing with work on lists of numbers.
quigley
parents:
16520
diff
changeset
|
299 |
++ term_num_list |
aa36ae6b955e
Temporarily removed Rewrite from the translation code so that parsing with work on lists of numbers.
quigley
parents:
16520
diff
changeset
|
300 |
>> (fn (_, (_, (c))) => Rewrite (c)) |
15642 | 301 |
|
302 |
||
303 |
val mrr = (a (Word "MRR")) ++ (a (Other ":")) |
|
304 |
++ term_num ++ (a (Other ",")) |
|
305 |
++ term_num |
|
306 |
>> (fn (_, (_, (c, (_, e)))) => MRR (c, e)) |
|
307 |
||
16357 | 308 |
val ssi = (a (Word "SSi")) ++ (a (Other ":")) |
309 |
++ term_num ++ (a (Other ",")) |
|
310 |
++ term_num |
|
311 |
>> (fn (_, (_, (c, (_, e)))) => SortSimp (c, e)) |
|
312 |
||
313 |
val unc = (a (Word "UnC")) ++ (a (Other ":")) |
|
314 |
++ term_num ++ (a (Other ",")) |
|
315 |
++ term_num |
|
316 |
>> (fn (_, (_, (c, (_, e)))) => UnitConf (c, e)) |
|
317 |
||
318 |
||
15642 | 319 |
|
320 |
val obv = (a (Word "Obv")) ++ (a (Other ":")) ++ term_num |
|
321 |
>> (fn (_, (_, c)) => Obvious ((fst c),(snd c))) |
|
16357 | 322 |
|
323 |
val eqres = (a (Word "EqR")) ++ (a (Other ":")) ++ term_num |
|
324 |
>> (fn (_, (_, c)) => EqualRes ((fst c),(snd c))) |
|
325 |
||
326 |
val con = (a (Word "Con")) ++ (a (Other ":")) ++ term_num |
|
327 |
>> (fn (_, (_, c)) => Condense ((fst c),(snd c))) |
|
328 |
||
15642 | 329 |
(* |
330 |
val hyper = a (Word "hyper") |
|
331 |
++ many ((a (Other ",") ++ number) >> snd) |
|
332 |
>> (Hyper o snd) |
|
333 |
*) |
|
334 |
(* val method = axiom ||binary || factor || para || hyper*) |
|
335 |
||
16357 | 336 |
val method = axiom || binary || factor || para ||super_l || super_r || rewrite || mrr || obv || aed || ssi || unc|| con |
337 |
||
15642 | 338 |
val binary_s = a (Word "binary_s") ++ a (Other ",") ++ term_num |
339 |
>> (fn (_, (_, a)) => Binary_s a) |
|
340 |
val factor_s = a (Word "factor_s") |
|
341 |
>> (fn _ => Factor_s ()) |
|
342 |
val demod_s = a (Word "demod") |
|
343 |
++ (many ((a (Other ",") ++ term_num) >> snd)) |
|
344 |
>> (fn (_, a) => Demod_s a) |
|
345 |
||
346 |
val hyper_s = a (Word "hyper_s") |
|
347 |
++ many ((a (Other ",") ++ number) >> snd) |
|
348 |
>> (Hyper_s o snd) |
|
349 |
val simp_method = binary_s || factor_s || demod_s || hyper_s |
|
350 |
val simp = a (Other ",") ++ simp_method >> snd |
|
351 |
val simps = many simp |
|
352 |
||
353 |
||
354 |
val justification = |
|
355 |
a (Other "[") ++number ++ a (Other ":") ++ method ++ a (Other "]") |
|
356 |
>> (fn (_,(_, (_,(b, _)))) => b) |
|
357 |
||
358 |
||
359 |
exception NOTERM |
|
360 |
||
361 |
||
362 |
fun implode_with_space [] = implode [] |
|
363 |
| implode_with_space [x] = implode [x] |
|
364 |
| implode_with_space (x::[y]) = x^" "^y |
|
365 |
| implode_with_space (x::xs) = (x^" "^(implode_with_space xs)) |
|
366 |
||
367 |
(* FIX - should change the stars and pluses to many rather than explicit patterns *) |
|
368 |
||
369 |
(* FIX - add the other things later *) |
|
370 |
fun remove_typeinfo x = if (String.isPrefix "v_" x ) |
|
371 |
then |
|
372 |
(String.substring (x,2, ((size x) - 2))) |
|
373 |
else if (String.isPrefix "V_" x ) |
|
374 |
then |
|
375 |
(String.substring (x,2, ((size x) - 2))) |
|
376 |
else if (String.isPrefix "typ_" x ) |
|
377 |
then |
|
378 |
"" |
|
379 |
else if (String.isPrefix "Typ_" x ) |
|
380 |
then |
|
381 |
"" |
|
382 |
else if (String.isPrefix "tconst_" x ) |
|
383 |
then |
|
384 |
"" |
|
385 |
else if (String.isPrefix "const_" x ) |
|
386 |
then |
|
387 |
(String.substring (x,6, ((size x) - 6))) |
|
388 |
else |
|
389 |
x |
|
390 |
||
391 |
||
392 |
fun term input = ( ntermlist ++ a (Other "-") ++ a (Other ">") ++ ptermlist >>(fn (a,(_,(_,b))) => (a@b)) |
|
393 |
) input |
|
394 |
||
395 |
(* pterms are terms from the rhs of the -> in the spass proof. *) |
|
396 |
(* they should have a "~" in front of them so that they match with *) |
|
397 |
(* positive terms in the meta-clause *) |
|
398 |
(* nterm are terms from the lhs of the spass proof, and shouldn't *) |
|
399 |
(* "~"s added word ++ a (Other "(") ++ arglist ++ a (Other ")") >> (fn (a,(_,(b,_ ))) => (a^" "^b)) *) |
|
400 |
||
401 |
and pterm input = ( |
|
402 |
peqterm >> (fn (a) => a) |
|
403 |
||
404 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*")++ a (Other "*") ++ a (Other "+") |
|
405 |
>> (fn (a, (_,(b, (_,(_,_))))) => ("~"^" "^(remove_typeinfo a)^" "^b)) |
|
406 |
||
407 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "+") |
|
408 |
>> (fn ( a, (_,(b, (_,(_,_))))) => ("~"^" "^(remove_typeinfo a)^" "^b)) |
|
409 |
||
410 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "*") |
|
411 |
>> (fn ( a, (_,(b, (_,(_,_))))) => ("~"^" "^(remove_typeinfo a)^" "^b)) |
|
412 |
||
413 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") |
|
414 |
>> (fn (a, (_,(b, (_,_)))) => ("~"^" "^(remove_typeinfo a)^" "^b)) |
|
415 |
||
416 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") |
|
417 |
>> (fn ( a, (_,(b,_ ))) => ("~"^" "^(remove_typeinfo a)^" "^b)) |
|
418 |
||
16357 | 419 |
|| word ++ a (Other "*") >> (fn (w,b) => "~"^" "^(remove_typeinfo w)) |
420 |
||
421 |
|| word >> (fn w => "~"^" "^(remove_typeinfo w))) input |
|
15642 | 422 |
|
423 |
and nterm input = |
|
424 |
||
425 |
( |
|
426 |
neqterm >> (fn (a) => a) |
|
427 |
||
428 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "*") ++ a (Other "+") |
|
429 |
>> (fn ( a, (_,(b, (_,(_,_))))) => ((remove_typeinfo a)^" "^b)) |
|
430 |
||
431 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "+") |
|
432 |
>> (fn ( a, (_,(b, (_,(_,_))))) => ((remove_typeinfo a)^" "^b)) |
|
433 |
||
434 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "*") |
|
435 |
>> (fn ( a, (_,(b, (_,(_,_))))) => ((remove_typeinfo a)^" "^b)) |
|
436 |
||
437 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") |
|
438 |
>> (fn ( a, (_,(b, (_,_)))) => ((remove_typeinfo a)^" "^b)) |
|
439 |
||
440 |
|| word ++ a (Other "(") ++ arglist ++ a (Other ")") |
|
441 |
>> (fn (a, (_,(b,_ ))) => ((remove_typeinfo a)^" "^b)) |
|
442 |
||
16357 | 443 |
|| word ++ a (Other "*") >> (fn (w,b) => (remove_typeinfo w)) |
444 |
|| word >> (fn w => (remove_typeinfo w)) |
|
445 |
) input |
|
15642 | 446 |
|
447 |
||
448 |
and peqterm input =( |
|
449 |
||
450 |
a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
451 |
++ a (Other "*") ++ a (Other "*") ++ a (Other "+") |
|
452 |
>> (fn (_,(_,(a,(_,(b,(_,(_,(_,_)))))))) => (a^" ~= "^b)) |
|
453 |
||
454 |
|| a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
455 |
++ a (Other "*") ++ a (Other "+") |
|
456 |
>> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" ~= "^b)) |
|
457 |
||
458 |
|| a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
459 |
++ a (Other "*") ++ a (Other "*") |
|
460 |
>> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" ~= "^b)) |
|
461 |
||
462 |
|| a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
463 |
++ a (Other "*") |
|
464 |
>> (fn (_,(_,(a,(_,(b,(_,_)))))) => (a^" ~= "^b)) |
|
465 |
||
466 |
||
467 |
||a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
468 |
>> (fn (_,(_,(a,(_,(b,_))))) => (a^" ~= "^b))) input |
|
469 |
||
470 |
||
471 |
||
472 |
and neqterm input =( |
|
473 |
||
474 |
a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
475 |
++ a (Other "*") ++ a (Other "*") ++ a (Other "+") |
|
476 |
>> (fn (_,(_,(a,(_,(b,(_,(_,(_,_)))))))) => (a^" = "^b)) |
|
477 |
||
478 |
|| a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
479 |
++ a (Other "*") ++ a (Other "+") |
|
480 |
>> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" = "^b)) |
|
481 |
||
482 |
|| a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
483 |
++ a (Other "*") ++ a (Other "*") |
|
484 |
>> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" = "^b)) |
|
485 |
||
486 |
|| a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
487 |
++ a (Other "*") |
|
488 |
>> (fn (_,(_,(a,(_,(b,(_,_)))))) => (a^" = "^b)) |
|
489 |
||
490 |
||
491 |
||a (Word "equal") ++ a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") |
|
492 |
>> (fn (_,(_,(a,(_,(b,_))))) => (a^" = "^b))) input |
|
493 |
||
494 |
||
495 |
||
496 |
and ptermlist input = (many pterm |
|
497 |
>> (fn (a) => (a))) input |
|
498 |
||
499 |
and ntermlist input = (many nterm |
|
500 |
>> (fn (a) => (a))) input |
|
501 |
||
502 |
(*and arglist input = ( nterm >> (fn (a) => (a)) |
|
503 |
|| nterm ++ many (a (Other ",") ++ nterm >> snd) |
|
504 |
>> (fn (a, b) => (a^" "^(implode_with_space b)))) input*) |
|
505 |
||
506 |
and arglist input = ( nterm ++ many (a (Other ",") ++ nterm >> snd) |
|
507 |
>> (fn (a, b) => (a^" "^(implode_with_space b))) |
|
508 |
|| nterm >> (fn (a) => (a)))input |
|
509 |
||
510 |
val clause = term |
|
511 |
||
15919
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
512 |
|
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
513 |
|
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
514 |
(*val line = number ++ justification ++ a (Other "|") ++ |
15642 | 515 |
a (Other "|") ++ clause ++ a (Other ".") |
15919
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
516 |
>> (fn (a, (z, (_,( _, (c, _))))) => (a, z, c))*) |
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
517 |
|
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
518 |
|
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
519 |
(* not entirely sure nterm is right here, but I don't think you get negative things before the ||s *) |
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
520 |
val line = number ++ justification ++ many( nterm) ++ a (Other "|") ++ |
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
521 |
a (Other "|") ++ clause ++ a (Other ".") |
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
522 |
>> (fn (a, (z, (w, (_,( _, (c, _)))))) => (a, z,(w@ c))) |
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
523 |
|
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
524 |
|
b30a35432f5a
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents:
15789
diff
changeset
|
525 |
|
15642 | 526 |
val lines = many line |
527 |
val alllines = (lines ++ finished) >> fst |
|
528 |
||
529 |
val parse = fst o alllines |
|
530 |
val s = proofstring; |
|
531 |
||
532 |
||
533 |
||
534 |
||
535 |
fun dropUntilNot ch [] = ( []) |
|
536 |
| dropUntilNot ch (x::xs) = if not(x = ch ) |
|
537 |
then |
|
538 |
(x::xs) |
|
539 |
else |
|
540 |
dropUntilNot ch xs |
|
541 |
||
542 |
||
543 |
fun remove_spaces str [] = str |
|
544 |
| remove_spaces str (x::[]) = if x = " " |
|
545 |
then |
|
546 |
str |
|
547 |
else |
|
548 |
(str^x) |
|
16061 | 549 |
| remove_spaces str (x::xs) = |
550 |
let val (first, rest) = ReconOrderClauses.takeUntil " " (x::xs) [] |
|
551 |
val (next) = dropUntilNot " " rest |
|
552 |
in |
|
553 |
if next = [] |
|
554 |
then |
|
555 |
(str^(implode first)) |
|
556 |
else remove_spaces (str^(implode first)^" ") next |
|
557 |
end |
|
15642 | 558 |
|
559 |
||
560 |
fun remove_space_strs clsstrs = map (remove_spaces "") (map explode clsstrs) |
|
561 |
||
562 |
||
563 |
fun all_spaces xs = List.filter (not_equal " " ) xs |
|
564 |
||
565 |
fun just_change_space [] = [] |
|
16061 | 566 |
| just_change_space ((clausenum, step, strs)::xs) = |
567 |
let val newstrs = remove_space_strs strs |
|
568 |
in |
|
569 |
if (all_spaces newstrs = [] ) (* all type_info *) |
|
570 |
then |
|
571 |
(clausenum, step, newstrs)::(just_change_space xs) |
|
572 |
else |
|
573 |
(clausenum, step, newstrs)::(just_change_space xs) |
|
574 |
end; |
|
15642 | 575 |
|
576 |
fun change_space [] = [] |
|
16061 | 577 |
| change_space ((clausenum, step, strs)::xs) = |
578 |
let val newstrs = remove_space_strs strs |
|
579 |
in |
|
580 |
if (all_spaces newstrs = [] ) (* all type_info *) |
|
581 |
then |
|
582 |
(clausenum, step, T_info, newstrs)::(change_space xs) |
|
583 |
else |
|
584 |
(clausenum, step, P_info, newstrs)::(change_space xs) |
|
585 |
end |
|
15642 | 586 |
|
15684
5ec4d21889d6
Reconstruction code, now packaged to avoid name clashes
paulson
parents:
15642
diff
changeset
|
587 |
end; |