This doc highlights and describes the differences in the programming language design and implementation between Interactive Small Basic (ISB) and Microsoft Small Basic (MSB).
Microsoft maintains a comprehensive introduction of Small Basic, which has already covered most programming language features of ISB.
Here I only listed the ISB-specific features.
' a will be set to 3.
a = 10 Mod 7
' 3 will be printed.
a = 3
If Not (a > 5) Then
Print(a)
EndIf
ISB reserves the keywords True
and False
as boolean literals. Boolean
literals and logical operators can be used to construct boolean expressions:
' "Passed" will be printed.
toCheck = True
a = 3
b = 4
c = 5
p2 = (a * a + b * b = c * c)
If toCheck and p2 Then
print("Passed")
EndIf
Note that in BASIC the token =
can be explained either as an assignment
operator or a logical equal operator, depending on the context. Please use
parentheses when necessary to avoid confusions.
ISB supports implicit value conversions among numbers, strings and boolean values, where the implicit conversions to and from boolean values are different with MSB.
' Implicit conversion from boolean values to strings.
a = True
b = False
print(a + ", " + b) ' True, False
' Implicit conversion from boolean values to numbers.
a = True ' True will be converted to 1
b = False ' False will be converted to 0
print(a - b) ' 1
' Implicit conversion from numbers to boolean values.
a = 0
b = True
print(a and b) ' False
a = 1
b = True
print(a and b) ' True
a = 0
b = 1
print(a and b) ' False
a = -1
b = True
print(a and b) ' True
a = 98765.4321
b = True
print(a and b) ' True
' Implicit conversion from strings to boolean values.
a = ""
b = True
print(a and b) ' False
a = "True"
b = True
print(a and b) ' True
a = "False"
b = True
print(a and b) ' True
a = "Anything"
b = True
print(a and b) ' True
As a lightweight embeddable scripting engine, ISB's standard library functions and properties are way less than MSB's.
Please type help
within ISB's interactive shell to get the up-to-date function
and property list of standard libraries.
I used C#'s reflection feature to support a straightforward structure to add and maintain library functions and properties.
See the standard libraries doc for the steps how to add more standard libraries.
See Engine.cs for the interfaces of the ISB Engine.
The compiler and the runtime support incremental invocations. Code pieces can be passed into the system one by one without losing internal states.
The client program can access some internal states, such as the stack top, to provide an interactive experience. E.g., it's easy to build an REPL (read-evaluate-print loop) on top of ISB to implement a command-line calculator.
See the REPL loop of the ISB interactive shell as an example.
I implemented an IR (intermediate representation) to split the compiler into a front-end and a back-end. The IR is a simple assembly language, looking a bit similar to WebAssembly.
See Instruction.cs for the instruction set of the IR.