-- Main module for simple expression parser and evaluator
-- Developed for use in COMP2600
-- Clem Baker-Finch

module Main (main) where

-- import IO
import Parser
import Evaluator

-- One expression per line.  Get the source expression, parse it and
-- evaluate it.  Print the resulting state to stdout.  Exit on ".".

main :: IO()
main = do
       putStrLn "Enter an expression, e.g. \"12 + (32 - 6) * 19\""
       putStrLn "Type \"q\" to quit.\n"
       evalLoop

evalLoop :: IO()
evalLoop = do
           putStr "> "
           source <- getLine
           if source == "q" 
              then return()
              else do
                   let result = eval (parseExp source)
                   putStrLn ("\t= " ++ show result ++ "\n")
                   evalLoop


