GMPParser.hs revision edf1cf81945b26f90b0a40bf1669099466e7e43e
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riesco-------------------------------------------------------------------------------
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner-- the Generic Model Parser Abstract Syntax
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl-- Copyright 2007, Lutz Schroeder and Georgel Calin
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl-------------------------------------------------------------------------------
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescomodule GMPParser where
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescoimport ModalLogic
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühlimport GMPSAT
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl-------------------------------------------------------------------------------
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl-- Parser for polymorphic (Formula a) Type
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl-------------------------------------------------------------------------------
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühlpar5er :: ModalLogic a b => Parser (Formula a) -- main parser
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescopar5er = do f <- prim; option (f) (inf f)
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescojunc :: Parser Junctor -- junctor parser
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescojunc = do try(string "/\\"); whiteSpace; return And
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl <|> do try(string "\\/"); whiteSpace; return Or
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl <|> do try(string "->"); whiteSpace; return If
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl <|> do try(string "<->"); whiteSpace; return Iff
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder <|> do try(string "<-"); whiteSpace; return Fi
7cc38b3c10994dd7ce31a79c80c547700ede6435Martin Kühlinf :: ModalLogic a b => (Formula a)-> Parser (Formula a)-- infix parser
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl do iot <- junc; f2 <-par5er; return $ Junctor f1 iot f2
28b2d5ede20044fa1b9cd03ceb8deefa1944e045Martin Kühlprim :: ModalLogic a b => Parser (Formula a) -- primitive parser
fb3fd94a4eb255d4f7c05d17bfab7431f5c8e1f7Martin Kühlprim = do try(string "F")
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl <|> do try(string "T")
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl <|> do try(string "~")
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;f <- par5er
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;return $ Neg f
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl <|> do try(char '(')
4bb939cba8002dcd6afe5b878e3b5e66f6316d3cMartin Kühl ;f <- par5er
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl <|> do try(char '[')
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;i <- parseIndex
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl ;return $ Mapp (Mop i Square) f
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl <|> do try(char '<')
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;i <- parseIndex
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;f <- par5er
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;return $ Mapp (Mop i Angle) f
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl-------------------------------------------------------------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl-- Funtion to run parser & print
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl-------------------------------------------------------------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin KühlrunLex :: (Ord a, Show a) => Parser (Formula a) -> String -> IO ()
3462be79216360f7196bcaececec5fe03cad970aMartin KühlrunLex p input = run (do
3462be79216360f7196bcaececec5fe03cad970aMartin Kühlrun :: (Ord a, Show a) => Parser (Formula a) -> String -> IO ()
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl = case (parse p "" input) of
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl Left err -> do putStr "parse error at "
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl Right x -> do let ls = guessPV x -----------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;let h = head(ls) ------------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;print h ------------ FOR TESTING --------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;let lro = test (h) ----------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ; print lro ------------------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl-------------------------------------------------------------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl-------------------------------------------------------------------------------