home *** CD-ROM | disk | FTP | other *** search
- /***********************************************
- Programm BP6: Validierung propositionaler
- Formeln
- ************************************************/
-
- include "MATCH.1"
- include "MATCH.2"
-
- predicates
- pattern(symbol, patternlist)
- main
- retractprops
- wang
- solve(symbol, stringlist)
- put(stringlist, stringlist)
- efface(string, stringlist, stringlist)
- treat(string, symbol, string, string, string)
- repeat
- listdb
- test(stringlist, stringlist)
- check(string)
-
- goal
- main.
-
- include "MATCH.3"
-
- clauses
- pattern(w, [break(["imp", "and", "or"])]).
- pattern(binop, [any(["imp", "and", "or"])]).
- pattern(formula, [W, BINOP, lit("("), bal, lit(","),
- bal, lit(")"), rpos(0)] ):-
- pattern(w, [W]), pattern(binop, [BINOP]).
- pattern(formula, [break(["not"]), lit("not"),
- lit("("), bal, lit(")"), null, null, rpos(0) ]).
-
-
- main:-
- makewindow(1,7,7,"Logic Analyzer",0,0,25,80),
- repeat,
- clearwindow,
- write("Formula:"), nl,
- readln(Input), nl,
- retractprops,
- assertz(prop([], [])),
- trim(Input, Form),
- check(Form),
- put([], [Form]),
- wang, fail.
-
- check(Form) :-
- match(Form, [bal, rpos(0)], _), !.
- check(_):- nl, nl,
- write("*** THIS IS NOT A BALANCED EXPRESSION ***"),
- readchar(_), fail.
-
-
- retractprops :-
- retract(prop(_, _)), fail.
- retractprops.
-
- put(SL1, SL2) :-
- retract(prop(_, _)),
- assertz(prop(SL1, SL2)),
- write(SL1, " ", '\205','\205','\16', " ", SL2),
- nl, nl,
- readchar(_).
-
- wang:- not(prop(_, _)),
- write("valid"), nl,
- readchar(_), !.
- wang:-
- prop(Ante, _),
- solve(ante, Ante), !, wang.
- wang:-
- prop(_, Conseq),
- solve(conseq, Conseq), !,
- wang.
- wang:-
- prop(A, B),
- test(A, B), !, wang.
- wang:-!, write("not valid"), nl,
- readchar(_), retractprops, fail.
-
- test([], _):- !, fail.
- test(_, []):- !, fail.
- test([H| _], B) :-
- member(H, B), !,
- /*write(" OK"), nl,
- listdb,*/
- retract(prop(_, _)).
- test([_| Tail], B):- !, test(Tail, B).
- test(_, _):- !, write("not valid"), nl,
- readchar(_).
-
- solve(ante, [H| _]) :-
- pattern(formula, Pattern),
- match(H, Pattern, [_, Op, _, Phi, _, Psi, _,_]),
- treat(H, ante, Op, Phi, Psi), !.
- solve(ante, [_| Tail]) :-
- solve(ante, Tail).
- solve(conseq, [H| _]) :-
- pattern(formula, Pattern),
- match(H, Pattern, [_, Op, _, Phi, _, Psi, _,_]),
- treat(H, conseq, Op, Phi, Psi), !.
- solve(conseq, [_| Tail]) :-
- solve(conseq, Tail).
-
- treat(Str, ante, "and", Phi, Psi) :-
- prop(Ante, Conseq),
- efface(Str, Ante, Ante1),
- append(Ante1, [Phi], Ante2),
- append(Ante2, [Psi], Ante3),
- put(Ante3, Conseq).
- treat(Str, ante, "or", Phi, Psi):-
- prop(Ante, Conseq),
- efface(Str, Ante, Ante1),
- append(Ante1, [Phi], Ante2),
- put(Ante2, Conseq),
- append(Ante1, [Psi], Ante3),
- assertz(prop(Ante3, Conseq)),
- write(Ante3, " ", '\205','\205','\16', " ", Conseq),
- nl, nl,
- readchar(_).
- treat(Str, ante, "imp", Phi, Psi):-
- prop(Ante, Conseq),
- efface(Str, Ante, Ante1),
- append(Ante1, [Psi], Ante2),
- put(Ante2, Conseq),
- append(Conseq, [Phi], Conseq1),
- assertz(prop(Ante1, Conseq1)),
- write(Ante1, " ", '\205','\205','\16', " ", Conseq1),
- nl, nl,
- readchar(_).
- treat(Str, ante, "not", Phi, _) :-
- prop(Ante, Conseq),
- efface(Str, Ante, Ante1),
- append(Conseq, [Phi], Conseq1),
- put(Ante1, Conseq1).
-
- treat(Str, conseq, "and", Phi, Psi) :-
- prop(Ante, Conseq),
- efface(Str, Conseq, Conseq1),
- append(Conseq1, [Psi], Conseq2),
- put(Ante, Conseq2),
- append(Conseq1, [Phi], Conseq3),
- assertz(prop(Ante, Conseq3)),
- write(Ante, " ", '\205','\205','\16', " ", Conseq3),
- nl, nl,
- readchar(_).
- treat(Str, conseq, "or", Phi, Psi) :-
- prop(Ante, Conseq),
- efface(Str, Conseq, Conseq1),
- append(Conseq1, [Phi], Conseq2),
- append(Conseq2, [Psi], Conseq3),
- put(Ante, Conseq3).
- treat(Str, conseq, "imp", Phi, Psi) :-
- prop(Ante, Conseq),
- efface(Str, Conseq, Conseq1),
- append(Ante, [Phi], Ante1),
- append(Conseq1, [Psi], Conseq2),
- put(Ante1, Conseq2).
- treat(Str, conseq, "not", Phi, _) :-
- prop(Ante, Conseq),
- efface(Str, Conseq, Conseq1),
- append(Ante, [Phi], Ante1),
- put(Ante1, Conseq1).
-
- repeat.
- repeat:- repeat.
-
- efface(A, [A| L], L) :- !.
- efface(A, [B| L], [B| M]) :- efface(A, L, M).
-
- listdb :-
- prop(A, B),
- write("DB=", A, " -> ", B), nl,
- fail.
- listdb:- write("DB= "), readchar(_), nl.
- /**************** Ende BP6 *********************/
-