5.Apêndice
Código do programa em Prolog
/*[]-------------------------------------------------------------------------------------------------[]
[] Definicao dos operadores, de acordo com suas prioridades(ordem decrescente) []
[]--------------------------------------------------------------------------------------------------[]*/
:- op(500,fy,not).
:- op(600,xfy,and).
:- op(700,xfy,or).
:- op(800,xfy,=>).
/*[]--------------------------------------------------------------------------------[]
[] Definicao dos Predicados para negacao da expressao []
[]---------------------------------------------------------------------------------[]*/
/* Simplificacao da expressao booleana
usando a regra not not a <=> a
e validacao da entrada */
simplifica(not ( not X),Y):- !,simplifica(X,Y).
simplifica(X,X):- !, X\==not,X\== or, X\== and, X\== =>, X\== not not, X\== not (and), X\== not (or), X\== not ( => ).
/* Negacao da expressao de entrada usando as
seguintes regras:
not(a => b) <=> a and not b
not(a and b) <=> not a or not b
not(a or b) <=> not a and not b
not(a) <=> not a
*/
negacao(X => Y, W and Z):- !, simplifica(X,W), negacao(Y,Z).
negacao(X and Y,K or F):-!,negacao(X,K), negacao(Y,F).
negacao(X or Y, K and F):-!, negacao(X,K), negacao(Y,F).
negacao(X, Y):- simplifica(not X,Y).
/*[]------------------------------------------------------------------------------[]
[] Predicados usdaos na Interface grafica para resposta []
[]--------------------------------------------------------------------------------[]*/
% inicializa a aplicacao que ira negar uma expressao logica composta por operacoes and,
% or, not e =>
neg(X) :-
wfocus( Window ),
create_resp_win(X),
window_handler( resposta, resp_handler ),
show_dialog( resposta ).
% define a janela de dialogo e insere os componentes nesta
create_resp_win(X) :-
negacao(X,Y), % calcula a negacao da resposta
% estilos dos componentes
Dstyle = [dlg_ownedbyprolog,ws_sysmenu,ws_caption,dlg_modalframe],
Estyle = [ws_child,ws_visible,es_left,es_readonly],
Sstyle = [ws_child,ws_visible,ss_left],
Bstyle = [ws_child,ws_visible,ws_tabstop,bs_pushbutton],
% janela de dialogo principal
wdcreate( resposta,`Negacao de Expressoes Logicas`, 1, 150, 500, 110, Dstyle ),
% componentes da janela
wccreate( (resposta,1), static, 'Expressao:', 10, 8, 60, 16, Sstyle ),
wccreate( (resposta,2), edit, X, 65, 8, 425, 16, Estyle ),
wccreate( (resposta,3), static, 'Resposta:', 10, 30, 60, 16, Sstyle ),
wccreate( (resposta,4), edit, Y, 65, 30, 425, 16, Estyle ),
% wccreate( (resposta,5), button, `&Calcular`, 195, 52, 50, 30, Bstyle ),
wccreate( (resposta,6), button, `&Sair`, 225/*255*/, 52, 50, 30, Bstyle )
.
% Ao receber uma mensagem "msg_close", reinicializa o handler do dialogo e fecha
% a janela de dialogo.
resp_handler( _, msg_close, _, _ ):-
window_handler( resposta, window_handler ),
wclose( resposta ).
% Evento do click sobre o botao fechar, que encerra a aplicacao.
resp_handler( (resposta,6), msg_button, _, _ ) :-
window_handler( resposta, window_handler ),
wclose( resposta ).