PaloAlto BASIC (also known as Tiny BASIC) interpreter less than in 500 lines writen in Ruby. The original program takes only 3KB of ROM and runs on Intel 8080, Motorola 6800 and MOS Technology 6502 processors.
This BASIC understands a few statements and all variables there are 16 or 32-bit integers.
Take a look on Wikipedia page.
Print statement: PRINT "HELLO WORLD"
, PRINT A
or PRINT "X: ", X, ", Y: ", Y, ", Z: ", Z
Input staement: INPUT A
, or you can use list of variables: INPUT A, B, C
Variable defenition/assigment: LET A = 10
, LET B = (2 + 6) * 4
or LET C = (A * B) + (B / A) - 1
Goto: 10 GOTO 10
is endless cycle. GOTO A * 10 + 230
is also possible.
If: IF A = B THEN PRINT "EQUALITY"
, IF A > B * 2 THEN LET C = C + (B - A)
or IF A <> B THEN PRINT "UNEQUALITY"
GoSub: 10 IF A = 1 THEN GOSUB 50
... 50 LET X = X * X
... 60 RETURN
Important Note: To run the program just type in
RUN
and hit<Enter>
!
The grammer is also pretty simple and can be described in EBNF just in a very few lines:
CR stands for Carret Return (\r\n
or \n
, depends on OS)
empty stands for nothing.
space stands for any white space ASCII symbol.
(...)* means that ... may be repeated zero or more times.
digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
lowercase ::= a | b | c ... x | y | z
uppercase ::= A | B | C ... X | Y | Z
letter ::= lowercase | uppercase
number ::= digit (digit)*
string ::= " (letter | digit | space)* "
var ::= uppercase
var-list ::= var (, var)*
factor ::= var | number | ( expression )
term ::= factor ((* | /) factor)*
expression ::= (+ | - | empty) term ((+ | -) term)*
expression-list ::= (expression | string) (, expression | string)*
ralational-operator ::= (< (> | = | empty)) | (> (< | = | empty)) | =
statement ::= (PRINT expression-list) | (INPUT var-list) | (LET var = expression) | (GOTO expression) | (GOSUB expression) | (RETURN) | (IF expression relational-operator expression THEN statement) | (END)
line ::= ((number statement) | (statement)) CR
To run the programm just download paloaltobasic.rb and run it using ruby paloaltobasic.rb
. Program works stable on Ruby version 2.6.
Attention! Program works unstable under GIT Bash. Try using some other terminal (ex. Windows CMD)
Contact me via e-mail kuznetsovsa_user@protonmail.com
.