The library for making brainf*ck dialect 👍
- These are implemented by brainhack
- nico-lang
- detailed
- hs-kemono-friends
- easily
- nico-lang
- 1: Define your Text newtype for your brainf*ck tokens
newtype NicoToken = NicoToken { unNicoToken :: Text }
deriving (Eq, IsString)
- 2: Define
BrainfuckToken
instance
instance BrainfuckToken NicoToken where
forwardToken = "笑顔届ける矢澤にこにこ!"
backwordToken = "だめだめだめっ!"
incrToken = "にっこにっこにー"
decrToken = "にこにーって覚えてラブニコ!"
outputToken = "ぴょんぴょんぴょんっ!"
inputToken = "あなたのハートににこにこにー!"
loopBeginToken = "にこにーはみんなのもの!"
loopEndToken = "キモチワルイ"
toText = unNicoToken
fromText = NicoToken
toOperator = flip lookup [ ("笑顔届ける矢澤にこにこ!", ForwardOp)
, ("だめだめだめっ!", BackwardOp)
, ("にっこにっこにー", IncrOp)
, ("にこにーって覚えてラブニコ!", DecrOp)
, ("ぴょんぴょんぴょんっ!", OutputOp)
, ("あなたのハートににこにこにー!", InputOp)
, ("にこにーはみんなのもの!", LoopBeginOp)
, ("キモチワルイ", LoopEndOp)
]
- 3: Run
parse
andeval
main :: IO ()
main = do
nicoCode <- NicoToken . pack <$> readFile "hello.nico"
case parse nicoCode of
Left e -> error $ "Caught the error: " ++ show (e :: SomeException)
Right a -> do
void $ flip runBrainState emptyMachine $ eval a
--(mem, logs) <- fst . flip runBrainState emptyMachine $ eval a
--print mem
--mapM_ putStrLn logs