2162N/ADescription : <optional short description entry>
2162N/ACopyright : (c) <Authors or Affiliations>
2162N/AStability : unstable | experimental | provisional | stable | frozen
2162N/APortability : portable | non-portable (<reason>)
2162N/A{-# OPTIONS -fglasgow-exts #-}
2362N/A{------------------------------------------------------------------------------}
2162N/A{- Formulas of Modal CASL -}
2162N/A{------------------------------------------------------------------------------}
2162N/A | Sand (StateFormula a) (StateFormula a)
2162N/A | Sor (StateFormula a) (StateFormula a)
2162N/A | DiamondPast (StateFormula a)
2162N/Adata PathFormula a = State (StateFormula a)
2162N/A | Pand (PathFormula a) (PathFormula a)
2162N/A | Por (PathFormula a) (PathFormula a)
2162N/A -- Future Temporal Operators
2162N/A | W (PathFormula a) (PathFormula a)
2162N/A | U (PathFormula a) (PathFormula a)
2162N/A | B (PathFormula a) (PathFormula a)
2162N/A | W' (PathFormula a) (PathFormula a)
2162N/A | U' (PathFormula a) (PathFormula a)
2162N/A | B' (PathFormula a) (PathFormula a)
-- Past Temporal Operators
| WPast (PathFormula a) (PathFormula a)
| UPast (PathFormula a) (PathFormula a)
| BPast (PathFormula a) (PathFormula a)
| WPast' (PathFormula a) (PathFormula a)
| UPast' (PathFormula a) (PathFormula a)
| BPast' (PathFormula a) (PathFormula a)
instance (Show a) => Show (StateFormula a) where
show phi = showStateFormula phi True
instance (Show a) => Show (PathFormula a) where
show phi = showPathFormula phi True
showStateFormula (Var x) outer = show x
showStateFormula (Snot phi) outer = "not " ++ showStateFormula phi False
showStateFormula (Sand phi psi) True = showStateFormula phi False ++ " /\\ " ++ showStateFormula psi False
showStateFormula (Sor phi psi) True = showStateFormula phi False ++ " \\/ " ++ showStateFormula psi False
showStateFormula (E phi) outer = "E " ++ showPathFormula phi False
showStateFormula (A phi) outer = "A " ++ showPathFormula phi False
showStateFormula (Diamond phi) True = "<> " ++ showStateFormula phi False
showStateFormula (Box phi) True = "[] " ++ showStateFormula phi False
showStateFormula (DiamondPast phi) True = "<~> " ++ showStateFormula phi False
showStateFormula (BoxPast phi) True = "[~] " ++ showStateFormula phi False
showStateFormula (Mu x phi) True = "mu " ++ show x ++ " . " ++ showStateFormula phi False
showStateFormula (Nu x phi) True = "nu " ++ show x ++ " . " ++ showStateFormula phi False
showStateFormula phi False = "(" ++ showStateFormula phi True ++ ")"
showPathFormula (State phi) outer = showStateFormula phi outer
showPathFormula (Pnot phi) outer = "not " ++ showPathFormula phi False
showPathFormula (Pand phi psi) True = showPathFormula phi False ++ " /\\ " ++ showPathFormula psi False
showPathFormula (Por phi psi) True = showPathFormula phi False ++ " \\/ " ++ showPathFormula psi False
showPathFormula (X phi) outer = "X " ++ showPathFormula phi False
showPathFormula (G phi) outer = "G " ++ showPathFormula phi False
showPathFormula (F phi) outer = "F " ++ showPathFormula phi False
showPathFormula (W phi psi) True = showPathFormula phi False ++ " W " ++ showPathFormula psi False
showPathFormula (U phi psi) True = showPathFormula phi False ++ " U " ++ showPathFormula psi False
showPathFormula (B phi psi) True = showPathFormula phi False ++ " B " ++ showPathFormula psi False
showPathFormula (W' phi psi) True = showPathFormula phi False ++ " W! " ++ showPathFormula psi False
showPathFormula (U' phi psi) True = showPathFormula phi False ++ " U! " ++ showPathFormula psi False
showPathFormula (B' phi psi) True = showPathFormula phi False ++ " B! " ++ showPathFormula psi False
showPathFormula (XPast phi) outer = "~X " ++ showPathFormula phi False
showPathFormula (GPast phi) outer = "~G " ++ showPathFormula phi False
showPathFormula (FPast phi) outer = "~F " ++ showPathFormula phi False
showPathFormula (WPast phi psi) True = showPathFormula phi False ++ " ~W " ++ showPathFormula psi False
showPathFormula (UPast phi psi) True = showPathFormula phi False ++ " ~U " ++ showPathFormula psi False
showPathFormula (BPast phi psi) True = showPathFormula phi False ++ " ~B " ++ showPathFormula psi False
showPathFormula (XPast' phi) outer = "~X! " ++ showPathFormula phi False
showPathFormula (WPast' phi psi) True = showPathFormula phi False ++ " ~W! " ++ showPathFormula psi False
showPathFormula (UPast' phi psi) True = showPathFormula phi False ++ " ~U! " ++ showPathFormula psi False
showPathFormula (BPast' phi psi) True = showPathFormula phi False ++ " ~B! " ++ showPathFormula psi False
showPathFormula phi False = "(" ++ showPathFormula phi True ++ ")"
{------------------------------------------------------------------------------}
parser :: Parser a -> Parser (StateFormula a)
parser var = between spaces eof stateImpl where
stateImpl = chainl1 stateOr (do string "->"
stateOr = chainl1 stateAnd (do string "\\/"
stateAnd = chainl1 state (do string "/\\"
y <- option "" (string "~")
"<>" -> liftM Diamond state
"<~>" -> liftM DiamondPast state)
y <- option "" (string "~")
"[~]" -> liftM BoxPast state)
pathImpl = chainl1 pathOr (do string "->"
pathOr = chainl1 pathAnd (do string "\\/"
pathAnd = chainl1 pathBinary (do string "/\\"
pathBinary = chainl1 pathUnary $ (do x <- option "" (string "~")
y <- (string "W" <|> string "U" <|> string "B")
z <- option "" (string "!")
<|> (do x <- option "" (string "~")
y <- (string "X" <|> string "G" <|> string "F")
z <- if concat [x, y] == "~X" then option "" (string "!")
"~X" -> liftM XPast pathUnary
"~G" -> liftM GPast pathUnary
"~F" -> liftM FPast pathUnary
"~X!" -> liftM XPast' pathUnary)
{------------------------------------------------------------------------------}