small s.c.r.i.p.t.

From Esolang
Jump to navigation Jump to search

small s.c.r.i.p.t. is a single character read interpret programming toyol, designed and implemented in OpenCOBOL by Brian Tiffin, User:Btiffin in August 2013.

Based on the bf model of memory access and looping structures, with forth colon defintions, special numbering modes and text echo.

toyol
Toy, tool. Represents fun, usefulless work; toil. Pronounced toil.

Operators

Operation Meaning
+ add value to current cell
- subtract value from current cell
> advance data cell index up by value
< retreat data cell index down by value
[ if current value, or current cell, is zero, scan source index forward to matching, nestable ]
] closes closest [ loop, decrementing count for numbered loops
{ if current value, or current cell, is non zero, scan source index forward to matching, nestable }
} closes closest { block
. output current value or current cell as character value
, accept character value(s) starting at current cell
: colon definition of current value or next symbol
; end colon definition
# output current value or current cell as number
? randomize current cell, or numbered debug
' CALL link library name
" laydown quoted string
@ fetch current, relative, absolute memory cell and treat as immediate literal
\ echo next value characters
! store value or current cell to source tape position
0 for building up values, leading zeros can further modify numbering behaviour
1 to 9 for building up integer numbers
other all other characters are echoed

Literal integer values are handled as an implicitly accessed, optional, single register. Numbers modify operator behaviour, leading zeros on numbers modifies the behaviour further.

Examples

Hello world

 $ small 'Hello\, world'
 Hello, world

Immediate loop

 $ small '5[a]'
 aaaaa

Cell based loop

 $ small '+++++[a-]'
 aaaaa

Mixed nested loops

 $ small '4[a05+[b-] ]'
 abbbbb abbbbb abbbbb abbbbb

Call and string

 $ small "\"ls\">0+01'system'"
 a5.small  asciichart.small  hello.small  inc-a5.small  inc-a5b4.small

Memory

 $ small '+++ # >+++ # <--- # >+++ #'
   3  3  0  6

Fetch immediate

 $ small '>++@[a]>>02@[b]<<<1@[c]'
 aabbcc

Enter on zero

 $ small '0{a}1{b}{c}+{d}[-{e}]'
 ace

Goto, tape store

 $ small '05!ab2!cd'
 bd

Printable ASCII chart

 0[Printable Ascii Chart in small s.c.r.i.p.t., by Brian Tiffin]10:;
 10[ ]Printable ASCII Chart10.
 10[ ]21[=]10.
 032+
 15[0@# .  5[16+0@# .  ]10.79-]
 0@.# .  4[16+0@# .  ]10.

Tested with

$ small --file asciichart.small

giving

           Printable ASCII Chart
           =====================
 032    048 0  064 @  080 P  096 `  112 p  
 033 !  049 1  065 A  081 Q  097 a  113 q  
 034 "  050 2  066 B  082 R  098 b  114 r  
 035 #  051 3  067 C  083 S  099 c  115 s  
 036 $  052 4  068 D  084 T  100 d  116 t  
 037 %  053 5  069 E  085 U  101 e  117 u  
 038 &  054 6  070 F  086 V  102 f  118 v  
 039 '  055 7  071 G  087 W  103 g  119 w  
 040 (  056 8  072 H  088 X  104 h  120 x  
 041 )  057 9  073 I  089 Y  105 i  121 y  
 042 *  058 :  074 J  090 Z  106 j  122 z  
 043 +  059 ;  075 K  091 [  107 k  123 {  
 044 ,  060 <  076 L  092 \  108 l  124 |  
 045 -  061 =  077 M  093 ]  109 m  125 }  
 046 .  062 >  078 N  094 ^  110 n  126 ~  
 047 /  063 ?  079 O  095 _  111 o

asciichart.small explained.

 0[Printable Ascii Chart in small s.c.r.i.p.t., by Brian Tiffin]10:;
 10[ ]Printable ASCII Chart10.
 10[ ]21[=]10.
 032+
 15[0@# .  5[16+0@# .  ]10.79-]
 0@.# .  4[16+0@# .  ]10.

Starting with

0[Printable Ascii Chart in small s.c.r.i.p.t., by Brian Tiffin]

as a comment block, up to and including the ]. The [ operator will either loop using current memory cell or, when proceeded by a literal number, will use a counted loop, the count down to zero managed by small.

The following 10:; is a trick to allow source files to not echo newlines. (This works with GNU/Linux, probably breaks on Windows and Macs.) small newlines are 10s. Colon definitions ala Forth, allow any symbol not listed as a small operator to be redefined. In this case, the immediate 10 is used for the colon definition symbol, instead of the no number case of the character immediately following the colon operator. Colon definitions end at semicolons, and in this case 10:; does nothing, turning off the implicit character echo. Now the source code can have newlines that don't muck up output. The same can be done for space, with 32:; or : ; but this code looks better with the spaces as output I think.

Next up is a counted loop, echoing 10 spaces. Then the title, Printable ASCII Chart, and a forced newline, 10..

Next is 10 spaces in a loop, 21 equal signs and a newline 10..

032+ clears current memory cell (leading-zero rule for +) and adds in 32. Skip over some non-printables.

 15[0@# .  5[16+0@# .  ]10.79-]
 0@# .  4[16+0@# .  ]10.

Displays the chart. 15 loops over number zero formats it with 0@#, space, dot . (which outputs current memory as ASCII). Then two spaces (echoed as usual). A 5 loop follows, adding 16 to current each time to get a nice columnar display. ("0@# . " should a colon def). ] closes the inner loop. Display a newline with 10. and subtract the 79 needed to get back to the column 1 value, closing the outer loop. Last line could have been in a 16 loop above, but it excludes the non-printable ASCII 127 to keep things on the up and up, only looping over 4 more columns.

That chart could be written as

 0[Printable Ascii Chart in small s.c.r.i.p.t., by Brian Tiffin]10[ ]Printable ASCII Chart
 10[ ]21[=]
 032+:~0@# .  ;15[~5[16+~]10.79-]~4[16+~]10.

where the newlines count and the last 10. is needed as small will strip off any trailing newline from scripts read with --file. It's a rule. Template files need to output any final newline or leave two newlines at the bottom. This nuisance is added to make it easier on non template scripts, and not worrying about source file final newlines.

small s.c.r.i.p.t. Hello sample

 $ cat samples/hello.small
 Hello\, world
 
 This is the hello world sample for small 12\s.c.r.i.p.t.
 A single character read interpret programming toyol\.
 
 Nothing too fancy or deep\, only best wishes\.
 01"Unir tbbq, rirelbar.">0+01>[.>] 

 May you get enough  7[06+[z-]]\'s\.:w59.);:~20[ ];
 If not\, at least 40# 10[w ]10.2[~10[w ]10.]~9[w ]w\'s 119.hen needed\.
 
 0[Implemented in OpenCOBOL, see http://sourceforge.net]
 small 12\s.c.r.i.p.t.\, By Brian Tiffin
 
 $ src/small --file samples/hello.small

Which outputs

Hello, world

This is the hello world sample for small s.c.r.i.p.t.
A single character read interpret programming toyol.

Nothing too fancy or deep, only best wishes.
Have good, everyone.

May you get enough  zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz's.
If not, at least 40 ;) ;) ;) ;) ;) ;) ;) ;) ;) ;)
                    ;) ;) ;) ;) ;) ;) ;) ;) ;) ;)
                    ;) ;) ;) ;) ;) ;) ;) ;) ;) ;)
                    ;) ;) ;) ;) ;) ;) ;) ;) ;) ;)'s when needed.
 
small s.c.r.i.p.t., By Brian Tiffin

The Hello sample is mostly character echo, backslash escapes for operators, including 12\ for s.c.r.i.p.t., just because.

 01"Unir tbbq, rirelbar.">0+01>[.>] 

 May you get enough  7[06+[z-]]\'s\.:w59.);:~20[ ];
 If not\, at least 40# 10[w ]10.2[~10[w ]10.]~9[w ]w\'s 119.hen needed\.

might be a little trickier. Quoted strings are layed down starting at the current memory cell, or the numbered cell. Leading zeros are a joke, and lay down ROT13 strings instead. >0+ lays down a null, then using a leading zero (first cell relative numbered cell movement) to cell 1 with 01>. Using stock bf code to loop across the string and displaying characters until a zero byte. The ROT13 being Have good, everyone. Because, yeah, we should ... have good.

After that there is 42 z's, a colon definition of w (smooshed up against the z line as newlines count in the output in this and source code formatting has to be technical and not so much artistically pleasing. Following the winky is a squiggle definition of 20 spaces. As w is now defined, when needs to be spelled as 119.hen.


99 bottles of beer on the wall

 0[99 bottles of beer, in small s.c.r.i.p.t.]:B01>;:X02>;:Y03>;:S-X01+Y0+B[sX-]>[X-Y]B+;:ZX01+Y0+B[#X-]>[noX-Y]B;
 099+[# bottleS of beer on the wall\, # bottleS of beer\.
 Take one down and pass it around\, -Z bottleS of beer on the wall\.
 ]
 No more bottles of beer on the wall\, no more bottles of beer\.
 Go to the store and buy some more4\, 99 bottles of beer on the wall\.

with a run of (from 3 instead of 99)

$ ./small.exe --file ../samples/99bottles.small
3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall. 

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.

This one is a little shorter, and more true to the line spacing used in http://www.99-bottles-of-beer.net/lyrics.html

239 bytes

 :A01>;:X02>;:Y03>;:S-X01+Y0+A[sX-]>[X-Y]A+;:ZX01+Y0+A[#X-]>[ noX-Y]A;:BbottleS of beer;:Oon the wall;:Mmore;099+[# B O\, # B\.
 Take one down and pass it around\, -Z B O\.10.
 ]No M B O\, no M B\.
 Go to the store and buy some M4\, 99 B O\.

And even a little shorter at 190 bytes

 :S-{3!}s+;:Z{no3!}#;:BbottleS of beer;:Oon the wall;:Mmore;099+[# B O\, # B\.
 Take one down and pass it around\, -Z B O\.10.
 ]No M B O\, no M B\.
 Go to the store and buy some M4\, 99 B O\.
 


0.6.2 help output

 small s.c.r.i.p.t.
 -v0.6.2  Aug 2013-
 A single character read interpret programming toyol
 by Brian Tiffin, while horsing around with autoconf and OpenCOBOL 
 
 Operators include:
   ' allowing CALL of a link library symbol
   " for placing strings into memory
   : colon definitions of the next character
   ; marking the end of a colon definition
   > for advancing the memory pointer
   < for retreating the memory pointer
   + adding to current cell
   - subtracting from current cell
   [ opening a (nestable) enter when not zero loop
   ] closing a no zero loop
   { opening a (nestable) enter on zero block
   } closing a zero block
   . to output ascii
   , to accept ascii
   # to output number
   ? randomize cell or numbered debug
   @ fetch numbered cell and treat as literal number to next operator
   \ to echo next operator, or number thereof
   ! set source tape position to value or relative value
   0 leading zeros further modify behaviour of next operator
   1 to 9 for building up numbers, which modify behaviour of next operator
   all other characters are echoed
 Usage: small [--help] [--version] [--file name] [program-text]

Implementation Implemented in OpenCOBOL, with GNU autotools. The author admits to low levels of GNU Autotools-Fu, and builds may have issues. If ./configure; make check doesn't work for a particular platform; it's basically

 cobc -x src/small.cob
 

beta tarball stashed away at http://opencobol.add1tocobol.com/small/small-0.6.2.tar.gz