- Notifications
You must be signed in to change notification settings - Fork2
PaloAlto BASIC (also known as Tiny BASIC) interpreter less than in 500 lines.
License
pankuznetsov/Palo-Alto-BASIC-in-Ruby-less-then-in-500-lines
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
PaloAlto BASIC (also known asTiny 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 orPRINT "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 orLET 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) orIF 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
RUNand hit<Enter>!
The grammer is also pretty simple and can be described in EBNF just in a very few lines:
CRstands for Carret Return (\r\n or\n, depends on OS)
emptystands for nothing.
spacestands for any white spaceASCII 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 ::= (PRINTexpression-list)| (INPUTvar-list)| (LETvar=expression)| (GOTOexpression)| (GOSUBexpression)| (RETURN)| (IFexpressionrelational-operatorexpressionTHENstatement)| (END)
line ::= ((numberstatement) | (statement)) CR
Torun the programm just downloadpaloaltobasic.rb and run it usingruby paloaltobasic.rb. Program works stable on Ruby version2.6.
Attention! Program works unstable underGIT Bash. Try using some other terminal (ex.WindowsCMD)
Contact me via e-mailkuznetsovsa_user@protonmail.com.
About
PaloAlto BASIC (also known as Tiny BASIC) interpreter less than in 500 lines.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.