Crates.io | xbasic |
lib.rs | xbasic |
version | 0.3.2 |
source | src |
created_at | 2020-11-08 23:57:20.694895 |
updated_at | 2021-05-24 16:38:33.947474 |
description | A library that allows adding a scripting language onto your project with ease. This lets your users write their own arbitrary logic. |
homepage | |
repository | https://git.scd31.com/stephen/xbasic |
max_upload_size | |
id | 310125 |
size | 131,754 |
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:
PRINT
and INPUT
work withTODO:
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.
As mentioned already, xBASIC is a very simple language. Like other BASIC languages, it is designed to be easy for beginners to understand.
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.
input a // Read in a line, store it in a
input b // Read in another line, store it in b
a = 3
print a // "3"
print b // "0"
All variables are implicitly initialized to 0.
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 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.
a = 0
while a < 10
print a // prints 0 1 2 3 4 5 6 7 8 9, each on a newline
a += 1
wend
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
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.