From: Mart Lubbers Date: Sun, 29 May 2016 19:09:17 +0000 (+0200) Subject: printen en parsen voor de demo X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=25712a3b8efd62feba2c64ff6a8b48f78f64e3d1;p=cc1516.git printen en parsen voor de demo --- diff --git a/examples/parsing.spl b/examples/printparse.spl similarity index 62% rename from examples/parsing.spl rename to examples/printparse.spl index 96160bd..06b4f1f 100644 --- a/examples/parsing.spl +++ b/examples/printparse.spl @@ -12,6 +12,20 @@ toInt(x) :: Char -> Int{ } else { return -1; }}}}}}}}}} } +toChar(x) :: Int -> Char{ + if(x == 0){ return '0'; + } else { if(x == 1){ return '1'; + } else { if(x == 2){ return '2'; + } else { if(x == 3){ return '3'; + } else { if(x == 4){ return '4'; + } else { if(x == 5){ return '5'; + } else { if(x == 6){ return '6'; + } else { if(x == 7){ return '7'; + } else { if(x == 8){ return '8'; + } else { if(x == 9){ return '9'; + } else { return '0'; }}}}}}}}}} +} + isDigit(x) :: Char -> Bool { return toInt(x) != -1; } @@ -48,8 +62,17 @@ printList(p, l) { print("]\n"); } +printInt(x) { + [Char] l = []; + while(x > 0){ + l = toChar(x % 10) : l; + x = x / 10; + } + print(l); +} + main(){ var num = "-1234"; - printList(print, 1 : 2 : []); + printList(printInt, 32 : 4 : []); } diff --git a/gen.icl b/gen.icl index e9d6cac..eba5a1d 100644 --- a/gen.icl +++ b/gen.icl @@ -178,6 +178,7 @@ instance g Expr where ,Instr "ldc" [Lit 0] "" ,Instr "sth" [] "" ,Instr "ajs" [Lit -1] ""] + Nothing = liftT $ Left $ Error "PANIC: unresolver variable expr" g (LambdaExpr _ _ _) = liftT $ Left $ Error "PANIC: Lambdas should be unfolded" g (FunExpr _ k es fs) = funnyStuff k es fs