;;;-*-Mode:LISP; Package: CHAOS; Base:10; Syntax:Common-lisp -*- ;;; ;;; Copyright (c) 2000-2016, Toshimi Sawada. All rights reserved. ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; (in-package :chaos) #|============================================================================= System:CHAOS Module:thstuff File:citp.lisp =============================================================================|# #-:chaos-debug (declaim (optimize (speed 3) (safety 0) #-GCL (debug 0))) #+:chaos-debug (declaim (optimize (speed 1) (safety 3) #-GCL (debug 3))) (defun check-context-module () (unless *current-module* (with-output-chaos-error ('no-context) (format t "No context module is specified, please 'select' or 'open' a module.")))) (defun check-ptree () (unless *proof-tree* (with-output-chaos-error ('no-proof-tree) (format t "No proof is ongoing.")))) (defun check-on-going() (unless (and *proof-tree* (get-unproved-nodes *proof-tree*)) (with-output-chaos-error ('no-target) (format t "There are no unproved goals.")))) (defun check-context-module-and-ptree () (check-context-module) (check-ptree)) ;;; ============================ ;;; CITP related command parsers ;;; ============================ ;;; ;;; :goal { . . .... . } ;;; (defun citp-parse-goal (args) (let ((ax-decls nil)) (dolist (elem (third args)) (push (parse-module-element-1 elem) ax-decls)) (nreverse ax-decls))) ;;; ;;; :apply [to ] ( ...) ;;; ;;; (":apply" ("(" ("tc" "rd" "si") ")")) ;;; (":apply" ("to" ("1-1-1")) ("(" ("RD") ")")) ;;; (defun citp-parse-apply (args) (let ((tactic-forms nil) (tactics nil) (target nil)) (cond ((string-equal (car (second args)) "to") (setq target (car (second (second args)))) (setq tactic-forms (second (third args)))) (t (setq tactic-forms (second (second args))))) (dolist (tac tactic-forms) (let ((tactic (get-tactic tac))) (setq tactics (nconc tactics tactic)))) (cons target tactics))) ;;; citp-parse-ind-on ;;; :ind on (var ... var) ;;; (":ind" ("on" "(" ("A:S-1" "B:S-2" "C:S-3") ")")) ;;; (":ind" ("{" ("on" #1="(" ("L1:List") #2=")") ;;; ("base" #1# ("nil") "." nil #2#) ;;; ("step" #1# ("X:Elm" "T:List") "." nil #2#) "}")) ;;; (":ind" ("{" ("on" #1="(" ("S1:Seq") #2=")") ;;; ("base" #1# ("nil") "." nil #2#) ;;; ("hypo" #1# ("SQ:Seq") "." nil #2#) ;;; ("step" #1# ("EL:Elt" "SQ:Seq") "." nil #2#) "}")) (defun citp-parse-seq-of-terms (module token-list) (let ((terms nil)) (when (atom token-list) (return-from citp-parse-seq-of-terms nil)) (dolist (term? token-list) ;; (format t "~%<<>> ~s" term?) (when (consp term?) (let* ((*parse-variables* nil) (target-term (simple-parse module term? *cosmos*))) (when (or (null (term-sort target-term)) (sort<= (term-sort target-term) *syntax-err-sort* *chaos-sort-order*)) (with-output-chaos-error ('invalid-term) (format t "Could not parse ~s" term?))) (push target-term terms)))) (nreverse terms))) (defun citp-parse-ind-on (args) (check-context-module) (with-in-module (*current-module*) (let ((ind-type (first (second args)))) (flet ((parse-vars (decls) (let ((vars nil)) (dolist (var-decl decls) (let ((var (simple-parse-from-string var-decl))) (when (term-is-an-error var) (with-output-chaos-error ('no-parse) (format t "Illegal variable form: ~a" var-decl))) (unless (term-is-variable? var) (with-output-chaos-error ('no-var) (format t "Invalid argument to ':ind' command: ~a" var-decl))) (push var vars))) (nreverse vars)))) (if (equal ind-type "on") (let ((vars (parse-vars (third (second args))))) (cons :simple vars)) ;; :ind { on () base() [hypo ()] step() } (let* ((decl (second args)) (vars (parse-vars (third (second decl)))) (bases (citp-parse-seq-of-terms *current-module* (third decl))) (hypo (citp-parse-seq-of-terms *current-module* (fourth decl))) (steps (citp-parse-seq-of-terms *current-module* (fifth decl)))) (if steps (list :user vars bases hypo steps) (list :user vars bases nil hypo)))))))) ;;; ;;; :auto ;;; (defun citp-parse-auto (args) (declare (ignore args)) (cons :auto (get-default-tactics))) ;;; ;;; :roll back ;;; (defun citp-parse-roll-back (args) (declare (ignore args)) :roll-back) ;;; ;;; :init {[