From c8f70a66ad6ebd2d618a998a3787651a87921cac Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 18 Jul 2018 15:54:36 +0200 Subject: [PATCH] main program --- main.icl | 23 +++++++++++++++++++++++ parse.dcl | 2 +- parse.icl | 25 ++----------------------- 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 main.icl diff --git a/main.icl b/main.icl new file mode 100644 index 0000000..edf5b3a --- /dev/null +++ b/main.icl @@ -0,0 +1,23 @@ +module main + +import StdEnv +import System.CommandLine +import Data.Func + +import ast +import parse +import infer + +readFile :: *File -> ([Char], *File) +readFile f +# (ok, c, f) = freadc f +| not ok = ([], f) +# (rest, f) = readFile f += ([c:rest], f) + +Start w +# (io, w) = stdio w +# ([argv0:argv], w) = getCommandLine w +# (chars, io) = readFile io += parse zero + $ lex chars diff --git a/parse.dcl b/parse.dcl index e059278..7327c57 100644 --- a/parse.dcl +++ b/parse.dcl @@ -10,4 +10,4 @@ from StdOverloaded import class zero instance zero ParseState lex :: [Char] -> [Token] -parse :: [Token] ParseState -> Either [String] AST +parse :: ParseState [Token] -> Either [String] AST diff --git a/parse.icl b/parse.icl index 4359629..00c5f44 100644 --- a/parse.icl +++ b/parse.icl @@ -94,8 +94,8 @@ token t :== parseIf ((=+?=)t) top (until) infix 5 :: (Parser a) (Parser b) -> Parser ([a], b) (until) p grd = (tuple [] <$> grd) <|> (appFst o 'SS'._cons <$> p <*> p until grd) -parse :: [Token] ParseState -> Either [String] AST -parse ts st = runStateT parseAST {st & tokens=ts} >>= uncurry parse2 +parse :: ParseState [Token] -> Either [String] AST +parse st ts = runStateT parseAST {st & tokens=ts} >>= uncurry parse2 parse2 :: AST ParseState -> Either [String] AST parse2 (AST fs) ps = AST <$> mapM pfun fs @@ -171,24 +171,3 @@ parseIdent = (\(IdentToken s)->s) <$> token (IdentToken "") parseInt :: Parser Int parseInt = (\(IntToken i)->i) <$> token (IntToken 0) - -Start = - toString <$> parse ( - lex $ - ['id x = x;'] ++ - ['const x y = x;'] ++ - ['flip x y z = x z y;'] ++ - ['twice f = f . f;'] ++ - ['fix f x = let x = f x in x;'] ++ - ['. infixr 9 f g x = f $ g x;'] ++ - ['$ infixr 0 = id;'] ++ - ['& infixr 0 = flip $;'] ++ - ['+ infixr 6 = code add;'] ++ - ['- infixr 6 = code sub;'] ++ - ['* infixr 7 = code mul;'] ++ - ['/ infixr 7 = code div;'] ++ - ['&& infixl 3 = code and;'] ++ - ['|| infixl 2 = code or;'] ++ - ['ap = (1 +);'] ++ - ['ap = (+ 1);'] - ) zero -- 2.20.1