Partner sites: Aminet - Amiga downloadsIntuitionBase - Amiga guidesAmigaNN - Amiga newsAmiFund - Sponsor projects

[Y]UtilityBase
Your guide to Amiga development
Not logged in
  HomeProjectsForumArticlesResourcesLinksChatAbout 
Search
Login
Username:
Password:
Register now!
Forgot your password?
Aminet - Development
Blitz_AVI.lha (dev/basic)
bullet.lha (dev/lib)
MCC_TheBar-26.6.lha (dev/mui)
MCC_TextEditor-15.35.lha (dev/mui)
MCC_BetterString-11.19.lha (dev/mui)
fw_c2p_p2c.lha (dev/lib)
plib_examples.lha (dev/src)
plib.lha (dev/lib)
MCC_NList-0.107.lha (dev/mui)
MCC_NList-0.106.lha (dev/mui)
More...
Newest users
prowler
apache64 (Chris)
cpeel2300 (Chris)
Branquito
chris (Chris Young)

Pending:
ZebraZeem, Mad_Dog, hhjoker, voxel, JosDuchIt, MarcB, MarBo, Sollaris, sara, species
More...
Who's Online
Online members:


12 guests are online.

You are an Anonymous user. You can register for free by clicking here.
News sites
Amiga-News.de
Amiga.org
AmigaNN
Amigans.net
Amigaweb.net
AmigaWorld.net
AROS-Exec
MorphOS-News.de
MorphZone
polarBoing
Tutorials
Change Graphics cards in AmigaOS 4.
Installing the latest OS4 SDK in Cubic IDE
Writing Installer scripts for AmiUpdate
Cross Compiling for OS4 or OS3 using MS Visual Studio 2005
Installing an AmigaOS 4 cross compiler
More...
Sources
How to open and use the exec debug interface
How to install a hardware interrupt
Install SObjs with Installer
How to make clean picture datatypes
Most of the old ClassACT examples converted to OS4
More...
Documentations
How to write portable code for Amiga (english)
Comment écrire du code portable pour Amiga (français)
Development How to with OS3.9 SDK
The PartyPack Hack
The Amiga PDA Programming Guidelines
More...
DreamHost

Support
UtilityBase

[Valid RSS]

UtilityBase needs your help!

Description:Brainfuck interpreter
Language:haskell
Nickname:xrymbos
Page URL:http://utilitybase.com/paste/emi
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
module Main where

import qualified Control.Exception as CE
import Data.Char
import Data.Word
import System.Environment
import System.IO
import Text.ParserCombinators.Parsec
import Debug.Trace

type Program = [Operator]
data Operator = Add
| Minus
| Next
| Previous
| Loop Program
| Input
| Output

type Index  = Int
type Memory = [Int]
data ProgramState  = ProgramState Memory Index deriving Show

--transform :: IO ProgramState->ProgramState
--transform (ProgramState mem ind) = (ProgramState mem ind)

johnSmith :: Program
johnSmith  = [Input, Next, Input, Loop [Minus, Previous, Add, Next], Previous, Output]

exec :: Program->ProgramState->IO ProgramState
--exec p st = foldM run p st
exec [] st = return st
exec (x:xs) st = do
newSt <- run x st
exec xs newSt

run  :: Operator->ProgramState->IO ProgramState
run op st=
case op of
Add       -> return $! myAdd st
Minus     -> return $! minus st
Next      -> return $! next st
Previous  -> return $! prev st
Loop p    -> loop p st
Input     -> getIn st
Output    -> printOut st

myAdd     :: ProgramState->ProgramState
addHelper :: Int->Int->Memory->Memory
myAdd (ProgramState mem ind) = (ProgramState (addHelper 0 ind mem) ind)
addHelper n ind (x:xs)| n==ind  = [x+1] ++ xs
| n/=ind  = [x]   ++ (addHelper (n+1) ind xs)
addHelper n ind []    | n==ind  = [1]
| n/=ind  = [0]   ++ (addHelper (n+1) ind [])

minus       :: ProgramState->ProgramState
minusHelper :: Int->Int->Memory->Memory
minus (ProgramState mem ind)   = (ProgramState (minusHelper 0 ind mem) ind)
minusHelper n ind (x:xs)| n==ind  = [x-1] ++ xs
| n/=ind  = [x]   ++ (minusHelper (n+1) ind xs)
minusHelper n ind []    | n==ind  = [-1]
| n/=ind  = [0]   ++ (minusHelper (n+1) ind [])

next :: ProgramState->ProgramState
next (ProgramState mem ind) = (ProgramState mem (ind+1))

prev :: ProgramState->ProgramState
prev (ProgramState mem 0)   = error "Pointer fell off back of data"
prev (ProgramState mem ind) = (ProgramState mem (ind-1))

loop :: Program->ProgramState->IO ProgramState
loop p st=
if isZero st
then return st
else do
newSt <- exec p st
loop p newSt

isZero     :: ProgramState->Bool
zeroHelper :: Int->Int->Memory->Bool
isZero (ProgramState mem ind) = zeroHelper 0 ind mem
zeroHelper n ind []    = True
zeroHelper n ind (x:xs)| n==ind = testInt x
| n/=ind = zeroHelper (n+1) ind xs
testInt :: Int->Bool
testInt 0  = True
testInt n  = False

myMem   = [0]
myInd   = 0
myProgramState = (ProgramState myMem myInd)

getIn    :: ProgramState->IO ProgramState
inHelper :: Int->Int->Memory->Int->Memory
getIn (ProgramState mem ind) = do line <- getLine
return (ProgramState (inHelper 0 ind mem (read line :: Int)) ind)
inHelper n ind (x:xs) s| n==ind  = [s] ++ xs
| n/=ind  = [x] ++ (inHelper (n+1) ind xs s)
inHelper n ind []     s| n==ind  = [s]
| n/=ind  = [0] ++ (inHelper (n+1) ind [] s)

printOut  :: ProgramState->IO ProgramState
outHelper :: Int->Int->Memory->IO Memory
printOut (ProgramState mem ind) = do outHelper 0 ind mem
return (ProgramState mem ind)

outHelper n ind (x:xs)| n==ind  = do print x
return ([x] ++ xs)
| n/=ind  = do rest <- outHelper (n+1) ind xs
return ([x] ++ rest)
outHelper n ind []              = do print 0
return []



pParser :: Parser Program
pParser = many iParser

iParser :: Parser Operator
iParser = simple <|> lParser

lParser :: Parser Operator
lParser = between (char '[') (char ']') pParser >>= p -> return $ Loop p

simple :: Parser Operator
simple =     ((char '+') >>= _ -> return $ Add )
<|> ((char '-') >>= _ -> return $ Minus)
<|> ((char '>') >>= _ -> return $ Next)
<|> ((char '<') >>= _ -> return $ Previous)
<|> ((char '.') >>= _ -> return $ Output)
<|> ((char ',') >>= _ -> return $ Input)

main = do args <- getArgs
if length args < 1
then fail "Please provide name of the program to run"
else do prog <- readFile (head args)
case (parse pParser "" . normalize) prog of
Left err    -> do putStr "Parse error at "
print err
Right res   -> do exec res (ProgramState [0] 0)
return ()
normalize :: String -> String
normalize program = filter (`elem` "+-<>[].,") program


Latest pastes
idc3 (text) by anonymous 18 hours ago
<div style="border:1px solid; border-color:#000000; color:#FFFFFF; width:315px; height:220px; ove...
idc3 (text) by anonymous 19 hours ago
<div style="border:1px solid; border-color:#000000; color:#FFFFFF; width:345px; height:350px; ove...
idc2 (text) by anonymous 19 hours ago
<div style="border:1px solid; border-color:#000000; color:#FFFFFF; width:210px; height:245px; ove...
Byakuya (text) by byk 1 day ago
&#26429;&#26408; &#30333;&#21705;
Executionery (text) by anonymous 3 days ago
<div style="border:1px solid; border-color:#000000; color:#000000; width:300px; height:305px; ove...
ironver (text) by sdfsdf 4 days ago
Global $Attempts = 0 Global $Plus = 0 Global $Elixirs = 0 Global $1 = 0 Global $2 = 0 Glob...
new (text) by fdfsdf 4 days ago
#include <Date.au3> Global $Attempts, $Plus, $Elixirs Global $aArray[20], $aCLabel[10][2] Glob...
xFauxxi (text) by anonymous 4 days ago
<div style="border:1px solid; border-color:#000000; color:#000000; width:905px; height:40px; over...
idc (text) by anonymous 6 days ago
<div style="border:1px solid; border-color:#000000; color:#FFFFFF; width:460px; height:70px; over...
testest (text) by lalanuss 7 days ago
;MacrosIncludesUDF FunctionsProcessSetPriority(@AutoItExe, 4) Global $Attempts = 0 Global $Plus...
No description (text) by anonymous 1 week ago
<div style="border:3px solid; border-color:#000000; color:#6600CC; width:120px; height:260px; ove...
luckyday (text) by anonymous 1 week ago
Global $Attempts = 0 Global $Plus = 0 Global $Elixirs = 0 Global $1 = 0 Global $2 = 0 Global...
cool function (text) by master 1 week ago
void large_cock(void) { uint32 inches; uint32 thick; thick = inches; }
No description (text) by anonymous 1 week ago
<div style="border:1px solid; border-color:#000000; color:#000000; width:955px; height:40px; over...
No description (text) by anonymous 1 week ago
<div style="border:1px solid; border-color:#000000; color:#000000; width:955px; height:40px; over...
No description (text) by anonymous 1 week ago
<div style="border:1px solid; border-color:#0000CC; color:#0000CC; width:300px; height:405px; ove...
No description (text) by anonymous 1 week ago
<div style="border:1px solid; border-color:#FFCCFF; color:#000000; width:905px; height:40px; over...
No description (text) by anonymous 1 week ago
<div style="border:1px solid; border-color:#660033; color:#660033; width:300px; height:405px; ove...
aa (text) by aa 1 week ago
kparkhurst@grainvalley.k12.mo.us ivplay02@yahoo.ca dlaing1972@gmail.com passion_wheels@yahoo...
aa (text) by aa 1 week ago
MASA@drake.edu.desmoines.iowa.usa.earth UpMASA@drake.edu.desmoines.iowa.usa.earth bsoderlind@us...
No description (text) by anonymous 1 week ago
</style><style type="text/css"> #URL_panel_header,.imvucodes_net { display:none; } </style><sty...
CODES (text) by anonymous 1 week ago
<style type="text/css"> /* by xxxalex15malexxx published on http://imvu.at/ic294 under CC-Share-...
No description (text) by anonymous 1 week ago
<div style="border:1px solid; border-color:#0000CC; color:#0000CC; width:120px; height:305px; ove...
No description (text) by anonymous 1 week ago
<div style="border:1px solid; border-color:#0000CC; color:#0000CC; width:120px; height:305px; ove...
No description (text) by anonymous 1 week ago
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true); pDevice->SetRenderState(D3DRS_DESTBLEND,D3...
Christian Heinrich 0day Vista Exploit (text) by cmlh 2 weeks ago
/* Windows 7 and Vista Backup Utility sdclt.exe fveapi.dll DLL Hijacking Exploit Found by:...
0day Daemon Tools Lite exploit by Christian Heinrich (cmlh) (text) by cmlh 2 weeks ago
/* Daemon Tools Lite <= 4.35.6.0091 mfc80loc.dll DLL Hijacking Exploit Found by: Christian...
iToxiicCrayons (text) by anonymous 2 weeks ago
<div style="border:1px solid; border-color:#000000; color:#FFFFFF; width:195px; height:155px; ove...
No description (text) by anonymous 2 weeks ago
case 59: { vector<DataObj*> * li; vector<ObjSearch * > input; Ricerca *r=req...
hudi (c) by zine 2 weeks ago
// Room: /clone/misc/hudi.c // Date: by jason(&#23572;&#22909;&#21834;) Tue Nov 17 15:40:17 2009...
No description (acl) by anonymous 2 weeks ago
asdgdfh jfhvgf
Instalando o IndyTiburon ( Windows 7 - Delphi 2010 Version 14.0.3615.26342 ) (delphi) by Thiago Pedro 2 weeks ago
Instalando o IndyTiburon ( Windows 7 - Delphi 2010 Version 14.0.3615.26342 ) conceda permissão...
No description (python) by anonymous 2 weeks ago
student_infos = [StudentInfo("female", 13), StudentInfo("male", 13)] result_...
No description (python) by anonymous 2 weeks ago
class StudentInfo(object): def __init__(self, sex, age): self.sex = sex self.age = a...
No description (csharp) by anonymous 2 weeks ago
void updateRequestTimer_Tick(object sender, EventArgs e) { if (AppData.app.allow_updat...
No description (csharp) by anonymous 2 weeks ago
void updateRequestTimer_Tick(object sender, EventArgs e) { if (AppData.app.allow_updat...
AwSNAP (text) by anonymous 2 weeks ago
<div style="border:1px solid; border-color:#000000; color:#000000; width:200px; height:360px; ove...
No description (text) by anonymous 2 weeks ago
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++...
No description (java122) by anonymous 2 weeks ago
import java.text.DecimalFormat; import java.text.NumberFormat; import org.apache.commons.lang...
Assinatura Eurogamer (html) by DiogoC. 3 weeks ago
<center><a href="http://www.eurogamer.pt/forum_thread_posts.php?thread_id=191530&start=0" title="...
Dent@IMVU (text) by code134 3 weeks ago
<div style="border:1px solid; border-color:#FFFFFF; color:#FFFFFF; width:500px; height:200px; ove...
big integer (fortran90) by terryys 3 weeks ago
program bigNumber implicit none integer, dimension(40000) :: numberArray integer :...
No description (c) by anonymous 3 weeks ago
/* * File: main.c * Author: moises * * Created on 17 de Agosto de 2010, 22:07 */ ...
No description (c) by anonymous 3 weeks ago
/* * File: main.c * Author: moises * * Created on 17 de Agosto de 2010, 22:07 */ ...
No description (text) by anonymous 3 weeks ago
http://codepad.org/S9uwlO7g
No description (text) by anonymous 3 weeks ago
<div style="border:1px solid; border-color:#FFFFFF; color:#FFFFFF; width:200px; height:350px; ove...
No description (text) by anonymous 3 weeks ago
<div style="border:0px solid; border-color:#FFFFFF; color:#FFFFFF; width:200px; height:350px; ove...
No description (text) by anonymous 3 weeks ago
<div style="border:0px solid; border-color:#FFFFFF; color:#FFFFFF; width:250px; height:400px; ove...
No description (cpp) by anonymous 3 weeks ago
bool QKeymapItemEdit::event( QEvent *evt ) { // Consume all keypress events if ( (evt->t...
No description (pascal) by anonymous 3 weeks ago
program spoj_1; var x:longint; begin readln(x); while x<>42 do begin writeln(x)...

UtilityBase is a site focused on development for Amiga systems,
spanning over all different Amiga clones, that be AmigaOS 3.x, 4.x, MorphOS, AROS or AmigaDE/Anywhere.
News syndication: RSS
Contact address: mail@utilitybase com