File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 :description " An Inference Engine using Propositional Calculus"
99 :author " Manoel Vilela <manoel_vilela@engineer.com>"
1010 :license " BSD"
11- :version " 0.1 .0"
11+ :version " 0.2 .0"
1212 :serial t
1313 :pathname " src"
1414 :components ((:file " package" )
2525 :description " Lisp Inference Test Suit"
2626 :author " Manoel Vilela <manoel_vilela@engineer.com>"
2727 :license " BSD"
28- :version " 0.1 .0"
28+ :version " 0.2 .0"
2929 :serial t
3030 :pathname " t"
3131 :depends-on (:lisp-inference :prove )
Original file line number Diff line number Diff line change 4040 # :make-biconditional
4141 # :*valid-operators*
4242 # :prefix-to-infix
43+ # :infix-to-prefix
4344 # :print-truth-table ; ; truth-table.lisp
4445 # :eval-expression
4546 # :equal-expression
Original file line number Diff line number Diff line change 112112
113113
114114(defun infix-to-prefix (exp )
115- (cond ((atom exp ) exp )
116- ((null (cdr exp )) (infix-to-prefix (car exp )))
117- (t (list (cadr exp )
118- (infix-to-prefix (car exp ))
119- (infix-to-prefix (cddr exp ))))))
115+ " INFIX-TO-PREFIX translate a infix expression to a prefix expression.
116+
117+ This function assumes that exp it is not ambiguous.
118+ In that case, use a completly 'parenthesed' expression
119+
120+ Returns a new prefixed list.
121+ "
122+ (cond ((atom exp ) exp )
123+ ((and (listp exp )
124+ (= 2 (length exp )))
125+ (list (car exp )
126+ (infix-to-prefix (cdr exp ))))
127+ ((null (cdr exp )) (infix-to-prefix (car exp )))
128+ (t (list (cadr exp )
129+ (infix-to-prefix (car exp ))
130+ (infix-to-prefix (cddr exp ))))))
Original file line number Diff line number Diff line change 33
44(in-package :lisp-inference )
55
6+ (defparameter *truth-string* " T" )
7+ (defparameter *false-string* " F" )
8+
69(defun propositionp (symbol )
710 " Check if the given SYMBOL can be a proposition (letters)"
811 (and (atom symbol )
106109
107110(defun pretty-values (v)
108111 (if (not (null v))
109- " T "
110- " F " ))
112+ *truth-string*
113+ *false-string* ))
111114
112115(defun prepare-table (evaluated-cases)
113116 " Get the evaluated cases after EVAL-OPERATIONS
@@ -204,10 +207,10 @@ a tautology."
204207
205208
206209(defun main ()
207- (format t " Example of usage: (^ p q)~% Operators: ~a ~% " *valid-operators* )
210+ (format t " Example of usage: (p ^ q)~% Operators: ~a ~% " *valid-operators* )
208211 (handler-case (loop do (princ " TRUTH-TABLE> " )
209212 do (force-output )
210- do (print-truth-table (read )))
213+ do (print-truth-table (infix-to-prefix ( read ) )))
211214 (end-of-file () )
212215 #+ sbcl (sb-sys :interactive-interrupt () nil ))
213216
Original file line number Diff line number Diff line change 102102 ' (p))
103103 " EQUAL EXPRESSION 2" )
104104
105+ (diag " == Infix Parsing" )
106+
107+ (is (infix-to-prefix ' (~ (p v q)))
108+ ' (~ (v p q)))
109+
110+ (is (infix-to-prefix ' (p => q))
111+ ' (=> p q))
112+
113+ (is (infix-to-prefix ' ((p v q) <=> ((~ p) ^ (~ q))))
114+ ' (<=> (v p q)
115+ (^ (~ p)
116+ (~ q))))
117+
105118(finalize)
You can’t perform that action at this time.
0 commit comments