-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
29 lines (26 loc) · 803 Bytes
/
Main.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
import Text.ParserCombinators.Parsec
import ParseGrammar
import FirstFollow
readHelper :: IO [String]
readHelper = do
x <- getLine
if x == ""
then return [""]
else do xs <- readHelper
return ((x ++ "\n"):xs)
loop :: Grammar -> IO ()
loop g = do
var <- getLine
case parse nonterminal "" var of
Left err -> putStrLn $ show err
Right nt -> do let firsts = show $ firstSet g nt
follows = show $ followSet g nt
putStrLn $ "First Set of " ++ show nt ++ " is: " ++ firsts
putStrLn $ "Follow Set of " ++ show nt ++ " is: " ++ follows
loop g
main = do
x <- readHelper
putStrLn "Queries:"
case parse parseGrammar "" $ concat x of
Left err -> putStrLn $ show err
Right g -> loop g