| FunExpr Pos String [Expr] [FieldSelector]
| EmptyListExpr Pos
| TupleExpr Pos (Expr, Expr)
+ | LambdaExpr Pos [String] Expr
:: VarDef = VarDef String [FieldSelector]
:: FieldSelector = FieldHd | FieldTl | FieldFst | FieldSnd
:: Op1 = UnNegation | UnMinus
print (FunExpr _ id as fs) = printFunCall id as fs
print (EmptyListExpr _) = ["[]"]
print (TupleExpr _ (e1, e2)) = ["(":print e1] ++ [",":print e2] ++ [")"]
+ print (LambdaExpr _ args e) = ["\\":args] ++ ["->": print e]
instance toString Expr where
toString e = concat $ print e
[Int] x = [];
[Int] y = [];
Int z = a();
+ var f = \x -> x+1;
x = mapP1(x);
y = mapP1(x);
return a() + 5;
[Instr "ldc" [Lit fn] ""
,Instr "ldc" [Lit 0] ""
,Instr "stmh" [Lit 2] ""]
+ g (LambdaExpr _ _ _) = liftT $ Left $ Error "PANIC: Lambdas should be transformed"
g (FunExpr _ k es fs) = getAdressbook >>= \ab->case 'Map'.get k ab of
//Identifier points to function
Just (LAB l arity fn) = if (arity <> (length es))
| 'return' [<Expr>] ';'
<VarDecl> ::= <Type> <id> '=' <Expr> ';'
<Expr> ::= <BinOrExpr> [':' <Expr>]
+ | <LambdaExpr>
<BinOrExpr> ::= <BinAndExpr> ['||' <BinOrExpr>]
<BinAndExpr> ::= <CompareExpr> ['&&' <BinAndExpr>]
<CompareExpr> ::= <PlusMinExpr> [('==' | '<' | '>' | '<=' | '>=' | '!=') <CompareExpr>]
| '[]' <Expr>
| '(' <Expr> ',' <Expr> ')'
| '"' <char> '"'
+<LamdaExpr> ::= '\'<id>+ '->' <Expr>
<FieldSels> ::= ('.' ('hd'|'tl'|'fst'|'snd))*
<FunCall> ::= <id> ['(' <ActArgs>+ ')']
<ActArgs> ::= <Expr> [',' ActArgs]
| LesserToken // <
| BiggerToken // >
| ExclamationToken // !
+ | BackslashToken // \
:: LexerOutput :== Either Error [Token]
lexWord "/" SlashToken <|> lexWord "%" PercentToken <|>
lexWord "=" AssignmentToken <|> lexWord "<" LesserToken <|>
lexWord ">" BiggerToken <|> lexWord "!" ExclamationToken <|>
- lexWord "-" DashToken <|>
+ lexWord "-" DashToken <|> lexWord "\\" BackslashToken <|>
//Number and identifier tokens
lexString <|> lexNumber <|> lexIdentifier <|>
(item '\n' >>| pure LexNL) <|>
(IdType <$> parseIdent)
parseExpr :: Parser Token Expr
-parseExpr = //Operators in order of binding strength
+parseExpr = parseValueExpr <|> parseLambda
+parseValueExpr :: Parser Token Expr
+parseValueExpr = //Operators in order of binding strength
parseOpR (trans1 ColonToken BiCons) $
parseOpR (trans1 PipesToken BiOr) $
parseOpR (trans1 AmpersandsToken BiAnd) $
pure $ FunExpr pos ident args fs) <|>
(VarExpr pos <$> parseVarDef)
+parseLambda :: Parser Token Expr
+parseLambda = LambdaExpr <$> peekPos
+ <*> (satTok BackslashToken *> some parseIdent)
+ <*> (satTok ArrowToken *> parseExpr)
+
makeStrExpr :: Pos [Char] -> Expr
makeStrExpr p [] = EmptyListExpr p
makeStrExpr p [x:xs] = Op2Expr p (CharExpr zero x) BiCons (makeStrExpr p xs)
infer e2 >>= \(s2, t2, e2_) ->
pure (compose s2 s1, TupleType (t1,t2), TupleExpr p (e1_,e2_))
+ LambdaExpr _ _ _ = liftT $ Left $ Error "PANIC: lambdas should be tasnformed"
+
FunExpr p f args fs =
lookup f >>= \expected ->
let accST = (\(s,ts,es) e->infer e >>= \(s_,et,e_)-> pure (compose s_ s,ts++[et],es++[e_])) in