NuSmv.hs revision f1edf379717f0ddb7607585a027cf6f03a6fce68
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian MaederModule : $Header$
c63ebf815c8a874525cf18670ad74847f7fc7b26Christian MaederCopyright : (c) Klaus Hartke, Uni Bremen 2008
c092fcac4b8f5c524c22ca579189c4487c13edf7Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiMaintainer : Christian.Maeder@dfki.de
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederStability : experimental
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiPortability : portable
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maedermodule NuSmv (basicExpr, program) where
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian Maederimport Control.Monad (liftM, liftM2)
980c2505814d75dc689de1412f4de30b4d96314fRazvan Pascanuimport Data.Char (toLower)
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maederimport Data.List (intersperse)
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maederimport Text.ParserCombinators.Parsec hiding (State, token)
0799b5dc3f06d2640e66e9ab54b8b217348fd719Christian Maeder(<<) :: (Monad m) => m a -> m b -> m a
0799b5dc3f06d2640e66e9ab54b8b217348fd719Christian Maeder(<<) a b = do x <- a
eb9a06d3b5c6354c0573f0cb93d5a5d558f51136Heng Jiang{------------------------------------------------------------------------------}
59fddbdd745a05adeaf655b617ab8da947903832Christian MaedercheckWith :: (Show a) => GenParser tok st a -> (a -> Bool) -> GenParser tok st a
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till MossakowskicheckWith p f = do x <- p
cfaa17b0d2ed0a663f0a4f18b23f98ab876c2f40Christian Maeder if f x then return x
f77f29e84b3f6e791c82e61b13fbf76582bedd2fChristian Maeder else unexpected (show x)
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian Maederreserved :: [String] -> CharParser st String -> CharParser st String
c0c2380bced8159ff0297ece14eba948bd236471Christian Maederreserved l p = try $ checkWith p (`notElem` l)
5b50a0fb9834540caf04471389df975fbd356ca3Razvan Pascanu{------------------------------------------------------------------------------}
980c2505814d75dc689de1412f4de30b4d96314fRazvan Pascanuws :: Parser ()
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian Maederws = many (oneOf " \t\r\n") >> return ()
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanutoken :: String -> Parser ()
8955ea64c61a6e8b96b7696021863afd1a75f6daRazvan Pascanutoken x = string x >> ws
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanukeyword :: String -> Parser ()
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanukeyword x = try (string x >> notFollowedBy alphaNum) >> ws
ee1c7c5796832536932d7b06cbfb1ca13f9a0d7bMartin Kühlidentifier :: Parser String
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maederidentifier = liftM2 (:) idFirstChar (many idConsecutiveChar) <?> "identifier"
9726e6290bc036adbad9fa7751fc05c10e79d647Christian Maeder idFirstChar = letter
08635fe65017b90fe76df12e064d840619f4ec4eChristian Maeder idConsecutiveChar = idFirstChar
08635fe65017b90fe76df12e064d840619f4ec4eChristian Maeder <|> char '\\'
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanuinteger :: Parser Int
fa388aea9cef5f9734fec346159899a74432ce26Christian Maederinteger = liftM read (liftM2 (++) (option "" (string "-")) (many1 digit)) <?> "integer number"
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu{------------------------------------------------------------------------------}
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanukeywords :: [String]
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanukeywords = [ "MODULE", "DEFINE", "CONSTANTS", "VAR", "IVAR", "INIT", "TRANS",
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu "INVAR", "SPEC", "CTLSPEC", "LTLSPEC", "PSLSPEC", "COMPUTE",
48c6e734f777f9fe756f171077560066937a3275Klaus Luettich "INVARSPEC", "FAIRNESS", "JUSTICE", "COMPASSION", "ISA", "ASSIGN",
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu "CONSTRAINT", "SIMPWFF", "CTLWFF", "LTLWFF", "PSLWFF", "COMPWFF",
48c6e734f777f9fe756f171077560066937a3275Klaus Luettich "IN", "MIN", "MAX", "process", "array", "of", "boolean",
16281c97e3e04f9f88c806d7da79feb106dbee2aTill Mossakowski "integer", "real", "word", "word1", "bool", "EX", "AX", "EF",
fe5d536284c81622d823a99a92db6e94fa8583d2Razvan Pascanu "AF", "EG", "AG", "E", "F", "O", "G", "H", "X", "Y", "Z", "A",
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu "U", "S", "V", "T", "BU", "EBF", "ABF", "EBG", "ABG", "case",
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu "esac", "mod", "next", "init", "union", "in", "xor", "xnor",
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu "self", "TRUE", "FALSE" ]
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu{------------------------------------------------------------------------------}
f1dec6898638ba1131a9fadbc4d1544c93dfabb0Klaus Luettich{- Basic Expressions of NuSMV -}
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu{------------------------------------------------------------------------------}
| Not Expr -- Logical/Bitwise NOT
| And Expr Expr -- Logical/Bitwise AND
| Or Expr Expr -- Logical/Bitwise OR
| Xor Expr Expr -- Logical/Bitwise XOR
| Xnor Expr Expr -- Logical/Bitwise NOT XOR
| Impl Expr Expr -- Logical/Bitwise Implication
| Equiv Expr Expr -- Logical/Bitwise Equivalence
showBasicExpr (And exprA exprB) True = concat [ showBasicExpr exprA False, " & ", showBasicExpr exprB False ]
showBasicExpr (Or exprA exprB) True = concat [ showBasicExpr exprA False, " | ", showBasicExpr exprB False ]
showBasicExpr (Xor exprA exprB) True = concat [ showBasicExpr exprA False, " xor ", showBasicExpr exprB False ]
showBasicExpr (Xnor exprA exprB) True = concat [ showBasicExpr exprA False, " xnor ", showBasicExpr exprB False ]
showBasicExpr (Impl exprA exprB) True = concat [ showBasicExpr exprA False, " -> ", showBasicExpr exprB False ]
showBasicExpr (Equiv exprA exprB) True = concat [ showBasicExpr exprA False, " <-> ", showBasicExpr exprB False ]
showBasicExpr (Eq exprA exprB) True = concat [ showBasicExpr exprA False, " = ", showBasicExpr exprB False ]
showBasicExpr (Neq exprA exprB) True = concat [ showBasicExpr exprA False, " != ", showBasicExpr exprB False ]
showBasicExpr (Lt exprA exprB) True = concat [ showBasicExpr exprA False, " < ", showBasicExpr exprB False ]
showBasicExpr (Gt exprA exprB) True = concat [ showBasicExpr exprA False, " > ", showBasicExpr exprB False ]
showBasicExpr (Leq exprA exprB) True = concat [ showBasicExpr exprA False, " <= ", showBasicExpr exprB False ]
showBasicExpr (Geq exprA exprB) True = concat [ showBasicExpr exprA False, " >= ", showBasicExpr exprB False ]
showBasicExpr (Add exprA exprB) True = concat [ showBasicExpr exprA False, " + ", showBasicExpr exprB False ]
showBasicExpr (Sub exprA exprB) True = concat [ showBasicExpr exprA False, " - ", showBasicExpr exprB False ]
showBasicExpr (Mult exprA exprB) True = concat [ showBasicExpr exprA False, " * ", showBasicExpr exprB False ]
showBasicExpr (Div exprA exprB) True = concat [ showBasicExpr exprA False, " / ", showBasicExpr exprB False ]
showBasicExpr (Mod exprA exprB) True = concat [ showBasicExpr exprA False, " mod ", showBasicExpr exprB False ]
showBasicExpr (Bsr exprA exprB) True = concat [ showBasicExpr exprA False, " >> ", showBasicExpr exprB False ]
showBasicExpr (Bsl exprA exprB) True = concat [ showBasicExpr exprA False, " << ", showBasicExpr exprB False ]
showBasicExpr (Concat exprA exprB) True = concat [ showBasicExpr exprA False, " :: ", showBasicExpr exprB False ]
showBasicExpr (Select expr (from, to)) outer = concat [ showBasicExpr expr False, "[", show from, ", ", show to, "]" ]
showBasicExpr (Union exprA exprB) True = concat [ showBasicExpr exprA False, " union ", showBasicExpr exprB False ]
showBasicExpr (Set exprs) outer = concat [ "{", concat (intersperse ", " (map (\expr-> showBasicExpr expr False) exprs)), "}" ]
showBasicExpr (In exprA exprB) True = concat [ showBasicExpr exprA False, " in ", showBasicExpr exprB False ]
showBasicExpr (Case cases) outer = concat [ "case ", concat (intersperse "\n" (map (\(exprA, exprB)-> concat [showBasicExpr exprA False, " : ", showBasicExpr exprB False, ";"]) cases)), " esac" ]
showModule (Module name params elements) = concat [ "MODULE ", name, showParams params, "\n", concatMap showElement elements ]
showElement (Compassion exprA exprB) = concat [ "COMPASSION(", showBasicExpr exprA True, ", ", showBasicExpr exprB True, ");\n" ]