Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PaloAlto BASIC (also known as Tiny BASIC) interpreter less than in 500 lines.

License

NotificationsYou must be signed in to change notification settings

pankuznetsov/Palo-Alto-BASIC-in-Ruby-less-then-in-500-lines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 

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.

Just take a look on somecode examples

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 inRUN and hit<Enter>!

EBNF Grammer

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.


[8]ページ先頭

©2009-2025 Movatter.jp