An xBASIC interpreter library written in Rust. xBASIC is a language loosely based off of QBasic.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
Stephen cfe256ac1e Fix warning 19 saat önce
benches Give IO ownership to XBasic object 4 gün önce
examples Functions 1 ay önce
src Fix warning 19 saat önce
tests Added *= += -= /= ^= %= 19 saat önce
.gitignore Initial commit - does hello world 1 ay önce
Cargo.lock cut release 2 gün önce
Cargo.toml cut release 2 gün önce
LICENSE.md Add license 4 hafta önce
README.md Add repository 2 hafta önce
rustfmt.toml Initial commit - does hello world 1 ay önce

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.