- Just another BASIC-like language written in C++
- C++ code documentation can be found in DEV_DOCS.md directory
- Available at: https://github.com/gamecraftCZ/BasicPlusPlus
basicplusplus <file>
REM Personalised welcome script
INPUT "Whats your name: ", name
INPUT "How old are you: ", age
TONUM age
IF age < 12 THEN
PRINT "Hi kid!"
ELSE
PRINT "Welcome " + name
END- More examples in
examples/directory
- Can contain only english alphabet and underscore
a-zA-Z_ - Must not collide with builtin keywords
- Case sensitive
- String: variable length UTF-8 string
- Number: IEEE double-precision floating point number (64 bit)
- Boolean: true / false
Variable are declared and assigned using LET keyword
-
eg.
LET num = 14 -
eg.
LET VarOne = "Age: " + 14 -
You must use let even when assigning to already existing variable.
-
There is no such value as null. Every variable must have a value.
-
Number
-
Comparing
<,>,<=,>=,==,<><number> OP <number> -> <boolean>- eg.
7 > 5 -> true
-
Arithmetic
+,-,*,/<number> OP <number> -> <number>- eg.
7 / 2 -> 3.5 DivisionByZeroruntime error may occur.
-
Negation
-- <number> -> <number>- eg.
-7 -> -7
-
-
String
-
Joining
+<string> + <string> -> <string><string> + <number> -> <string><string> + <boolean> -> <string><number> + <string> -> <string><boolean> + <string> -> <string>- eg.
"I am from" + "Pilsen" -> "I am from Pilsen" - eg.
"I am " + 7 + "years old." -> "I am 7 years old." - eg.
"This statement is " + True -> "This statement is TRUE"
-
Comparing
==,<><string> OP <string> -> <boolean>- eg.
"Hello" == "hello" -> false - Comparing is case sensitive
-
-
Boolean
-
Negation
NOTNOT <boolean> -> <boolean>- eg.
NOT true -> false
-
Logic operators
AND,OR<boolean> OP <boolean> -> <boolean>- eg.
false OR 1 > 0 AND true -> true
-
- You can group expressions using
(and) - Precedence is from highest to lowest
()- grouping-- negation/,*-,+<,>,<=,>=,==,<>NOTANDOR
-
Keywords are case-insensitive
-
There is no such value as null. Every variable must have a value.
PRINT <expr>- Evaluates and prints expr to stdout with new line at the end
- <expr> can be
string,number,boolean numberis printed to two decimal places if decimal, otherwise it gets printed without decimal places if whole.- eg.
PRINT "Age: " + 7
INPUT <expr>, var- Evaluates and prints expr to stdout and reads user input to variable var
- <expr> can be
string,number,boolean - eg.
INPUT "Age: ", age
-
IF- Executes
expr, if result is true, execute expressions inthen_branch, else execute expressions inelse_branchif exists. - Else branch is optional
- Branches can contain multiple expressions
- Usage:
IF expr THEN ...then_branch... (ELSE ...else_branch...) END
- eg.
IF 5 < 7 THEN PRINT "Hello" PRINT "Low number" ELSE PRINT "Else never occures" END
- Executes
-
WHILE- Execute
codeuntilexprevaluates to true - Usage:
WHILE expr DO code END
- eg.
LET i = 0 WHILE i < 10 DO PRINT "Hello for " + i + " time." LET i = i + 1 END
- Execute
-
BREAK- Stops execution of
codeand exits the closestWHILEloop. LoopControlOutsideLooperror may occur if not inside a loop.
- Stops execution of
-
CONTINUE- Stops execution of
codeand continues at the beginning of the closestWHILEloop. LoopControlOutsideLooperror may occur if not inside a loop.
- Stops execution of
-
REM comment- Comment. Anything after
REMon that line is ignored.
- Comment. Anything after
-
TONUM var(, out_var)- Converts
varto number and saves the result toout_var - If only
varis defined, output is saved back tovar InvalidNumberFormaterror may occur if conversion failed
- Converts
-
TOSTR var(, out_var)- Converts
varto string and saves the result toout_var - If only
varis defined, output is saved back tovar
- Converts
-
RND var, lowerBound, upperBound- Generates random integer in range [lowerBound, upperBound) including lowerBound, excluding upperBound.
- Stores result to
var
If error occur, execution of code stops and error message is printed to stderr.
DivisionByZero= tried to divide by 0LoopControlOutsideLoop= usingcontinueorbreakoutside of loop bodyInvalidNumberFormat= parsing string that is not a number usingTONUMVariableNotDeclared= using variable that was not declared beforeConditionNotBoolean= condition inIForWHILEevaluated to non boolean value