tinyBasic v1.0
==============
  an iziBasic sample program
    Copyleft 2005 by Laurent DUVEAU
    http://www.aldweb.com/




Tiny BASIC 
----------

Tiny BASIC started out as a way to get a BASIC running in the minimum amount of memory space (~2 KBytes), because RAM used to be very expensive and home computers would only have a few KB of RAM back in the 1970's.
Here is an interesting link about Tiny BASIC: http://en.wikipedia.org/wiki/Tiny_BASIC_programming_language

Nowadays, Tiny BASIC is no more than a programming game that still a few people have fun with :-)

My Tiny BASIC dialect, that I just called "tinyBasic", is similar and loosely based on the Intel 8080 Tiny BASIC written by Li Chen Wang and appearing in Doctor Dobb's Journal of Computer Calisthenics & Orthodontia in the May 1976 Vol 1, No. 5 issue. It is worth mentioning that Li Chen Wang's Tiny BASIC interpreter was released with full source code, showing the "copyleft" label for the first time, and occupied only 1.77 KBytes of memory.

The main differences between my tinyBasic dialect and Li Chen Wang's Tiny BASIC are:
- the use of float and not of integer numbers (because it is written in iziBasic, there is no need to bring a limit in this area), and the use of the integer division operation ("\") to easily get the integer part of a number;
- the no use of GOSUB/RETURN to avoid a stack (and because you can easily simulate a GOSUB/RETURN call with GOTO and a variable set to the return line);
- the addition of the LOAD/SAVE statements, for allowing to keep working on a source code;
- the addition of the HELP statement, to get an immediate onboard reminder;
- the addition of the MEM statement, to get an idea of the free remaining storage;
- the addition of the CLS statement, to clear the screen;
- the addition of the TICKS/TICKSPERSEC functions, to show how to integrate functions in the math parser and to get an idea of speed execution (benchmarking).

Note: tinyBasic's bytecode is 2.97 KBytes long, to be compared with the 1.77 KBytes of Li Chen Wang's Tiny BASIC.




tinyBasic
---------

Statements  (yeah, that's all folks!):
  BYE
  CLEAR
  CLS
  END
  GOTO <expression>
  HELP
  IF <expression> THEN <statement>
  INPUT <variable> 
  [LET] <variable>=<expression> 
  LIST [<expression>|PAUSE]
  LOAD <expression> 
  MEM
  NEW 
  PRINT <expression>|<string>[,<expression>|<string>][...][;]
  REM <anything> 
  RUN 
  SAVE <expression>

Functions (available in <expression>): 
  TICKS
  TICKSPERSEC

Variables & Expressions:
The variables allowed in tinyBasic are represented by the letters [A-Z] (A to Z), each representing a float (no strings). Expressions consist of the following operations [<=,<,=,>,>=,+,-,*,/,\] ("\" is integer division), with [*,/,\] having the highest priority, followed by [+,-], then by [<=,<,=,>,>=]. "(" and ")" may be used to group expressions. 

Source code lines:
Any number of statements can appear on a line, separated by ":".
If a line is entered without a number in front, it is executed immediately. If a nonzero number appears at the start of the line, then the line is placed into program storage in the order of that line number. If there is already a line by that number, it is replaced by the new line. If the line entered has nothing after the number (line number is alone on the line), then the given line will be deleted. 
A line is limited to 63 characters. The storage capability is of 99 lines.

Statements & functions quick explanations:
BYE exits the tinyBasic application.
CLEAR resets all A to Z variables to the 0 (zero) value.
CLS clears the screen.
END finishes a program and returns to the "Ready" prompt.
GOTO moves program execution to a given line number.
Trick: you can easily simulate a GOSUB/RETURN call with GOTO and a variable set to the return line. Example:
10 INPUT A : R=20 : GOTO 30
20 PRINT "A=",A : END
30 A=A+10 : GOTO R
HELP displays a quick help/reminder screen of statements & functions.
The expression in the IF statement ends up in a value (>=1 is true, <1 is false). If the condition is true the statement placed after the THEN word is executed. If it is false, the execution moves to the next line. 
INPUT stores a user input in a variable.
LET is a facultative statement to store an expression into a variable.
The stored program is listed with LIST. If the listing is long, you may pause its scrolling at each page with the PAUSE option, or display a single line providing its number.
The LOAD statement loads a program identified by its value, previously saved with the SAVE statement in the "huge" RAM storage of your Palm device. If the program value is 0 (zero), then it is considered as an autoload and autorun application, which will be launched when you launch tinyBasic.
MEM returns the number of free source code lines out of the 99 lines storage capability.
NEW empties all lines.
A PRINT statement consists of any number of variables, expressions or strings separated by commas. Although strings cannot be stored in variables, a string, consisting of characters appearing between quote marks, can be printed. 
You may write anything you want after a REM statement which is bypassed by the interpreter (the interpreter ignores everything on a line following a REM statement).
The RUN statement causes all variables to be reset to 0 (zero) and the first line of the program is executed. 
SAVE saves all stored lines to a file. If no line is stored and if the file exists, it deletes the file. So,doing "NEW : SAVE 1" will delete file 1.
The TICKS function returns the Palm OS CPU ticks value and the TICKSPERSEC one returns the number of ticks that the CPU delivers per second. I added these 2 functions for the fun of benchmarking tinyBasic with the other development tools and languages :-) Don't worry, tinyBasic is very slow! Using TICKS is also a convenient way to generate pseudo random numbers (see the Matches sample program for an example of generating pseudo random numbers).




Memo2tinyBas
------------

As it soon becomes a real pain to use the very basic editing capabilities of a Tiny Basic, and so of tinyBasic, I added this Memo2tinyBas application to easily convert a tinyBasic source code written in a Memo (in the Memo Pad application) to the format that can be read by tinyBasic.

To be identified as a tinyBasic source code by Memo2tinyBas, the first line of a Memo should start with "tinyBas" followed by a number which will be value to use with the LOAD statement in tinyBasic. All other characters on the first line will be ignored by Memo2tinyBas and are considered as comments. So, it is a good place to put a short description of what the program does.
All following lines in the Memo should follow the structure of a tinyBasic source code line. 
To ease the reading of the source code, empty lines are allowed and will be ignored by Memo2tinyBas.

Note: tinyBasic is another good and small example of a GUI & files accesses sample source code for iziBasic.




tinyBasic sample source codes
-----------------------------

I designed 4 quick and easy applications while testing tinyBasic.
1. tinyBas0 - AutoRun     : Personalized Welcome
2. tinyBas1 - Hello World : Classical 'Hello World'
3. tinyBas2 - Matches     : Marienbad Game
4. tinyBas3 - Numerus     : Roman Numerals Convertor

