Tiny
Newtiny The next generation of the Tiny programming language family. Labels and Strings!
Newtiny removes the line numbers and gives you labels for jumping to and named variables to store your information.
Syntax
- ! /usr/bin/env newtiny
Begin: [ 0 ] sum num [ " %8.4lf " ] FORMAT
getinp: [ "Please type: end | bad | add | clr " "" PROMPT ] inp
[ inp "end" .EQ. done * ] @ [ inp "bad" .EQ. subt * ] @ [ inp "add" .EQ. sumb * ] @ [ inp "clr" .EQ. clrg * ] @ CRLF [ " What ?? " ] ? [ getinp ] @
clrg: [ 0.00 ] sum num [ getinp ] @
sumb: [ " Add data point" "" PROMPT ] inp
[ sum inp + ] sum [ num 1 + ] num [ disp ] @
subt: [ " Remove data point" "" PROMPT ] inp
[ sum inp - ] sum [ num 1 - ] num [ disp ] @
disp: [ "Count Sum Average " ] ? CRLF
[ "=========== =========== ===========" ] ? CRLF [ num 0 .eq. none * ] @ [ num ] ? [ sum ] ? [ sum num / ] ? CRLF [ getinp ] @
none: [ "No data points at this time " ] ? CRLF
[ getinp ] @
done: HALT
- Variables
sum= num= inp=
Variables
Variables in NewTiny are named. They can hold either a string of up to 80 characters or a double.
Special variables
The following special variables are available:
- @ The next execution step. Assigning a value to this, other than 0, causes a jump to the line with the label that has been assigned once the current line finishes. All elements in the line must be completed before the jump is taken. Assigning 0 leads to no branch taken, because assigning 0 has no effect and a result of FALSE for the comparative operators is 0, you can take the boolean result and multiply it by the line label you wish to conditionally jump to, then assign that value to @. Reading from "@" (before it is assigned) gives the line number of the next line (Useful as a subroutine return address)
- $ Storage stack. Assigning to $ pushes a number onto the stack; reading from it pops a number from the stack and returns it. The main use for the stack is to store subroutine return addresses. [@]$ [subroutine line number] @ to call a subroutine and [$]@ to return from one.
- ? Input/Output [ ? ] ? reads data from the user and prints it out again. When inputting data, either numbers or strings can be typed.
- ~ Random number. Reading returns a random number. Writing does nothing as the PRNG is automatically seeded at launch.
Example
- Fizbuz
- A programmer's exercise
Begin: [ 1 ] enn [ " %6.0lf "] FORMAT
[ @ ] $
[ enn 15 % 0 .EQ. div15 * ] @ [ enn 5 % 0 .EQ. div05 * ] @ [ enn 3 % 0 .EQ. div03 * ] @ [ enn ] ? [ loop ] @
div15: [ " FizBuz " ] ? [ loop ] @ div05: [ " ...Buz " ] ? [ loop ] @ div03: [ " FIZ... " ] ? [ loop ] @
loop: [ enn 1 + ] enn
[ enn 101 .EQ. done * ] @ [ $ ] @ $
done: CRLF [ " Done " ] ?
end: HALT
enn=
Computational class
This may change - NewTiny uses named variables which can hold either a double or a 80-character string. Lines are no longer numbered, but target lines are labeled. Arrays are available. Declare an array with name=(size) where the name must start in col 1. The amount of memory available (variables + program steps) is set at compile time, as is the depth of both stacks.
Please re-evaluate the Computational Class because you may have as many arrays as you want.
Notes
Newtiny is an execute-only interpreter. You edit your source code in your own editor and then launch newtiny with the name of your source file.
External resources
NewTiny is available at Codeberg: https://codeberg.org/WasPentalive/newtiny.git
Download the latest tar.gz file and extract.
NewTiny is the latest evolution of the tiny language family. No more line numbers! Multicharacter labels for lines and variables. Arrays