- 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
DivisionByZero
runtime 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
NOT
NOT <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/
,*
-
,+
<
,>
,<=
,>=
,==
,<>
NOT
AND
OR
-
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
number
is 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_branch
if 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
code
untilexpr
evaluates 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
code
and exits the closestWHILE
loop. LoopControlOutsideLoop
error may occur if not inside a loop.
- Stops execution of
-
CONTINUE
- Stops execution of
code
and continues at the beginning of the closestWHILE
loop. LoopControlOutsideLoop
error may occur if not inside a loop.
- Stops execution of
-
REM comment
- Comment. Anything after
REM
on that line is ignored.
- Comment. Anything after
-
TONUM var(, out_var)
- Converts
var
to number and saves the result toout_var
- If only
var
is defined, output is saved back tovar
InvalidNumberFormat
error may occur if conversion failed
- Converts
-
TOSTR var(, out_var)
- Converts
var
to string and saves the result toout_var
- If only
var
is 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
= usingcontinue
orbreak
outside of loop bodyInvalidNumberFormat
= parsing string that is not a number usingTONUM
VariableNotDeclared
= using variable that was not declared beforeConditionNotBoolean
= condition inIF
orWHILE
evaluated to non boolean value