ViuaBasic is a BASIC compiler for ViuaVM written in Java.
- stable - <no release yet>
- development - v0.0.3/ViuaBasic.jar
Usage: java -jar ViuaBasic.jar <input_file.bas> <output_file.asm>
Input is a UTF-8 encoded BASIC source, output is a UTF-8 encoded ViuaVM assembly.
Single instruction per line. Line numbers are optional, when ommited line numbers from source file are used.
All instructions, variable names and keywords are case insensitive. String literals are case sensitive, double quote bounded, double quotes inside strings are escaped by repeating them.
Instruction arguments are comma delimited. Dot is used as a decimal separator. Variables have defined types that cannot be changed.
All math expressions are evaluated as floating point, and when result is stored in integer variable then it is rounded half up.
For example, two equivalent hello worlds:
10 PRINT "2.2 * 3.3 = ",2.2*3.3 20 LET A : INTEGER = 0 30 PRINT "Hello ""WORLD"" ! (",A,")" 40 LET A = A + 1 50 GOTO 30
print "2.2 * 3.3 = ", 2.2 * 3.3 let a:integer=0 print "Hello ""WORLD"" ! (", A, ")" let a=a+1 goto 3
REM makes comment.
REM <comment>where comment can be anything, it will be ignored.
LABEL sets a target point for a jump.
LABEL <label_name>where label name must be unique single word, case insensitive.
GOTO performs unconditional jump.
GOTO <line_number> GOTO <label_name>where line number or label must exist.
PRINT sends a line of text to output.
PRINT <print_list>where print list is a comma separated list of string literals, variable names or math expressions.
LET assigns value to a variable or array element.
LET <variable_name> [: <variable_type>] = <variable_value> LET <variable_name> (<array_index>) = <variable_value>where variable name must be unique single word, case insensitive. First assignment to a variable must have type definition. Three types are available:
FOR begins loop.
FOR <variable_name> = <from_expression> TO <to_expression> [STEP <step_expression>]where variable must be new or existing integer or floating point. If variable exists it will be used and its value set to from expression. If variable is new it will be created as integer. For, to and step expressions are evaluated as integer or floating point math expressions, depending on variable type. Step is optional and defaults to 1. After loop ends variable value is not changed and can be used. Variable value can be changed inside loop to break loop.
NEXT ends loop.
NEXT <variable_name>where variable must be existing loop variable.
IF performs conditional jump.
IF <condition> THEN <line_number_or_label> [ELSE <line_number_or_label>]Multi line if:
IF <condition> THEN .. block of instructions [ELSE .. block of instructions] ENDIFwhere condition is a logical expression and line number or label must exist.
DIM creates an array.
DIM <variable_name> (<array_dimensions>) <variable_type> [= <initial_value>]where variable name must be unique single word, case insensitive. Array dimensions is a comma separated list of integer expressions denoting array size in each dimension. Arrays can have 1 or more dimensions, dimension sizes must be greater than zero. All elements of an array hold values of the same type. Initial value is optional expression, integer or float or print list depending on array type, when ommited it defaults to zero or empty string. Arrays cannot be redefined and resized.
Math expressions can use following operators:
a + b - addition
a - b - substraction
a * b - multiplication
a / b - division
a % b - modulo
a ^ b - power of
and following functions:
ABS(a) - absolute value
EXP(a) - exponent
LOG(a) - logarithm
Unary minus and parentheses are supported.
Logical expressions can use following operators:
a = b - equals
a < b - less than
a > b - greater than
a <= b - less than or equals
a >= b - greater than or equals
a <> b - not equals
a OR b - disjunction
a AND b - conjunction
NOT a - negation
Parentheses are supported.