Main program ---------------------------------------------------------------------- > module Main ( main ) > where ---------------------------------------------------------------------- ---------------------------------------------------------------------- > import Support > import IOSupport > > import Text.ParserCombinators.Parsec > import Data.Char > import CLI > import Pretty > import CPS > import CPSParser > > import Prim > import Expr > import Limes > import Print > import Parse > import Function hiding ( zero ) > import Derive > import Convert > import Simplify hiding ( summ, prod ) > import Replace > import Table > import Integrate ---------------------------------------------------------------------- Command-line interpreter ---------------------------------------------------------------------- > type MyState = (Expr, Table) > g # f = f . g > main = readTable "integrals" >>= \t -> > putStrLn "for help type /help" >> > commandLineInterpreter > "> " commands evaluate (Var "x", t) ---------------------------------------------------------------------- ---------------------------------------------------------------------- > evaluate :: MyState -> String -> IO MyState > evaluate s x = case runParserCPS (expression s) x of > Left (Nothing, _) -> > putStrLn "sorry, does not compute" >> return s > Left (Just (t, s'), _) -> > putStrLn (pretty 78 t) >> return s' > Right _ -> > putStrLn "syntax error" >> return s ---------------------------------------------------------------------- Abarbeitung von Ausdr"ucken Execution for printing or printer ---------------------------------------------------------------------- > expression (e, t) = ((lit '\'' & var &= \x -> opt expr e &= \e -> > unit (wrap x (Just . derive) e)) > ? (lit '|' & var &= \x -> opt expr e &= \e -> > unit (wrap x (integrate t) e)) > ? (lit '[' & expr &= \e1 -> lit '/' & expr &= \e2 -> > lit ']' & opt expr e &= \e -> > unit (wrap "" (Just . replace (abstract "" e1, > abstract "" e2)) e)) > ? (lits "lim" & var &= \x -> lits "->" & > ext expr &= \a -> opt expr e &= \e -> > unit (wrap' x (limes (mapE (abstract "") a)) e)) > ? (lits "st2" & > unit (wrap "" (Just . standard2) e)) > ? (lits "st3" & number &= \n -> > unit (wrap "" (Just . standard3 (read n)) e)) > ? (expr &= \e -> > unit (wrap "" Just e))) > &= \r -> end & unit r > where > wrap x f = abstract x # standard1 # f > # mapMaybe (standard1 # rapply x # \e' -> (pp e', (e', t))) > wrap' x f = abstract x # standard1 # f > # mapMaybe (mapE (standard1 # rapply "") # \v -> (pp v, (e, t))) ---------------------------------------------------------------------- > rapply x f = apply f (Var x) ---------------------------------------------------------------------- ---------------------------------------------------------------------- > mapMaybe f Nothing = Nothing > mapMaybe f (Just a) = Just (f a) ---------------------------------------------------------------------- Abarbeitung von Kommandos Standardformen zu `expression'!!! Execution for commands standardforms for 'expression' ---------------------------------------------------------------------- > commands = [ > (["/exit", "/quit"], \_ _ -> > exit), > (["?", "/help"], \s _ -> > help >> return s)] ---------------------------------------------------------------------- ---------------------------------------------------------------------- > help = sequence (map putStr [ > " enter expression\n", > "' differentiate (or current expression)\n", > "| integrate (or current expression)\n", > "[/] replace by in (or current)\n", > "lim ... \n", > "st2 standard form 2\n", > "st3 standard form 3 [n]\n", > "? display this command summary\n", > "/exit quit the system\n", > "/help display this command summary\n", > "/quit quit the system\n"]) ---------------------------------------------------------------------- Hilfsfunktionen Helper functions ---------------------------------------------------------------------- > singleton a = [a] ---------------------------------------------------------------------- ---------------------------------------------------------------------- > getNatArg :: [String] -> IO (Integer, [String]) > getNatArg [] = error "argument expected" > getNatArg (arg:args) > | all isDigit arg = return (read arg, args) > | otherwise = error "number expected" ----------------------------------------------------------------------