Tinycat - minimal BASIC dialect with line numbers
basic [filename...]
Tinycat is a minimal dialect of the BASIC programming language, created as a demonstration and exercise, but still with the hope that it will prove useful.
The only supported data type is double-precision floating point numbers. (Strings can only be displayed, not manipulated.) This is sufficient for simple games or mathematics.
Save files are plain text, and can be created or modified with any text editor. The language itself is case-insensitive, like most BASIC dialects.
Running basic without any arguments will put you at an interactive prompt. You can quit by entering BYE
, or pressing Ctrl-D.
Giving one or more files as command-line arguments to the interpreter will cause it to first load those files in sequence, then RUN
them. In this mode, the interpreter will normally quit when the program ends, either by reaching the last line or a call to END
.
Either way, if the running program is interrupted with the STOP
statement, basic will enter interactive mode. Execution can be resumed with CONTINUE
, perhaps after replacing some variables and/or lines of code.
A line prefixed with a number will be stored for later use, overwriting any existing line with the same number. The absence of a line number will cause it to be interpreted on the spot, whether in interactive mode or not.
Commands aren't available in a stored program. Some statements make sense in either mode.
Display the stored program, if any, sorted by line number.
Runs the stored program, if any.
Resumes running a program interrupted with STOP (see below).
Deletes all currently defined variables.
Deletes all stored program lines.
Deletes only the given line number, if it exists.
Loads a stored program from the named file. If the file contains immediate commands, each is run as encountered.
Saves a stored program into the named file.
Quits the interpreter and return to the operating system. You can also press Ctrl-D.
Creates a variable with given value.
Runs statement if the expression is true.
Jumps to the line number given by expression (any decimals are truncated). Usually used after IF
. After a program has been interrupted with STOP
, GOTO
can be used to change where it should CONTINUE
from.
Displays the given value or values, in order, joined together. Adds a newline unless a semicolon ends the list. Just PRINT
by itself adds a newline.
Prompts the user to enter one or more numbers separated by commas, and assigns them in order to the given variables. If there are more variables than entered numbers, the remaining ones are zeroed.
Introduces a counted loop. Beware that it will always run at least once, no matter what the limits are.
Loops around to the matching FOR
unless the limit was reached. The variable name must be the same as in the matching FOR
, otherwise weird things will happen.
Jumps to the subroutine given by expression (any decimals are truncated).
Returns from a subroutine, to right after the matching GOSUB
statement.
Introduces a conditional loop.
Loops around to the matching DO
, depending on whether the condition is met.
Introduces a comment. Any text that follows is ignored, to the end of the line.
Defines a function with given name and arguments. Functions so defined can be called just like built-ins. Trying to redefine a function during the same run of the program is an error.
DEF FN
is absent in some implementations.
Initializes the random number generator, optionally to a fixed value (any decimals are truncated).
Some implementations do this automatically when basic starts, but not all.
Interrupts the running of a program, and puts basic in interactive mode. Does nothing if already in that state.
Ends the currently running program. Returns to either interactive mode or the operating system, depending on how the program was started.
Returns an implementation-dependent time in seconds (with decimals). It can be used to measure elapsed intervals. Can be called without parentheses.
Returns a random number in the [0, 1) interval. Can be called without parentheses.
Returns PI with 15-figure precision. Can be called without parentheses.
Returns n with any decimals truncated.
Returns the absolute value of n.
Returns the square root of n.
Returns the sine of n. (Works with radians.)
Returns the cosine of n. (Works with radians.)
Returns n converted from degrees to radians.
Returns n converted from radians to degrees.
Returns the smallest of a and b.
Returns the largest of a and b.
Returns the remainder of dividing a by b. Results may be unexpected if either have decimals.
Returns the equivalent of SQR(a ^ 2 + b ^ 2).
Returns the equivalent of SQR(a ^ 2 + b ^ 2 + c ^ 2).
Returns b if a is true, else returns c. Beware that all three are always evaluated.
Arithmetic operators are +, -, *, /, \ (flooring division) and ^ (exponentiation). The latter is right-associative. Unary minus is also supported. In fact, a minus in front of a number will always be interpreted as unary minus, and not a sign; the effect is identical anyway.
Comparison operators are <=, <, =, <>, >, >=. Logical operators AND, OR, NOT are also supported. Beware that both sides of a logical operator are always evaluated.
This manual applies to version 1.1 of the interpreter, from January 2017.
Some implementations are weird about the minimum number of decimals they display for a given number.
10 rem Compute the greatest common divisor (GCD) of two numbers.
20 input "Enter two numbers, please: ", a, b
30 if a > b then let a = a - b
40 if b > a then let b = b - a
50 if a <> b then goto 30
60 print "Greatest Common Divisor of given numbers: ", a
Tinycat Basic is written by Felix Pleşoianu.
This software is free and open source software under the Artistic License 2.0. Use at your own risk.