GMP.CoalitionL.hs revision 61b020f416f2204caf544da16d97b9955148b53e
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder{-# OPTIONS -fglasgow-exts #-}
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maedermodule GMP.CoalitionL where
81d182b21020b815887e9057959228546cf61b6bChristian Maeder
10397bcc134edbcfbe3ae2c7ea4c6080036aae22Christian Maederimport GMP.GMPAS
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maederimport GMP.ModalLogic
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maederimport qualified Data.Bits as Bits
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maederimport Text.ParserCombinators.Parsec
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maederdata CLrules = CLrules ()
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maederinstance ModalLogic CL CLrules where
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder-- orderIns _ = True
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder flagML _ = None
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder parseIndex = do (CL rres,size) <- bitParse 0
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder ;let res = revbInt rres size
1ae7298170b7a26dce9acc6d2c864fb01f0cb347Christian Maeder ;return (CL res)
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder matchR _ = [CLrules ()]
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder guessClause r = case r of
59c301c268f79cfde0a4c30a2c572a368db98da5Christian Maeder _ -> []
1ae7298170b7a26dce9acc6d2c864fb01f0cb347Christian Maeder-- Bit-String parsing ---------------------------------------------------------
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian MaederrevbInt :: Integer -> Int -> Integer
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaederrevbInt k s
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder = let
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maeder revaux (x,size,y,i)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder = if (i == (size+1))
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder then 0
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder else let auxy = revaux(x,size,y,i+1)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder in if (Bits.testBit x i)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder then Bits.setBit auxy (size-i)
f42bcc750a9a02cb4f753b70679f9aacf1b338d7Christian Maeder else Bits.clearBit auxy (size-i)
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder in revaux(k,s,0::Int,0::Int)
10397bcc134edbcfbe3ae2c7ea4c6080036aae22Christian MaederbitParse :: Int -> GenParser Char st (CL, Int)
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaederbitParse i = do try(char('0'))
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ;(CL n, size) <- bitParse (i+1)
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder ;return((CL(Bits.clearBit n i), size))
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder <|> do try(char('1'))
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ;(CL n, size) <- bitParse (i+1)
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian Maeder ;return((CL(Bits.setBit n i), size))
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder <|> return ((CL 0), i-1)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder <?> "GMPParse.bitParse"
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder-------------------------------------------------------------------------------
32a7cc7177ecf70e35ec831ff86887b9acc40dcaChristian Maeder