An xBASIC interpreter library written in Rust. xBASIC is a language loosely based off of QBasic.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
Stephen 0e92e5ce49 Another bug fix(arithmetic assign) 2 giorni fa
benches Give IO ownership to XBasic object 1 settimana fa
examples Functions 1 mese fa
src Another bug fix(arithmetic assign) 2 giorni fa
tests Another bug fix(arithmetic assign) 2 giorni fa
.gitignore Initial commit - does hello world 1 mese fa
Cargo.lock cut release 5 giorni fa
Cargo.toml cut release 5 giorni fa
LICENSE.md Add license 1 mese fa
README.md Add repository 2 settimane fa
rustfmt.toml Initial commit - does hello world 1 mese fa

README.md

xBASIC

xBASIC is designed to be a very simple language. The goal of this library is to make it easy to add user-defined logic to your Rust project.

Features:

  • Gracefully handles bad or malicious code.
  • Allows setting a compute time limit.
  • Allows calling xBASIC functions from Rust
  • Allows calling Rust functions from xBASIC
  • Allows defining custom IO, which PRINT and INPUT work with
  • Entirely safe rust

TODO:

  • Arrays
  • Better standard library(string lengths, type conversions, etc)

A basic interpreter is also included in this project. It can be started with cargo run. It possesses a REPL, but can also run files.

Syntax

As mentioned already, xBASIC is a very simple language. Like other BASIC languages, it is designed to be easy for beginners to understand.

Printing

print "hello world" // "hello world"
print "hello" "world" // "hello world"
print 5 "+" 3 "=" 5 + 3 // "5 + 3 = 8"

PRINT will automatically concatenate multiple expressions together.

Reading

input a // Read in a line, store it in a
input b // Read in another line, store it in b

Variables

a = 3
print a // "3"
print b // "0"

All variables are implicitly initialized to 0.

Comparisons

a = 3
print a = 3 // "true"
print not a = 3 // \"false\"
print a < 3 // "false"
print a > 3 // "false"
print a <= 3 // "true"
print a >= 3 // "true"

Note that a = 3 is an assignment when used as a statement, and a comparison when used as an expression.

IF statements

if 3 = 3 then
    print "hello world" // runs
end if

if not a then
    print "hello world" // runs, because a is implicitly 0
end if

if b = 2 then
elseif b = 3 then
elseif b = 4 then
else
end if

Truthy values are true and all numbers other than 0. It is an error to attempt to evaluate the truthiness of a string.

WHILE statements

a = 0
while a < 10
    print a // prints 0 1 2 3 4 5 6 7 8 9, each on a newline
    a = a + 1
wend

FOR statements

for x = 10 to 20
    print x // prints 10 11 12 13 14 15 16 17 18 19 20, each on a newline
next x

Functions

print a("hello", "world") // "helloworld"

function a(b, c)
    return b + c
end function

Functions can be defined before or after they are called. Return values can be specified with return, otherwise they will implicitly return 0. Recursion is also allowed.

For more examples, check out the examples directory.