Browse Source

Implement emojifuck

Ian Adam Naval 2 years ago
parent
commit
fc08f05fea
3 changed files with 16 additions and 46 deletions
  1. 0
    33
      examples/helloworld.bf
  2. 1
    0
      examples/helloworld.ef
  3. 15
    13
      src/emojifuck.hs

+ 0
- 33
examples/helloworld.bf View File

@@ -1,33 +0,0 @@
1
-+++++ +++               Set Cell #0 to 8
2
-[
3
-    >++++               Add 4 to Cell #1; this will always set Cell #1 to 4
4
-    [                   as the cell will be cleared by the loop
5
-        >++             Add 4*2 to Cell #2
6
-        >+++            Add 4*3 to Cell #3
7
-        >+++            Add 4*3 to Cell #4
8
-        >+              Add 4 to Cell #5
9
-        <<<<-           Decrement the loop counter in Cell #1
10
-    ]                   Loop till Cell #1 is zero
11
-    >+                  Add 1 to Cell #2
12
-    >+                  Add 1 to Cell #3
13
-    >-                  Subtract 1 from Cell #4
14
-    >>+                 Add 1 to Cell #6
15
-    [<]                 Move back to the first zero cell you find; this will
16
-                        be Cell #1 which was cleared by the previous loop
17
-    <-                  Decrement the loop Counter in Cell #0
18
-]                       Loop till Cell #0 is zero
19
- 
20
-The result of this is:
21
-Cell No :   0   1   2   3   4   5   6
22
-Contents:   0   0  72 104  88  32   8
23
-Pointer :   ^
24
- 
25
->>.                     Cell #2 has value 72 which is 'H'
26
->---.                   Subtract 3 from Cell #3 to get 101 which is 'e'
27
-+++++ ++..+++.          Likewise for 'llo' from Cell #3
28
->>.                     Cell #5 is 32 for the space
29
-<-.                     Subtract 1 from Cell #4 for 87 to give a 'W'
30
-<.                      Cell #3 was set to 'o' from the end of 'Hello'
31
-+++.----- -.----- ---.  Cell #3 for 'rl' and 'd'
32
->>+.                    Add 1 to Cell #5 gives us an exclamation point
33
->++.                    And finally a newline from Cell #6

+ 1
- 0
examples/helloworld.ef View File

@@ -0,0 +1 @@
1
+๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐ŸŒ”๐Ÿ”œ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐ŸŒ”๐Ÿ”œ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ”œ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ”œ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ”œ๐Ÿ“ˆ๐Ÿ”™๐Ÿ”™๐Ÿ”™๐Ÿ”™๐Ÿ“‰๐ŸŒ–๐Ÿ”œ๐Ÿ“ˆ๐Ÿ”œ๐Ÿ“ˆ๐Ÿ”œ๐Ÿ“‰๐Ÿ”œ๐Ÿ”œ๐Ÿ“ˆ๐ŸŒ”๐Ÿ”™๐ŸŒ–๐Ÿ”™๐Ÿ“‰๐ŸŒ–๐Ÿ”œ๐Ÿ”œ๐Ÿ“ค๐Ÿ”œ๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“ค๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ค๐Ÿ“ค๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ค๐Ÿ”œ๐Ÿ”œ๐Ÿ“ค๐Ÿ”™๐Ÿ“‰๐Ÿ“ค๐Ÿ”™๐Ÿ“ค๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ค๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“ค๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“‰๐Ÿ“ค๐Ÿ”œ๐Ÿ”œ๐Ÿ“ˆ๐Ÿ“ค๐Ÿ”œ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ค

src/brainfuck.hs → src/emojifuck.hs View File

@@ -1,6 +1,5 @@
1
+-- Emojifuck interpreter in Haskell: beause why not
1 2
 -- author: ianonavy
2 3
 
3 4
 import Data.Maybe
4 5
 import Data.List
@@ -22,16 +21,17 @@ data BFSource = BFSource [BrainfuckCommand]
22 21
 
23 22
 instance Show BFSource where
24 23
     show (BFSource bfs) = map bfToChar bfs where
25
-        bfToChar GoRight      = '>'
26
-        bfToChar GoLeft       = '<'
27
-        bfToChar Increment    = '+'
28
-        bfToChar Decrement    = '-'
29
-        bfToChar Print        = '.'
30
-        bfToChar Read         = ','
31
-        bfToChar LoopL        = '['
32
-        bfToChar LoopR        = ']'
33
-        bfToChar (Comment c)  = c
34
-
24
+              bfToChar GoRight = '\128284'
25
+              bfToChar GoLeft = '\128281'
26
+              bfToChar Increment = '\128200'
27
+              bfToChar Decrement = '\128201'
28
+              bfToChar Print = '\128229'
29
+              bfToChar Read = '\128228'
30
+              bfToChar LoopL = '\127764'
31
+              bfToChar LoopR = '\127766'
32
+
33
+--         bfToChar (Comment c)  = c
34
+--
35 35
 data Tape a = Tape [a] -- Left of the pivot element
36 36
                     a  -- Pivot element
37 37
                    [a] -- Right of the pivot element
@@ -64,7 +64,7 @@ traceParens :: BFSource -> [Int]
64 64
 traceParens (BFSource bfs) = scanl accParens 0 bfs
65 65
 
66 66
 getMissingOpenError :: BFSource -> String
67
-getMissingOpenError (BFSource bfs) = 
67
+getMissingOpenError (BFSource bfs) =
68 68
     "Syntax Error:\n- Close parens without open paren: character " ++ index where
69 69
         index = (show . fromJust . findIndex (<0) $ scanl accParens 0 bfs)
70 70
 
@@ -89,7 +89,7 @@ parseBrainfuck = checkSyntax . BFSource . mapMaybe charToBF
89 89
             charToBF ']' = Just LoopR
90 90
             charToBF  c  = Just (Comment c)
91 91
 
92
-printBrainfuck :: Either String BFSource -> IO () 
92
+printBrainfuck :: Either String BFSource -> IO ()
93 93
 printBrainfuck (Left bfs)  = putStrLn bfs
94 94
 printBrainfuck (Right bfs) = putStrLn . show $ bfs
95 95
 
@@ -176,4 +176,4 @@ runFile filename = readFile filename >>= runBrainfuck . parseBrainfuck
176 176
 main = do
177 177
     args <- getArgs
178 178
     mapM runFile args
179
-  
179
+

Loadingโ€ฆ
Cancel
Save