Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lisp code (s-expression) formatter

jSIMLIB checker prints out s-expression code that is essentially lisp code

(set-option :print-success false) 
(set-logic QF_LIA) 
(declare-fun RETURN () Int)
(declare-fun refs_1_SYMINT () Int)
(declare-fun flags_2_SYMINT () Int)
(assert+ ( and ( or ( and (/= flags_2_SYMINT 0) (and (= RETURN flags_2_SYMINT)) ) ( and (/= refs_1_SYMINT 0) (and (= flags_2_SYMINT 0)) (and (= RETURN refs_1_SYMINT)) ) ( and (and (= refs_1_SYMINT 0)) (and (= flags_2_SYMINT 0)) (and (= RETURN 100)) ) ) ( not ( or ( and (/= flags_2_SYMINT 0) (and (= RETURN flags_2_SYMINT)) ) ( and (/= refs_1_SYMINT 0) (and (= flags_2_SYMINT 0)) (and (= RETURN refs_1_SYMINT)) ) ( and (and (= refs_1_SYMINT 0)) (and (= flags_2_SYMINT 0)) (and (= RETURN 10)) ) ) ) ) )
(check)
(exit)

How can I format the code, preferable with emacs or TextMate? For example:

(set-option :print-success false) 
(set-logic QF_LIA) 
(declare-fun RETURN () Int)
(declare-fun refs_1_SYMINT () Int)
(declare-fun flags_2_SYMINT () Int)
(assert 
  (and  
    (and 
      (and  
        (distinct  flags_2_SYMINT 0)  
        (=  RETURN flags_2_SYMINT))
      (=  refs_1_SYMINT refs1_1_SYMINT)
      (=  flags_2_SYMINT flags1_2_SYMINT))
    (not 
      (and  
        (distinct  flags_2_SYMINT 0) 
        (=  RETURN flags_2_SYMINT))))) 
(check-sat)
like image 883
prosseek Avatar asked Dec 03 '22 01:12

prosseek


1 Answers

The pp function can print things out nicely but may not exactly match the formatting you want.

Here's one line from your question:

(pp '(assert+ ( and ( or ( and (/= flags_2_SYMINT 0) (and (= RETURN flags_2_SYMINT)) ) ( and (/= refs_1_SYMINT 0) (and (= flags_2_SYMINT 0)) (and (= RETURN refs_1_SYMINT)) ) ( and (and (= refs_1_SYMINT 0)) (and (= flags_2_SYMINT 0)) (and (= RETURN 100)) ) ) ( not ( or ( and (/= flags_2_SYMINT 0) (and (= RETURN flags_2_SYMINT)) ) ( and (/= refs_1_SYMINT 0) (and (= flags_2_SYMINT 0)) (and (= RETURN refs_1_SYMINT)) ) ( and (and (= refs_1_SYMINT 0)) (and (= flags_2_SYMINT 0)) (and (= RETURN 10)) ) ) ) ) ))

output is:

(assert+
 (and
  (or
   (and
    (/= flags_2_SYMINT 0)
    (and
     (= RETURN flags_2_SYMINT)))
   (and
    (/= refs_1_SYMINT 0)
    (and
     (= flags_2_SYMINT 0))
    (and
     (= RETURN refs_1_SYMINT)))
   (and
    (and
     (= refs_1_SYMINT 0))
    (and
     (= flags_2_SYMINT 0))
    (and
     (= RETURN 100))))
  (not
   (or
    (and
     (/= flags_2_SYMINT 0)
     (and
      (= RETURN flags_2_SYMINT)))
    (and
     (/= refs_1_SYMINT 0)
     (and
      (= flags_2_SYMINT 0))
     (and
      (= RETURN refs_1_SYMINT)))
    (and
     (and
      (= refs_1_SYMINT 0))
     (and
      (= flags_2_SYMINT 0))
     (and
      (= RETURN 10)))))))
like image 142
amitp Avatar answered Dec 05 '22 15:12

amitp