smtlib-tools

Programs for working with SMT-LIB files

git clone https://git.8pit.net/smtlib-tools.git

 1module Main where
 2
 3import Conduit
 4import qualified SimpleSMT as SMT
 5import Data.Text (unpack, Text)
 6
 7average :: Monad m => ConduitT Int Void m Int
 8average =
 9    getZipSink (go <$> ZipSink sumC <*> ZipSink lengthC)
10  where
11    go :: Int -> Int -> Int
12    go total len = total `div` fromIntegral len
13
14countDepth :: SMT.SExpr -> Int
15countDepth (SMT.Atom _) = 0
16countDepth (SMT.List []) = 1
17countDepth (SMT.List lst) = 1 + (maximum $ map countDepth lst)
18
19yieldSExpr :: ConduitM Text SMT.SExpr IO ()
20yieldSExpr = loop ""
21  where
22    loop rest = await >>= maybe (return ()) (go . (rest ++) . unpack)
23    go x =
24      case SMT.readSExpr x of
25        Just (expr, rest) -> yield expr >> go rest
26        Nothing -> loop x
27
28maxDepth :: IO Int
29maxDepth =
30  runConduit
31     $ stdinC
32    .| decodeUtf8C
33    .| yieldSExpr
34    .| mapC countDepth
35    .| average
36
37main :: IO ()
38main = maxDepth >>= print