packages feed

calc-0.1: Main.hs

module Main where
import System.Environment
import System.IO
import Compile
import Parser

main = do
  hSetBuffering stdout NoBuffering
  x <- getArgs
  parse (if null x then "-compile" else head x)
      where
        shell = do s <- (putStr "Expression: " >> getLine)
                   if null s then putStrLn "Enter an expression..." >> shell
                    else return s
        parse x | "-rpn"     == x = shell >>= (print   . parser . lexer)
                | "-compile" == x = shell >>= (compile . parser . lexer)
                | "-help"    == x = putStrLn $ unlines [ "options:"
                                                        ,"\t\t-compile -- compile to assembly"
                                                        ,"\t\t-rpn     -- show rpn output of expression"
                                                        ,"\t\t-help    -- this help"
                                                       ]
                | otherwise       = error "Invalid argument, try `-help'"