-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interact.hs
92 lines (81 loc) · 3.92 KB
/
Interact.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Interact where
import Parser
import Type
import Pretty
import SLD
import Subst
-- Wichtig
inGreen :: String -> String
inGreen s = "\x1b[32m" ++ s ++ "\x1b[0m"
help :: String
help = "Commands available from the prompt: \n" ++
" <goal> Solves/proves the specified goal. \n" ++
" :h Shows this help message. \n" ++
" :l <file> Loads the specified file. \n" ++
" :q Exits the interactive environment. \n" ++
" :s <strat> Sets the specified search strategy where <strat> is one of 'dfs' or 'bfs'."
main :: IO()
main = do
putStrLn("\n***************************")
putStrLn("*" ++ (inGreen " Flavio und Lara @2020 ") ++ "*")
putStrLn( "***************************")
putStrLn(inGreen "Welcome to interactive Prolog!\n")
putStrLn("Type \":h\" for help.")
mainloop (Prog []) dfs -- initial starten wir mit Tiefensuche
mainloop :: Prog -> Strategy -> IO ()
mainloop prog stra = do
putStr "?- "
input <- getLine
case (words input) of -- input holen
[":h"] -> do
putStrLn help
mainloop prog stra
[":help"] -> do
putStrLn help
mainloop prog stra
[":q"] -> do
putStrLn (inGreen "Bye.")
return()
[":quit"] -> do
putStrLn (inGreen "Bye.")
return()
[":s","bfs"] -> do
putStrLn "Strategy set to breadth-first search."
mainloop prog bfs
[":set","bfs"] -> do
putStrLn "Strategy set to breadth-first search."
mainloop prog bfs
[":s","dfs"] -> do
putStrLn "Strategy set to depth-first search."
mainloop prog dfs
[":set","dfs"] -> do
putStrLn "Strategy set to depth-first search."
mainloop prog dfs
(":l":[filename]) -> do
x <- parseFile filename
case x of
(Left err) -> do
putStrLn err
mainloop prog stra
(Right suc) -> do
putStrLn "Loaded. "
mainloop suc stra
_ -> do
let y = parse input :: Either String Goal
case y of
(Left err) -> do
putStrLn err
mainloop prog stra
(Right suc) -> do
let erg = (solve stra prog suc)
if (not (null erg)) then solvePrint(erg) else putStrLn("No solutions.")
mainloop prog stra
-- Substitutionen nur auf Semikolon Eingabe printen
solvePrint :: [Subst] -> IO ()
solvePrint [] = return () -- Fertig geprintet
solvePrint (x:xs) = do
putStr(pretty x)
input <- getLine
if (input == ";") then do
solvePrint(xs)
else return () -- Nutzer hat keinen Bock mehr auf weitere Ergebnisse