From: Mart Lubbers Date: Thu, 3 Mar 2016 13:40:39 +0000 (+0100) Subject: ding X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=6703509b4b132cee0f4c91dc23795d3d4ab131e8;p=cc1516.git ding --- diff --git a/Makefile b/Makefile index 6b53e08..593d5d0 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,9 @@ CPM:=cpm .PHONY: man -all: spl spl.1 +all: spl + +man: spl.1 spl: spl.icl lex.icl lex.dcl parse.icl parse.dcl spl.prj $(CPM) make diff --git a/README.md b/README.md index dc15e87..2747d59 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Append `envs/envs.mac` to your `IDEEnvs` and run `make`. Install a real operating system and try again. ## Usage +If `help2man` is installed you can generate a manpage by running `make man`. For full instruction see `man ./spl.1` or run `./spl --help`. ## `LICENCE` diff --git a/parse.icl b/parse.icl index acd7d9c..120935f 100644 --- a/parse.icl +++ b/parse.icl @@ -5,7 +5,6 @@ import StdTuple import StdList from StdFunc import const, o import Data.Either -import Data.Functor import Data.Maybe import Control.Monad import Control.Applicative @@ -22,7 +21,7 @@ parser (Left e) = Left e parser (Right r) = fst $ runParser parseProgram r parseProgram :: Parser Token AST -parseProgram = liftM2 AST (many parseVarDecl) (some parseFunDecl) +parseProgram = liftM2 AST (many parseVarDecl) (some parseFunDecl) parseFunDecl :: Parser Token FunDecl parseFunDecl = liftM5 FunDecl @@ -45,19 +44,18 @@ parseStmt = parseIfStmt <|> parseWhileStmt <|> satTok ReturnToken *> liftM ReturnStmt (optional parseExpr) parseAssStmt :: Parser Token Stmt - parseAssStmt = + parseAssStmt = liftM2 AssStmt (parseVarDef <* satTok AssignmentToken) parseExpr parseIfStmt :: Parser Token Stmt parseIfStmt = liftM3 IfStmt (satTok IfToken *> parseBBraces parseExpr) (parseBlock <|> parseOneLine) - (liftM (fromMaybe []) + (liftM (fromMaybe []) (optional (satTok ElseToken *> (parseBlock<|> parseOneLine)))) - parseWhileStmt :: Parser Token Stmt - parseWhileStmt = satTok WhileToken *> + parseWhileStmt = satTok WhileToken *> liftM2 WhileStmt (parseBBraces parseExpr) parseBlock parseBlock :: Parser Token [Stmt] @@ -68,15 +66,15 @@ parseStmt = parseIfStmt <|> parseWhileStmt <|> parseOneLine = liftM pure parseStmt parseFunType :: Parser Token FunType -parseFunType = satTok DoubleColonToken *> +parseFunType = satTok DoubleColonToken *> (parseInOutType <|> (liftM (FunType []) parseVoidOrType)) where parseInOutType :: Parser Token FunType - parseInOutType = liftM2 FunType + parseInOutType = liftM2 FunType (some parseType <* satTok ArrowToken) parseVoidOrType parseVoidOrType :: Parser Token (Maybe Type) - parseVoidOrType = (satTok VoidToken *> pure Nothing) <|> + parseVoidOrType = (satTok VoidToken *> pure Nothing) <|> (liftM Just parseType) <|> pure Nothing parseVarDecl :: Parser Token VarDecl @@ -86,7 +84,7 @@ parseVarDecl = liftM3 VarDecl (parseExpr <* satTok SColonToken) parseType :: Parser Token Type -parseType = +parseType = trans1 IntTypeToken IntType <|> trans1 CharTypeToken CharType <|> trans1 BoolTypeToken BoolType <|> @@ -122,7 +120,7 @@ parseExpr = //Operators in order of binding strength ) >>= \moe->foldM (\e->(\(op,e2)->pure $ Op2Expr e op e2)) e1 moe parseBasicExpr :: Parser Token Expr - parseBasicExpr = + parseBasicExpr = (liftM TupleExpr (parseTuple parseExpr)) <|> (liftM FunExpr parseFunCall) <|> parseBBraces parseExpr <|> @@ -140,7 +138,7 @@ parseFunCall = liftM2 FunCall parseVarDef :: Parser Token VarDef parseVarDef = liftM2 VarDef - parseIdent + parseIdent (many (satTok DotToken *> ( (parseIdent >>= (\i.if (i == "hd") (pure FieldHd) empty)) <|> (parseIdent >>= \i.if (i == "tl") (pure FieldTl) empty) <|> @@ -160,8 +158,8 @@ parseBSqBraces :: (Parser Token a) -> Parser Token a parseBSqBraces p = satTok SquareOpenToken *> p <* satTok SquareCloseToken parseTuple :: (Parser Token a) -> Parser Token (a, a) -parseTuple p = satTok BraceOpenToken *> - (liftM2 (\a->(\b->(a,b))) (p <* satTok CommaToken) p) +parseTuple p = satTok BraceOpenToken *> + (liftM2 (\a->(\b->(a,b))) (p <* satTok CommaToken) p) <* satTok BraceCloseToken trans2 :: TokenValue (TokenValue -> a) -> Parser Token a @@ -173,8 +171,9 @@ trans1 t r = trans2 t $ const r derive gPrint TokenValue derive gEq TokenValue satTok :: TokenValue -> Parser Token Token -satTok t = top >>= \tok=:{line,column,token} -> if (eq t token) - (return tok) (fail PositionalError line column ("ParseError: Unexpected token: " +++ printToString token)) +satTok t = top >>= \tok=:{line,column,token} -> if (eq t token) + (pure tok) (fail PositionalError line column + ("ParseError: Unexpected token: " +++ printToString token)) where eq (IdentToken _) (IdentToken _) = True eq (NumberToken _) (NumberToken _) = True @@ -182,7 +181,7 @@ satTok t = top >>= \tok=:{line,column,token} -> if (eq t token) eq x y = gEq {|*|} x y parseSepList :: TokenValue (Parser Token a) -> Parser Token [a] -parseSepList sep p = +parseSepList sep p = (liftM2 (\es->(\e->reverse [e:es])) (some (p <* satTok sep)) p) <|> (liftM pure p) <|> pure empty @@ -210,9 +209,9 @@ printStatements :: [Stmt] Int -> [String] printStatements [] i = [] printStatements [s:ss] i = (case s of (IfStmt b thens elses) = indent i ["if (":print b] ++ [")"] ++ - printCodeBlock thens i ++ + printCodeBlock thens i ++ indent i ["else ":printCodeBlock elses i] ++ ["\n"] - (WhileStmt b dos) = indent i ["while (":print b] ++ + (WhileStmt b dos) = indent i ["while (":print b] ++ [")":printCodeBlock dos i] (AssStmt vardef val) = indent i $ print vardef ++ ["=":print val] ++ [";\n"] @@ -248,7 +247,7 @@ instance print Type where instance print String where print s = [s] -instance print FieldSelector where +instance print FieldSelector where print FieldHd = print "hd" print FieldTl = print "tl" print FieldSnd = print "snd" diff --git a/spl.prj b/spl.prj index 2847826..da6268b 100644 --- a/spl.prj +++ b/spl.prj @@ -604,7 +604,7 @@ OtherModules Fusion: False Module Name: System.OS - Dir: {Application}/lib/clean-platform/OS-Mac + Dir: {Application}/lib/clean-platform/OS-Linux-64 Compiler NeverMemoryProfile: False NeverTimeProfile: False