Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #30045
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Brainfuck in ANS Forth |
| Date | 2014-05-01 16:08 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <op.xe6578fr6zenlw@localhost> (permalink) |
| References | <d02323e7-cce2-4495-9c11-401d248d8128@googlegroups.com> |
On Thu, 01 May 2014 11:31:38 -0400, Mark Wills <markwills1970@gmail.com> wrote: > Just for fun... > >> Increment the pointer. > < Decrement the pointer. > + Increment the byte at the pointer. > - Decrement the byte at the pointer. > . Output the byte at the pointer. > , Input a byte and store it in the byte at the pointer. > [ Jump forward past the matching ] if the byte at the pointer is zero. > ] Jump backward to the matching [ unless the byte at the pointer is > zero. > > > > create array > 8000 chars allot The array is usually 32KB. > variable pointer > array pointer ! > > : reset ( -- ) > \ zero bf memory and reset pointer > array 8000 0 fill > array pointer ! ; 0 fill. Good. Officially, BF doesn't need that. But, I found that some BF programs wont' work without it, and all seem to work with it. > : peek ( -- ) > pointer @ c@ ; > : poke ( -- ) > pointer @ c! ; ... > : > ( -- ) > \ increment the pointer > pointer @ 1+ pointer ! ; How common is +! ? It seems I picked it up from fig-Forth and one critical word needs it. > : < ( -- ) > \ decrement the pointer > pointer @ 1- pointer ! ; > ... > : + ( -- ) > \ increment the byte at the pointer > peek 1+ poke ; > : - ( -- ) > \ decrement the byte at the pointer > peek 1- poke ; If you're using peek and poke, why not words for 'pointer @' and 'pointer !' ... > : . ( -- ) > \ output the byte at the pointer > peek . ; . or EMIT ? Shouldn't it be EMIT ? It's a value for a character. > : , ( -- ) > \ input a byte and store it in the byte at the pointer > pad 3 expect pad 3 number drop poke ; Um, did ANS Forth remove KEY ? > : [ \ ( -- ) > \ jump forward past the matching ] if the byte at the pointer is zero > [compile] begin compile peek [compile] while ; immediate > : ] ( -- ) > \ jump backward to the matching [ unless the byte at the pointer is > zero > [compile] repeat ; immediate ... > : hw > + + + + + + + + [ > + + + + [ > + + > + + + > + + + > + < < < < - ] > > + > > + > - > > + [ < ] < - ] > > . > - - - . + + + + + + + . . + + + . > > > > . < - . < . + + + . - - - - - - . - - - - - - - - . > > + . > + + . ; > Ha! Each one has a space after them for Forth space parsing. And, it's a colon-def. Awkward. > Test: > > hw > 72 101 108 108 111 32 87 111 114 108 100 33 10 > > Note: BrainFuck can't emit characters, only numbers. So the Hello World! > example above (taken from WikiPedia) outputs the ASCII *values* of Hello > World! complete with a carriage return. > > http://en.wikipedia.org/wiki/Brainfuck No. You've misunderstood something. It's supposed to emit ASCII text "Hello World!" with linefeed (ASCII LF 0x0A). The . in BF emits the ASCII character for the value. If you look at the C equivalent for . and , on the Wikipedia page, they use getchar() and putchar() in C which fetches a char and emits a char, respectively. Rod Pemberton
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Brainfuck in ANS Forth Mark Wills <markwills1970@gmail.com> - 2014-05-01 08:31 -0700
Re: Brainfuck in ANS Forth "Alex McDonald" <blog@rivadpm.com> - 2014-05-01 18:54 +0100
Re: Brainfuck in ANS Forth Mark Wills <markwills1970@gmail.com> - 2014-05-01 15:20 -0700
Re: Brainfuck in ANS Forth "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-01 16:08 -0400
Re: Brainfuck in ANS Forth Mark Wills <markwills1970@gmail.com> - 2014-05-01 15:22 -0700
Re: Brainfuck in ANS Forth "Elizabeth D. Rather" <erather@forth.com> - 2014-05-01 12:31 -1000
Re: Brainfuck in ANS Forth Mark Wills <markwills1970@gmail.com> - 2014-05-02 01:09 -0700
Re: Brainfuck in ANS Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2014-05-02 14:18 +0200
Re: Brainfuck in ANS Forth Mark Wills <markwills1970@gmail.com> - 2014-05-02 09:06 -0700
Re: Brainfuck in ANS Forth Mark Wills <markwills1970@gmail.com> - 2014-05-02 15:04 -0700
Re: Brainfuck in ANS Forth "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-02 22:37 -0400
Re: Brainfuck in ANS Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2014-05-03 12:02 +0200
Re: Brainfuck in ANS Forth "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-03 09:21 -0400
Re: Brainfuck in ANS Forth Mark Wills <markwills1970@gmail.com> - 2014-05-06 08:14 -0700
Re: Brainfuck in ANS Forth "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-06 16:53 -0400
Re: Brainfuck in ANS Forth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-05-22 22:13 +0100
Re: Brainfuck in ANS Forth Coos Haak <chforth@hccnet.nl> - 2014-05-23 15:27 +0200
Re: Brainfuck in ANS Forth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-05-26 21:38 +0100
Re: Brainfuck in ANS Forth Assad Ebrahim <assad.ebrahim@alum.swarthmore.edu> - 2014-05-03 22:59 +0100
Re: Brainfuck in ANS Forth all2001@spambog.com (Wolfgang Allinger) - 2014-05-03 19:39 -0400
Re: Brainfuck in ANS Forth Ian Osgood <iano@quirkster.com> - 2014-06-16 15:35 -0700
csiph-web