Tiny

From Esolang
Jump to navigation Jump to search

Tiny is a small integer RPN based language created by User:Ron.hudson. It is a console/character type interpretive programming language, in which all statements are either assignments or those that print quoted strings.

Syntax

Each line consists of an integer line number, followed by any number of commands. Line numbers are long integer numbers. The number can have leading zeros. The commands are:

#comment to the end of line
"print this string"
[calculates an expression] stores the result into one or more variables
.

The third command is an assignment, and the fourth command ends the program. Multiple commands can be written on the same line. Escape sequences are allowed inside quoted strings (\n (newline), \e (ASCII 0x1B), \t (tab), \", \\).

Expressions are written in Reverse Polish notation, and can use the following operators:

+ - * / % ^ Arithmetic (add, subtract, multiply, divide, remainder, raise to a power)
< > = Comparison (less than, greater than, equal to;
                  returns 1 for true, 0 for false)
& | ! Logical (and, or, not; uses 1 for true and 0 for false)

The stack is dynamic.

Variables

There are three types of variables:

  • a to z. These are long int numbers. They have a range of a long in your C compiler.
  • Array members. There is one array, which is sized at compile time. An array element is specified by enclosing an expression in parens. The value of the expression is taken as an index into the array.
  • Special variables. These are used for I/O, storage, and program control, and have names that are punctuation marks.

Special variables

The following special variables are available:

  • @ The current execution step. Assigning a value to this, other than 0, causes a jump to the line with the number that has been assigned at the end of the line currently running. All elements in the line complete before the jump is taken. Assigning 0 has no effect. Because assigning 0 has no effect and a result of FALSE for the comparative operators is 0, you can take the boolian result and multiply it by the line number you wish to conditionally jump to and then assign that value to @. Reading from this (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.
  • ? Numeric I/O. Reading from ? inputs a number, and writing to it outputs a number. If a null string is entered by the user, 0 is returned. A global format for numbers can be presented between single quotes: ' %07ld '
  • ~ Random number. Reading returns a random number, and writing seeds the random-number generator (with the number given, or with the system time if 0 is given). This RNG returns a number between 0 and maximum for a long integer.

Example

0100 #squares to 42
0110 [?] x
0120 [x] ? " Squared is : " [x 2 ^] ? "\n"   [x 42 = ! 110 *] @
0130 "Thanks for trying Tiny! \n\n"
0140 .

Line 100 is a comment.

Line 110 waits for the user's numeric input, reads it, and then stores it in the variable x.

Line 120 prints x, prints a string, prints x squared, prints a newline, then tests x; if x is not equal to 42, it goes to line 110. (It stores 0 in @ if x is 42; or 110 in @ if x is not 42; storing 0 in @ has no effect.)

Line 130 prints a string.

Line 140 ends the program and stops execution.

Computational class

Due to the limits on the range of a variable, Tiny cannot be Turing-complete; the array is effectively finite, as only a finite number of elements can be indexed (due to the range of the variables a-z). The $ stack is infinite; however, there is only one $ stack, which is not enough for Turing-completeness (there is no temporary storage for a bignum anywhere else). Every Tiny program is a (random, if you use ~) push-down automaton. Because jump target line numbers are also limited in size, Tiny can probably not simulate PDAs with arbitrarily many states. The amount of memory available is likely to prove adequate for most programs.

Known and Discovered bugs

There is a bug in the editing feature. When one replaces a line with a longer line the new line won't fit where the old line was this causes a bunch of errors. For now, the best way around this is to edit your program in an external editor and just run it in Tiny

Notes

Tiny has simple facilities to load a program, replace lines and save a program from the tiny command line or you can edit your program in your favorite editor and have Tiny run it.

If you execute tiny with the name of a tiny source file (tiny filename<cr>) tiny will load and run that file, and when the program finishes tiny will exit back to the operating system.

When you use tiny to edit your program the comment marker also introduces commands:

#o filename, old, Read program steps from a file, the new steps are merged with the current program.
#b, bye, Exit Tiny.
#s filename, save, Save the current program in the file named.
#l, list, Lists the program (the whole program with no paging)
#n, new, Clears the program area.
#r, run, Run program in memory


Because the # is a comment marker, in Linux you can use the #! <path to tiny> and create command line executable in tiny

External resources

Tiny.c is available at GitLab - https://gitlab.com/waspentalive/tiny

Tiny is now in the package manager for Haiku - A Be OS clone at [1]

Plans and possible extensions

Floating point tiny again someday.

Line Number Sorting... Line number sorting has been handled by Bruce Hudson (My brother). Line numbers are now used to sort the program in both executive and interactive modes.

right now you have to say "0 5 -" if you mean -5.

Announcing Floating Point Tiny

Floating Point Tiny is not currently available.

I unfortunately have misplaced the source code.

I am working on Tiny2 which will replace line numbers with line labels.

A plea

I seem to have misplaced the source for fltiny.c If any of you have downloaded it please contact me so I can get a copy from you my email address is obfuscated in my user page user:Ron.hudson