morilib BASIC



Fundamental

morilib BASIC is a implementation of line-numbered BASIC by JavaScript and HTML5 canvas.
Statemtents can be separated by colon(:) like Microsoft BASIC.
The variable is a sequence of alphanumeric characters and dots which is not reserved as names of functions or statements.
The type of variable specifies by adding a character shown as follows.
%numeric type
!numeric type
#numeric type
$string type
morilib BASIC has only numeric and string type. Variables which has the same name but different type are distignished. Defalut type can be specified by DEFINT/DEFSNG/DEFDBL/DEFSTR statement.
Arrays are available by specifing indices like A(1, 2, 3). Dimension and upper limit of the arrays can be defined by DIM statement.


Expressions

Operators shown as follows are available in morilib BASIC.
(High priority)
Operators Association Description
(unary)- left to right inverts the sign
* / MOD left to right multiplicate, divide, or compute modulo, respectively
+ - left to right add or subtract, respectively
= left to right return true(-1) if the left value is equal to the right, otherwise false(0)
>< left to right return true(-1) if the left value is not equal to the right, otherwise false(0)
< left to right return true(-1) if the left value is less than the right, otherwise false(0)
> left to right return true(-1) if the left value is greater than the right, otherwise false(0)
<= left to right return true(-1) if the left value is less than or equal to the right, otherwise false(0)
>= left to right return true(-1) if the left value is greater than or equal to the right, otherwise false(0)
NOT left to right return true(-1) if the given value is false(0), otherwise false(0)
AND left to right logical product: return true(-1) if the both value are true, otherwise false(0)
OR left to right logical sum: return false(0) if the both value are false, otherwise true(-1)


Statements

variable=expr
assigns the expression value to the variable.

PRINT expr
prints the expression value to text screen.

IF expr THEN statement1 [ELSE statement2]
executes stamtent1 if expr is true, otherwise statement2.
Multiple statements can be described by separating colon(:).

GOTO linenumber
branchs to the statement which has linenumber.

GOSUB linenumber
calls the subroutine which is started from linenumber.
If RETURN statement has found in the subroutine, the statement next to GOSUB will be executed.

RETURN
returns the subroutine which is called by GOSUB.

END
ends the program.

STOP
interrupts the program. You can countine by "Continue" button.

FOR variable=expr1 TO expr2 [STEP expr3] / NEXT [varaible,...]
assigns expr1 to variable, executes until a NEXT statement is appeared, adds expr3 (default by 1) to variable, and backs to the FOR statement.
NEXT statement can specify variable names. The variable names must be specified from inner to outer.

NOTICE:
If you do not specify any varaible names, NEXT statement will be branched to the most nearly FOR statement. The phrase " the most nearly " does not mean balanced. For example, when you execute the program
10 FOR I=1 TO 4
20   FOR J=1 TO 4
30     PRINT J
40     GOTO 60
50   NEXT
60 NEXT
the result shown as follow in the text screen.
1
2
3
4
This result caused by branching to the most nearly FOR statement in line 20.
It is recommended that variable names of NEXT statement are specified explicitly.
That example shown as follows should be written.
10 FOR I=1 TO 4
20   FOR J=1 TO 4
30     PRINT J
40     GOTO 60
50   NEXT J
60 NEXT I

REM comment / 'comment
describes a comment. Any comments can write the end of statement.

DEFINT initial-character-of-variable[,initial-character-of-variable]
DEFSNG initial-character-of-variable[,initial-character-of-variable]
DEFDBL initial-character-of-variable[,initial-character-of-variable]
DEFSTR initial-character-of-variable[,initial-character-of-variable]
specifies the default type of variables which starts with initial-character-of-variable to %, !, # and $, respectively.
initial-character-of-variable can be specified by a range of characters as A-C.

COLOR color-coode,background
specifies the default color code. Color codes shown as follows are available.
0black
1blue
2red
3pink
4green
5cyan
6yellow
7white

LINE (X1,Y1)-(X2,Y2)[,color-coode][,B|BF]
draws the line to the graphic screen.
When B option is specified, this draws rectangle. When BF option is specified, this draws rectangle and fill it.

PSET (X1,Y1)[,color-coode]
draws the point to the graphic screen.

CIRCLE (X,Y),radius[,start-angle][,end-angle]
draws the circle or arc to the graphic screen.
start-angle and end-angle are start and end angle by radian, respectively. Angle 0 means right and π means left.

LOCATE [X][,Y]
specifies the location of cursor of text screen.
The defalt value of X is 0 and Y is current value of Y.

INPUT ["prompt";][variable,...]
inputs from text dialog and assigns to the variable.
When you want to input to many variables, the variable names should be separated by semicolon(;).


Functions

A function can only use in an expression. You can call a function without arguments by only the function name.
ABS(expr)
returns the absolute value of expr.

SGN(expr)
returns 1 when expr is positive, -1 when expr is negative, otherwise 0.

CINT(expr)
rounds expr.

INT(expr)
return the maximum integer which is not over expr.

FIX(expr)
trancates the decimal part of expr.

RND
returns a random number which is not negative and less than 1.

SIN(expr) / COS(expr) / TAN(expr) / ATN(expr)
computes sin, cos, tan, inverted tan of expr, respectively.
The result of ATN is radian.

SQR(expr)
computes square root of expr.

EXP(expr)
computes eexpr.

LOG(expr)
computes the natural logarithm of expr.

LEN(string)
returns the length of string.

MID$(string, index, length)
returns the substring which begins from the given index and has the given length.

LEFT$(string, length)
returns the substring of the given length from beginning of the string.

RIGHT$(string, length)
returns the substring of the given length from end of the string.

INSTR(string, search-string)
returns first index of search-string in string, or 0 if search-string is not found.
The index starts 1.

SPACE$(length)
returns the string which consists of whitespaces and has the given length.

STRING$(iteration, string-or-character-code)
repeats the given string by the given iteration and returns it.

STR$(number)
converts the given number to the string.

HEX$(number)
converts the given number to the hexadecimal string.

OCT$(number)
converts the given number to the octal string.

VAL(string)
converts the given string to the number.
The string is treated as hexadecimal when the string begins with &H. The string is treated as octal when the string begins with &O.

ASC(string)
converts the first character of the given string to the charcter code.

CHR$(code)
converts the character code to the corresponding string.

INKEY$ / INKEY
inputs a character from the keyboard and return the string(INKEY$) / character code(INKEY). This function will return 0 when no inputs from the keyboard.


Yuichiro Moriguchi
yuichiro-moriguchi@nifty.com