Hello. I've been looking at languages to run under Parrot, and I choose a certain language which is turing complete in eight instructions. Start with the small ones eh? Unfortunately its name is not family friendly. An interpreter is attached, although you'll need to add the chr() operator (see the patch). A BF compiler would be neat too, of course.
Any chance of this going in the languages directory if I provide more docs and examples? Leon ps yes, interpreters for "real" languages on the way -- Leon Brocard.............................http://www.astray.com/ Nanoware...............................http://www.nanoware.org/ .... (((((This tagline in Stereo where available)))))
# A Brainfuck interpreter # By Leon Brocard <[EMAIL PROTECTED]> # # See http://www.catseye.mb.ca/esoteric/bf/ # for more information on this silly language # Get the brainfuck source file into S0 get_keyed S0, P0, 1 if S0, SOURCE get_keyed S0, P0, 0 print "usage: ./parrot " print S0 print " file.bf\n" # Read the file into S1 SOURCE: open I0, S0 SOURCE_LOOP: readline S2, I0 concat S1, S2 if S2, SOURCE_LOOP close I0 length I30, S1 # Initialise set I0, 0 # Our PC new P0, PerlArray # Our memory set I1, 0 # Our pointer # The main interpreter loop INTERP: substr S0, S1, I0, 1 ne S0, "+", NOTPLUS get_keyed I2, P0, I1 inc I2 set_keyed P0, I1, I2 goto NEXT NOTPLUS: ne S0, "-", NOTMINUS get_keyed I2, P0, I1 dec I2 set_keyed P0, I1, I2 goto NEXT NOTMINUS: ne S0, ">", NOTGT inc I1 goto NEXT NOTGT: ne S0, "<", NOTLT dec I1 goto NEXT NOTLT: ne S0, "[", NOTOPEN get_keyed I2, P0, I1 if I2, NEXT set I2, 0 # "depth" OPEN_LOOP: inc I0 substr S2, S1, I0, 1 ne S2, "[", OPEN_NOTOPEN inc I2 goto OPEN_LOOP OPEN_NOTOPEN: ne S2, "]", OPEN_LOOP eq I2, 0, NEXT dec I2 goto OPEN_LOOP NOTOPEN: ne S0, "]", NOTCLOSE set I2, 0 # "height" CLOSE_LOOP: dec I0 substr S2, S1, I0, 1 ne S2, "]", CLOSE_NOTCLOSE inc I2 goto CLOSE_LOOP CLOSE_NOTCLOSE: ne S2, "[", CLOSE_LOOP eq I2, 0, INTERP dec I2 goto CLOSE_LOOP NOTCLOSE: ne S0, ".", NOTDOT get_keyed I2, P0, I1 chr S31, I2 print S31 goto NEXT NOTDOT: ne S0, ",", NEXT readline S31, 0 ord I2, S31 set_keyed P0, I1, I2 goto NEXT NEXT: inc I0 le I0, I30, INTERP end
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[ <++++>-]<+.[-]++++++++++.
Index: core.ops =================================================================== RCS file: /cvs/public/parrot/core.ops,v retrieving revision 1.144 diff -u -r1.144 core.ops --- core.ops 23 May 2002 18:36:49 -0000 1.144 +++ core.ops 30 May 2002 10:06:15 -0000 @@ -207,6 +207,22 @@ goto NEXT(); } +=item B<chr>(out STR, in INT) + +Returns the character represented by the $2 number in the ASCII +character set. + +=cut + +inline op chr (out STR, in INT) { + STRING *s; + s = string_make(interpreter, &$1, (UINTVAL)1, NULL, 0, NULL); + *(char *)s->bufstart = $2; + s->strlen = 1; + $1 = s; + goto NEXT(); +} + ########################################