Giter Site home page Giter Site logo

pankuznetsov / palo-alto-basic-in-ruby-less-then-in-500-lines Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 2.0 49 KB

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

License: MIT License

Ruby 100.00%
basic calculator-application ruby programming-language basic-implementation palo-alto-basic tiny-basic lexer-parser example-code tiny

palo-alto-basic-in-ruby-less-then-in-500-lines's Introduction

PaloAlto BASIC in Ruby less then in 500 lines

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.

Just take a look on some code examples

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>!

EBNF Grammer

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 [email protected].

palo-alto-basic-in-ruby-less-then-in-500-lines's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.