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