COBOL for fun and profit

The Lounge
2014-04-15
2014-04-17
  • Brian Tiffin
    Brian Tiffin
    2014-04-15

    small s.c.r.i.p.t. was written in COBOL, as a flight of fancy. Turns out to be pretty handy.

    small '128[@.+]' >codes.txt
    

    outputs the 128 7-bit ASCII values to a file.

    hexdump -C codes.txt 
    00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
    00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
    00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
    00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
    00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
    00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
    00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
    00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
    

    Why?

    Work has started on tarc, a text archive protocol, attempting to implement part of RFC 20 and ASCII control codes 28, 29, 30, 31; File Separator, Group Separator, Record Separator, Unit Separator. Escaped with ASCII 27, ESC. 0x1b thru 0x1f may someday be part of low level read routines. They will someday, be part of a tarc utility.

    Why?

    Because these ASCII control codes are old, and lonely.

    Why the small s.c.r.i.p.t.?

    Wanted to see how various editors react. 8 bytes of source, had to brag.

    (For 256 entries, it's a 6 character program)

    small '.+[.+]' >allbytes.txt
    

    bluesmiles

    http://esolangs.org/wiki/Small_s.c.r.i.p.t.

    Cheers,
    Brian

     
    Last edit: Brian Tiffin 2014-04-16
    • Brian Tiffin
      Brian Tiffin
      2014-04-16

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

      GNU    >>SOURCE FORMAT IS FIXED
      Cobol *> ***************************************************************
            *> Author:    Brian Tiffin
            *> Date:      20130730, 20130810
            *> Purpose:   small s.c.r.i.p.t.
            *> Tectonics: ./configure; make; make check && sudo make install
            *>              or, cobc -x small.cob
            *> ***************************************************************
             identification division.
             program-id. small.
      
             environment division.
             configuration section.
             repository.
                 function all intrinsic. 
      
             input-output section.
             file-control.
      
                 select program-channel
                 assign to program-filename
                 organization is line sequential
                 status is program-channel-status
                 .
      
            *> Magic numbers
             replace ==SMALL-BUFFER== by  ==32768==
                      ==BIG-BUFFER==  by ==1048576==.
      
             data division.
             file section.
             fd program-channel.
                 01 source-line      pic x(SMALL-BUFFER).
      
             working-storage section.
             01 argv                 pic x(BIG-BUFFER).
             01 current-arg          pic x(256).
                88 helping             value "-h", "--h", "--help".
                88 versioning          value "-v", "--v", "--version".
                88 use-file            value "-f", "--f", "--file".
                88 done-arguments      value high-value.
             01 file-used            pic x.
                88 file-loaded         value high-value.
      
             01 program-source.
                05 source-tape       pic x
                                       occurs BIG-BUFFER times
                                       depending on tape-length.
             01 tape-length          usage index.
             01 tape-position        usage index.
             01 ascii-value          pic 999.
      
             01 program-filename     pic x(256).
      
            *> Support single quote call
             01 first-quote          usage index.
             01 second-quote         usage index.
             01 symbol-len           pic 999.
      
            *> Memory.
             01 main-memory.
                05 memory-cell       usage binary-char unsigned
                                       occurs SMALL-BUFFER times
                                       depending on maximum-cell.
             01 maximum-cell         usage index value 1.
             01 current-cell         usage index value 1.
             01 fetch-cell           usage index value 1.
             01 character-value      pic x.
      
            *> numeric literal modes
             01 zero-context         pic x.
                88 leading-zero        value high-value
                                       when set to false is low-value.
             01 number-content       pic x.
                88 numbering           value high-value
                                       when set to false is low-value.
             01 last-number          usage binary-char unsigned.
             01 default-value        usage binary-char unsigned.
             01 zeroed-number        pic 999.
             01 formatted-number     pic zz9.
      
             01 colon-dictionary.
                05 colon-offsets     usage index occurs 256 times.
      
             01 colon-callstack.
                05 colon-returns     usage index
                                       occurs SMALL-BUFFER times
                                       depending on colons.
             01 colons               usage index.
      
             01 loop-stack.
                05 loop-offsetlimits  occurs 256 times
                                        depending on this-loop.
                   10 loop-offsets   usage index.
                   10 loop-is-numbered   pic x.
                   10 loop-limits    usage index.
             01 this-loop            usage index. 
             01 loop-limit           usage index.
             01 bracket-counter      usage binary-long.
             01 enter-block          usage index.
      
            *> I/O channels
             01 program-channel-status.
                88 no-more-source          value high-value.
                05 source-status-one     pic 9.
                05 filler                pic 9.
      
            *> for comma    
             01 user-line            pic x(SMALL-BUFFER).
             01 current-char         usage index.
      
            *> fsync output
             01 flush-status         usage binary-long.
      
            *> unix newline, should test for the other two kinds.
             01 newline pic x value x"0a".
      
            *> ***************************************************************
             procedure division.
             start-here.
      
            *> Parse command line options if any
                 move high-values to current-arg
                 accept current-arg from argument-value end-accept
                 perform until done-arguments
                     evaluate true
                         when helping
                             perform show-help
                         when versioning
                             perform show-version
                         when use-file
                             perform read-program-from-file
                     end-evaluate
      
                     move high-values to current-arg
                     accept current-arg from argument-value end-accept
                 end-perform           
      
            *> Accept program text from command line
                 if not file-loaded then
                     accept argv from command-line end-accept
                     set tape-length to BIG-BUFFER
      
                     if argv not equal spaces then
                         move argv to program-source
                     else
                         move "small s\.c\.r\.i\.p\.t\.10."
                           to program-source
                     end-if
                 end-if
      
                 set tape-length to length(trim(program-source))
                 set tape-position to 1
             .
      
            *>
            *> The big goto
            *>
             process-next.
                 if tape-position greater than tape-length then
                     go to script-end
                 end-if
      
                 compute
                     ascii-value = ord(source-tape(tape-position))
                 end-compute
      
                 go to 
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
      
                     echo L034 L035 L036 echo echo echo L040
                     echo echo echo L044 L045 L046 L047 echo
                     L049 L050 L051 L052 L053 L054 L055 L056
                     L057 L058 L059 L060 L061 echo L063 L064
      
                     L065 echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo L092 L093 L094 echo echo
      
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo L124 echo L126 echo echo
      
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
      
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
      
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
      
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                     echo echo echo echo echo echo echo echo
                 depending on ascii-value
             .
      
            *> If we get here, the small engine is broken, and it would be
            *>  uncool to fall through to the stepper.
             fail-safe.
                 display
                     "small engine problem. You get to laugh, and yell FAIL"
                 end-display
                 go script-end
             .
      
            *> we get here by jumping.  Handles digits and symbols that
            *>  need to pass literal value context to the next symbol
            *>  all other symbols reset context registers
             next-step.
                 set tape-position up by 1
                 go to process-next
             .
      
            *> or here for most symbols
             next-reset.
                 move 0 to last-number
                 set leading-zero numbering to false
                 set tape-position up by 1
                 go to process-next
             .
      
            *> The end.  s.c.r.i.p.t. complete.
             script-end.
            *> single quote CALL sets return-code, so clear it? Nah
            *>    move 0 to return-code
                 goback.
            *> ***************************************************************
      
            *> The opcodes
            *> Ordinals start at 1
            *> Default runtime is to check for and execute colon defs, or echo
             echo.
                 if colon-offsets(ascii-value) equal zero then
                     display
                         source-tape(tape-position) with no advancing
                     end-display
                     move 0 to last-number
                     set leading-zero numbering to false
                 else
                     set colons up by 1
                     set colon-returns(colons) to tape-position 
                     set tape-position to
                         colon-offsets(ascii-value)
                 end-if
                 compute
                     ascii-value = ord(source-tape(tape-position))
                 end-compute
      
            *> Call step instead of reset so colon definitions can assume a
            *>  literal context when called.  
                 go to next-step
             .
      
            *> GOTO tape position
             L034.
          >>D    display " STORE " end-display
                 if numbering then
                     if leading-zero then
                         move last-number to tape-position
                         set tape-position down by 1
                     else
                         add last-number to tape-position end-add
                     end-if
                 else
                     move memory-cell(current-cell) to tape-position
                 end-if
      
            *> When small implements audio, this will play some Grateful Dead
            *>                     SPACE
            *> as the tape position would be beyond the program source       
                 if (tape-position greater than tape-length) 
                 or (tape-position less than zero) then
                     set tape-length to tape-position
                 end-if
      
                 go to next-reset
             .
      
            *> Quote in a string
             L035.
          >>D    display " QUOTE " end-display
                 if numbering then
                     move last-number to current-cell
                     if current-cell is greater than maximum-cell then
                         set maximum-cell to current-cell
                     end-if
                 end-if
      
                 perform until tape-position is greater than tape-length
                     set tape-position up by 1
                     if source-tape(tape-position) = '"' then
                         exit perform
                     end-if
                     move source-tape(tape-position) to character-value
                     if leading-zero then
                         perform rot13-convert
                     end-if
                     compute memory-cell(current-cell) =
                         ord(character-value) - 1
                     end-compute
      
            *> Do a little dance, to avoid cell advance if no more characters
                     set tape-position up by 1
                     if (tape-position less than or equal to tape-length) and
                        (source-tape(tape-position) not = '"') then
                         set current-cell up by 1
                         if current-cell is greater than maximum-cell then
                             set maximum-cell to current-cell
                         end-if
                     end-if
                     set tape-position down by 1 
                 end-perform
      
                 go to next-reset
             .
      
            *> Display as number
             L036.
          >>D    display " OCTOTHORP " end-display
                 if numbering then
                     move last-number to default-value
                 else
                     move memory-cell(current-cell) to default-value
                 end-if
                 if leading-zero then
                     move default-value to zeroed-number
                     display zeroed-number with no advancing end-display
                 else
                     move default-value to formatted-number
                     display
                         trim(formatted-number leading) with no advancing
                     end-display
                 end-if
      
                 go to next-reset
             .
      
            *> single quote CALL
             L040.
          >>D    display " CALL " end-display
                 set first-quote to tape-position
                 set second-quote to tape-position
                 set second-quote up by 1
                 perform until second-quote > tape-length
                     if source-tape(second-quote) equal "'" then
                         set tape-position to second-quote
                         exit perform
                     end-if
                     set second-quote up by 1
                 end-perform
      
                 set second-quote down by 1
                 compute
                     symbol-len = second-quote - first-quote
                 end-compute
                 set first-quote up by 1
      
            *> If numbering, then set cell to last-number
                 if numbering then
                     set current-cell to last-number
                     if current-cell greater than maximum-cell then
                         set maximum-cell to current-cell
                     end-if
                 end-if
      
            *> For leading zero, pass address, leave status in last-number
                 if leading-zero then
                     call program-source(first-quote : symbol-len) using
                         by value address of memory-cell(current-cell)
                         returning last-number
                         on exception 
                             display "failed: "
                                 program-source(first-quote : symbol-len)
                             end-display
                     end-call
                 else
                     call program-source(first-quote : symbol-len) using
                         by value memory-cell(current-cell)
                         returning memory-cell(current-cell)
                         on exception 
                             display "failed: "
                                 program-source(first-quote : symbol-len)
                             end-display
                    end-call
                 end-if
      
                 go to next-step
             .
      
            *> Add
             L044.
          >>D    display " PLUS " end-display
                 if leading-zero then
                     move zero to memory-cell(current-cell)
                 end-if
                 if numbering then
                     move last-number to default-value
                 else
                     move 1 to default-value
                 end-if
                 add default-value to memory-cell(current-cell) end-add
      
                 go to next-reset
             .
      
            *> Accept input       
             L045.
          >>D    display " COMMA " end-display
                 accept user-line end-accept
      
                 if numbering then
                     move last-number to default-value
                 else
                     move 1 to default-value
                 end-if
      
                 set current-char to 1
                 perform until default-value equal zero
                     compute memory-cell(current-cell) =
                         ord(user-line(current-char:1)) - 1
                     end-compute
                     set default-value down by 1
                     if default-value greater than zero then
                         set current-char up by 1
                         set current-cell up by 1
                         if current-cell greater than maximum-cell then
                             set maximum-cell to current-cell
                         end-if
                     end-if
                 end-perform
      
                 go to next-reset
             .
      
            *> Subtract
             L046.
          >>D    display " MINUS " end-display
                 if leading-zero then
                     move zero to memory-cell(current-cell)
                 end-if
                 if numbering then
                     move last-number to default-value
                 else
                     move 1 to default-value
                 end-if
                 subtract
                     default-value from memory-cell(current-cell)
                 end-subtract
      
                 go to next-reset
             .
      
            *> Output as ASCII
             L047.
          >>D    display " DOT " end-display
                 if numbering then
                     move last-number to default-value
                 else
                     move memory-cell(current-cell) to default-value
                 end-if
                 move char(default-value + 1) to character-value
                 if leading-zero then
                     perform rot13-convert
                 end-if
                 if character-value not equal 10 then
                     display character-value with no advancing end-display
                 else
                     call "fsync" using by value 1
                         returning flush-status
                         on exception display "fsync fail" end-display
                     end-call
                 end-if
      
                 go to next-reset
             .
      
            *> Zero, with special rules for leading
             L049.
          >>D    display " Zero " end-display
                 if numbering then
                     multiply
                         last-number by 10 giving last-number
                     end-multiply
                 else
                    set last-number to zero
                    set leading-zero numbering to true
                 end-if
                 go to next-step
             .
      
            *> Digits, build up number
             L050.
          >>D    display " One " end-display
                 perform prep-digit
                 add 1 to last-number end-add
                 go to next-step
             .
      
             L051.
          >>D    display " Two " end-display
                 perform prep-digit
                 add 2 to last-number end-add
                 go to next-step
             .
      
             L052.
          >>D    display " Three " end-display
                 perform prep-digit
                 add 3 to last-number end-add
                 go to next-step
             .
      
             L053.
          >>D    display " Four " end-display
                 perform prep-digit
                 add 4 to last-number end-add
                 go to next-step
             .
      
             L054.
          >>D    display " Five " end-display
                 perform prep-digit
                 add 5 to last-number end-add
                 go to next-step
             .
      
             L055.
          >>D    display " Six " end-display
                 perform prep-digit
                 add 6 to last-number end-add
                 go to next-step
             .
      
             L056.
          >>D    display " Seven " end-display
                 perform prep-digit
                 add 7 to last-number end-add
                 go to next-step
             .
      
             L057.
          >>D    display " Eight " end-display
                 perform prep-digit
                 add 8 to last-number end-add
                 go to next-step
             .
      
             L058.
          >>D    display " Nine " end-display
                 perform prep-digit
                 add 9 to last-number end-add
                 go to next-step
             .
      
             L059.
          >>D    display " COLON " end-display
                 if numbering then
                    move last-number to default-value
                    add 1 to default-value end-add
                 else
                    set tape-position up by 1
                    if tape-position not greater than tape-length
                        move ord(source-tape(tape-position)) to default-value
                    else
                        go to next-reset
                    end-if
                 end-if
      
                 set colon-offsets(default-value) to tape-position
                 perform until source-tape(tape-position) = ";"
                     set tape-position up by 1
                     if tape-position greater than tape-length then
                         display "end of tape before ;" end-display
                         exit perform
                     end-if
                 end-perform
      
                 go to next-reset
             .
      
             L060.
          >>D    display " SEMI-COLON " end-display
                 if colons greater than zero then
                     set tape-position to colon-returns(colons)
                     set colons down by 1
                 else 
            *> no colon, semi-colon can suck it, and be ignored.
                     continue
                 end-if
      
                 go to next-reset
             .
      
             L061.
          >>D    display " LESS-THAN " end-display
                 if leading-zero then
                     set current-cell to maximum-cell
                 end-if
                 if numbering then
                     move last-number to default-value
                 else
                     move 1 to default-value
                 end-if
      
                 subtract default-value from current-cell end-subtract
      
                 go to next-reset
             .
      
             L063.
          >>D    display " GREATER-THAN " end-display
                 if leading-zero then
                     move zero to current-cell
                 end-if
                 if numbering then
                     move last-number to default-value
                 else
                     move 1 to default-value
                 end-if
      
                 add default-value to current-cell end-add
                 if current-cell greater than maximum-cell then
                     set maximum-cell to current-cell 
                 end-if
      
                 go to next-reset
             .
      
             L064.
          >>D    display " QUESTIONMARK " end-display
                 if leading-zero then
                     display "Debug" end-display
                 end-if
                 if numbering then
                     move last-number to default-value
                 else
                     compute last-number = random() * 1000 end-compute
                     compute
                         last-number = mod(last-number, 255) + 1
                     end-compute
                 end-if
      
                 move last-number to memory-cell(current-cell)
                 go to next-reset
             .
      
             L065.
          >>D    display " FETCH " end-display
                 if numbering then
                     add
                         last-number to current-cell giving fetch-cell
                     end-add
                 else
                     move current-cell to fetch-cell
                     set numbering to true
                 end-if
                 if leading-zero then
                     if last-number equal zero then
                         move current-cell to fetch-cell
                     else
                         move last-number to fetch-cell
                     end-if
                 end-if
      
                 if fetch-cell greater than maximum-cell then
                     set maximum-cell to fetch-cell 
                 end-if
      
                 move memory-cell(fetch-cell) to last-number
      
                 go to next-step
             .
      
             L092.
          >>D    display " BRACKET " end-display
                 set this-loop up by 1
                 if numbering then
                     move last-number to loop-limit
                 else
                     if loop-is-numbered(this-loop) equal high-value then
                         move loop-limits(this-loop) to loop-limit
                     else
                         move memory-cell(current-cell) to loop-limit
                     end-if
                 end-if
      
            *> If current is zero, skip to end of the (nested) loop
                 move 0 to bracket-counter
                 if loop-limit equal zero then
                     move low-value to loop-is-numbered(this-loop)
                     set this-loop down by 1
                     perform until tape-position greater than tape-length
                         set tape-position up by 1
                         if source-tape(tape-position) = '[' then
                             add 1 to bracket-counter end-add
                         end-if
                         if source-tape(tape-position) = "]" then
                             if bracket-counter = zero then
                                 exit perform
                             end-if
                             subtract 1 from bracket-counter end-subtract
                         end-if
                     end-perform
                 else
            *> small allows for counted loops, and needs to remember
                     if numbering then
                         move high-value to loop-is-numbered(this-loop)
                         move loop-limit to loop-limits(this-loop)
                     end-if
                     set loop-offsets(this-loop) to tape-position
            *> Next step will advance, decrement it here to account
                     set loop-offsets(this-loop) down by 1
                 end-if
      
                 go to next-reset
             .
      
            *> Output next operator, regardless
             L093.
          >>D    display " BACKSLASH " end-display
                 if numbering then
                     move last-number to default-value
                 else
                     move 1 to default-value
                 end-if
      
            *> Special backslash escape mode  with 0\
                 if default-value equal zero then
                     perform until tape-position equal to tape-length
                         set tape-position up by 1
                         if source-tape(tape-position) = '\' then
                             exit perform
                         end-if
                         display
                            source-tape(tape-position) with no advancing
                         end-display
                     end-perform
                     if tape-position greater than tape-length then
                         go to script-end
                     end-if
                 else
                     perform until default-value equal zero
                         set tape-position up by 1
                         move source-tape(tape-position) to character-value
                         if leading-zero then
                             perform rot13-convert
                         end-if
                         display character-value with no advancing end-display
                         set default-value down by 1
                     end-perform
                end-if
      
                go to next-reset
             .
      
             L094.
          >>D    display " CLOSE BRACKET " end-display
                 if loop-is-numbered(this-loop) equal high-value then
                     set loop-limits(this-loop) down by 1
                 end-if
      
                 set tape-position to loop-offsets(this-loop)
                 set this-loop down by 1
      
                 go to next-reset
             .
      
             L124.
          >>D    display " BRACE " end-display
                 if numbering then
                     move last-number to enter-block
                 else
                     move memory-cell(current-cell) to enter-block
                 end-if
      
            *> If current is not zero, skip to end of the (nested) block
                 move 0 to bracket-counter
                 if enter-block not equal zero then
                     perform until tape-position greater than tape-length
                         set tape-position up by 1
                         if source-tape(tape-position) = '{' then
                             add 1 to bracket-counter end-add
                         end-if
                         if source-tape(tape-position) = "}" then
                             if bracket-counter = zero then
                                 exit perform
                             end-if
                             subtract 1 from bracket-counter end-subtract
                         end-if
                     end-perform
                 end-if
      
                 go to next-reset
             .
      
             L126.
          >>D    display " CLOSE BRACE " end-display
      
                 go to next-reset
             .
      
            *>
            *> Support routines
            *>
      
            *> code common to all digits, except 0  
             prep-digit.
                 if numbering then
                     multiply
                         last-number by 10 giving last-number
                     end-multiply
                 else
                    set last-number to zero
                    set numbering to true
                 end-if
             .
      
            *> secret sam decoder rings
             rot13-convert.
                 inspect character-value converting
                      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
                           to
                      "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
             .
      
            *> --file support
             read-program-from-file.
                 set tape-length to 0
                 accept program-filename from argument-value end-accept
      
                 if program-filename equal spaces then
                     move 27 to tape-length
                     move "small s\.c\.r\.i\.p\.t\.10." to program-source
                 else
                     open input program-channel
                     if source-status-one not equal zero then
                         display "Sorry, file " trim(program-filename)
                                " not accessible."
                         end-display
                         move 1 to return-code
                         goback
                     end-if
      
                     read program-channel
                         at end set no-more-source to true
                     end-read
                     perform until no-more-source
                         set tape-length up by length(trim(source-line))
                         set tape-length up by 1
            *> add in newline, stripped by LINE SEQUENTIAL
                         move concatenate(trim(program-source)
                                 trim(source-line) newline)
                         to program-source
                         read program-channel
                             at end set no-more-source to true
                         end-read
                     end-perform
                     close program-channel
            *> Remove final newline as possibly unwanted output
                     if source-tape(tape-length) equal newline then
                         set tape-length down by 1
                     end-if
                 end-if
                 set file-loaded to true
             .
      
             show-version.
                 display "small s.c.r.i.p.t. 0.6.2" end-display
                 goback
             .
      
             show-help.
      
             >>SOURCE FORMAT IS FREE
                 display
                     "small s.c.r.i.p.t." newline
                     "-v0.6.2  Aug 2013-" newline
                     "A single character read interpret programming toyol" newline 
                     "by Brian Tiffin, while horsing around with autoconf and OpenCOBOL" newline newline
                     "Operators include:" newline
                     "  ' allowing CALL of a link library symbol" newline 
                     '  " for placing strings into memory' newline 
                     "  : colon definitions of the next character" newline
                     "  ; marking the end of a colon definition" newline
                     "  > for advancing the memory pointer" newline
                     "  < for retreating the memory pointer" newline
                     "  + adding to current cell" newline
                     "  - subtracting from current cell" newline
                     "  [ opening a (nestable) enter when not zero loop" newline
                     "  ] closing a loop" newline
                     "  { opening a (nestable) enter on zero block" newline
                     "  } closing a zero block" newline
                     "  . to output ascii" newline
                     "  , to accept ascii" newline
                     "  # to output number" newline
                     "  ? randomize cell or numbered debug" newline
                     "  @ fetch numbered cell and treat as literal number to next operator" newline
                     "  \ to echo next operator, or number thereof" newline
                     "  ! set source tape position to value or relative value" newline
                     "  0 leading zeros further modify behaviour of next operator" newline
                     "  1 to 9 for building up numbers, which modify behaviour of next operator" newline
                     "  all other characters are echoed" newline
                     "Usage: small [--help] [--version] [--file name] [program-text]" newline 
                 end-display
             >>SOURCE FORMAT IS FIXED
      
                 goback
             .
      
             bad-fortune.
                 display
                     "Really?  Zero?  In an ordinal scripting language?"
                 end-display
             .
      
             end program small.
      

      Example:

      asciichart.small

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

      Giving

      small -f asciichart.small
      
                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
      

      Cheers,
      Brian

       
      Last edit: Brian Tiffin 2014-05-24
      Attachments
  • Simon Sobisch
    Simon Sobisch
    2014-04-16

    Just for fun and profit: Why not using CBL_OC_GETOPT (found in current 2.0-branch) to parse the command line options?

    :-)

    Simon

     
    • Brian Tiffin
      Brian Tiffin
      2014-04-16

      I was pondering the same thing. Might be time for small s.c.r.i.p.t. 0.7.

      Cheers,
      Brian

       
  • Philipp Böhme
    Philipp Böhme
    2014-04-17

    If you do so, I'd be happy if you could watch out for any issues. And if you read the documentation, feel free to transform anything to good english. ^^

    Greetz,
    Philipp