brain-bleep (empty) → 0.1.0.1
raw patch · 6 files changed
+128/−0 lines, 6 filesdep +arraydep +basedep +containerssetup-changed
Dependencies added: array, base, containers, parsec
Files
- ChangeLog.md +5/−0
- LICENSE +30/−0
- Main.hs +62/−0
- README.md +1/−0
- Setup.hs +2/−0
- brain-bleep.cabal +28/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for brain-bleep++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017, Alan Hawkins++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Alan Hawkins nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Main.hs view
@@ -0,0 +1,62 @@+import Data.Array+import Text.ParserCombinators.Parsec+import System.IO.Unsafe+import Data.Tree+import Data.Maybe+import Control.Monad+import Data.Char+import System.IO++data BrainBleepOp = + Program + | Increment + | Decrement+ | ShiftLeft+ | ShiftRight+ | PutChar+ | GetChar+ | DoUntilZero+ deriving (Show,Read)+ ++main = do+ x <- getContents+ interpretBrainBleep x++opDefs = [('+',Increment)+ ,('-' , Decrement)+ ,(',' , GetChar)+ ,('.' , PutChar)+ ,('<' , ShiftLeft)+ ,('>' , ShiftRight)+ ]++ops = oneOf (map fst opDefs) >>= \x -> return $ Node (fromJust $ lookup x opDefs) []++doUntilZero = do+ char '['+ (Node Program x) <- myParser + char ']'+ return (Node DoUntilZero x) ++myParser = sepBy (many (try doUntilZero <|> try ops)) newline >>= return . Node Program . concat++exampleAst src = parse myParser "" (filter (/=' ') src)++initArray = listArray (0,30000-1) (replicate 30000 0)++interpretBrainBleep src = runAst' (0,initArray) ((\(Right x) -> x) (exampleAst src)) >> return ()++runAst' (cursor,array) l@(Node DoUntilZero xs) = + if (array!cursor == 0) then do+ return (cursor,array) + else do + s <- foldM runAst' (cursor,array) xs + runAst' s l+runAst' (cursor,array) (Node Program xs) = foldM runAst' (cursor,array) xs+runAst' (cursor,array) (Node Increment _) = do putStr "" >> return (cursor,array// [(cursor,array!cursor +1)])+runAst' (cursor,array) (Node Decrement _) = do putStr "" >> return (cursor,array// [(cursor,array!cursor -1)])+runAst' (cursor,array) (Node ShiftLeft _) = do putStr "" >> return (cursor-1,array)+runAst' (cursor,array) (Node ShiftRight _) = do putStr "" >> return (cursor+1,array)+runAst' (cursor,array) (Node GetChar _) = do getChar >>= \c -> return (cursor,array // [(cursor,ord c)])+runAst' (cursor,array) (Node PutChar _) = do putChar (chr$ array ! cursor) >> return (cursor,array)
+ README.md view
@@ -0,0 +1,1 @@+# brain-bleep
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ brain-bleep.cabal view
@@ -0,0 +1,28 @@+name: brain-bleep+version: 0.1.0.1+cabal-version: >=1.10+build-type: Simple+license: BSD3+synopsis: primitive imperative language+license-file: LICENSE+maintainer: hawk.alan@gmail.com+category: Language+author: Alan Hawkins+extra-source-files:+ ChangeLog.md+ README.md++source-repository head+ type: git+ location: http://github.com/xpika/brain-bleep.git++executable brain-bleep+ main-is: Main.hs+ build-depends:+ base >=4.9 && <4.10,+ array >=0.5 && <0.6,+ parsec >=3.1 && <3.2,+ containers >=0.5 && <0.6+ default-language: Haskell2010++