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-------------------------------------------------------------------------------
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescomodule GMPParser where
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescoimport Text.ParserCombinators.Parsec
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescoimport Lexer
3f9cd04710597ee787032a371f33861640ab2abeAdrián Riescoimport ModalLogic
3462be79216360f7196bcaececec5fe03cad970aMartin Kühlimport GMPAS
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl
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 Riesco <?> "GMPParser.par5er"
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl
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
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl <?> "GMPParser.junc"
7cc38b3c10994dd7ce31a79c80c547700ede6435Martin Kühl
7cc38b3c10994dd7ce31a79c80c547700ede6435Martin Kühlinf :: ModalLogic a b => (Formula a)-> Parser (Formula a)-- infix parser
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühlinf f1 =
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl do iot <- junc; f2 <-par5er; return $ Junctor f1 iot f2
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl <?> "GMPParser.inf"
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl
28b2d5ede20044fa1b9cd03ceb8deefa1944e045Martin Kühlprim :: ModalLogic a b => Parser (Formula a) -- primitive parser
fb3fd94a4eb255d4f7c05d17bfab7431f5c8e1f7Martin Kühlprim = do try(string "F")
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;whiteSpace
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl ;return F
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl <|> do try(string "T")
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;whiteSpace
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;return T
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl <|> do try(string "~")
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;whiteSpace
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;f <- par5er
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;return $ Neg f
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl <|> do try(char '(')
8efd110ee9a46516f0faba3e076c4670466e57edMartin Kühl ;whiteSpace
4bb939cba8002dcd6afe5b878e3b5e66f6316d3cMartin Kühl ;f <- par5er
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl ;whiteSpace
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;char ')'
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ;whiteSpace
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ;return f
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl <|> do try(char '[')
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;whiteSpace
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;i <- parseIndex
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;whiteSpace
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;char ']'
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;whiteSpace
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl ;f <-par5er
e6ddb072280a946875eda37f7dea91eac298ce91Martin Kühl ;return $ Mapp (Mop i Square) f
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl <|> do try(char '<')
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühl ;whiteSpace
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;i <- parseIndex
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;whiteSpace
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;char '>'
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;whiteSpace
635d75fbafc33da7c21f9c04ac7dd0b1533b5346Martin Kühl ;f <- par5er
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;return $ Mapp (Mop i Angle) f
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl <?> "GMPParser.prim"
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ühl whiteSpace
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ; x <- p
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ; eof
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ; return x
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ) input
ea0988d909c596e3ba5d795fe4916d6580b6e1bcMartin Kühl
3462be79216360f7196bcaececec5fe03cad970aMartin Kühlrun :: (Ord a, Show a) => Parser (Formula a) -> String -> IO ()
e1f8f9dc2060e76dc87ae593d60cce202dba92c2Martin Kühlrun p input
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl = case (parse p "" input) of
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl Left err -> do putStr "parse error at "
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl ;print err
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 ;print x
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl-------------------------------------------------------------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl-------------------------------------------------------------------------------
3462be79216360f7196bcaececec5fe03cad970aMartin Kühl