ちょっと時間がとれないので簡単な物ですみません。
(defun balancingp (str) (let ((ch-list (coerce str 'list))) (labels ((%balancing-p (ch-list stack) (if (char= #\. (car ch-list)) (null stack) (cond ((or (char= #\[ (car ch-list)) (char= #\( (car ch-list))) (%balancing-p (cdr ch-list) (cons (car ch-list) stack))) ((char= #\) (car ch-list)) (if (equal #\( (car stack)) (%balancing-p (cdr ch-list) (cdr stack)) nil)) ((char= #\] (car ch-list)) (if (equal #\[ (car stack)) (%balancing-p (cdr ch-list) (cdr stack)) nil)) (t (%balancing-p (cdr ch-list) stack)))))) (%balancing-p ch-list ())))) (defun main () (loop for line = (read-line) until (string= "." line) do (format t "~A~%" (if (balancingp line) "yes" "no"))))
スタックにプッシュしていって、順番にポップしていってという感じです