-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
27 lines (26 loc) · 758 Bytes
/
Main.hs
File metadata and controls
27 lines (26 loc) · 758 Bytes
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
module Main where
import Lexer (lexicallyAnalyse)
import Tokens (Token, Token(..))
import Ast (
Exp, Exp(..),
Exp', Exp'(..),
Term, Term(..),
Term',Term'(..),
Factor, Factor(..),
Atom, Atom(..),
ArithOp, ArithOp(..))
import Parser (parse)
import Evaluator (evaluate)
main :: IO ()
main = do
expression <- getLine
maybeTokens <- return (lexicallyAnalyse expression)
case maybeTokens of
(Just tokens) -> do
maybeExp <- return (parse tokens)
case maybeExp of
(Just exp) -> do
result <- return (evaluate exp)
putStrLn (show result)
Nothing -> putStrLn "The input expression is not semantically valid!"
Nothing -> putStrLn "The input expression is not lexically valid!"