2.13. testcall.bas

[<<<] [>>>]

This program tests the function call features of ScriptBasic. This tests rather the syntax analyzer capabilities and less the run-time. The function call syntax is rather free and is implemented by a special syntax analysis function in the interpreter. It is allowed to call a function without the keyword Call is the function is already defined, but is needed if the function/sub is not defined yet (before the actual function/sub definition).

Calling a function can be with and without arguments, and the arguments can be enclosed between parentheses but it is not a must unless the function is called inside and expression. Using parenthesis can be confusing when the first argument is enclosed between parentheses but the argument list is not. For this case a special algorithm is applied that counts the opening and closing parentheses on the line following the function call. This is tested in this program.

Example testcall.bas :

Call MySub(1,2,3)
Call MySub 2,3,4
Call MySub(3),4,5
Call MySub 4,(5),6
Call MySub
Call MySub()
Call MySub(3)

sub MySub(a,b,c) ByVal a,b,c if not isdefined(a) then a = "-" if not isdefined(b) then b = "-" if not isdefined(c) then c = "-" print a," ",b," ",c print "\n"

end sub

MySub(1,2,3) MySub 2,3,4 MySub(3),4,5 MySub 4,(5),6 MySub MySub() MySub(3) Call MySub(1,2,3) Call MySub 2,3,4 Call MySub(3),4,5 Call MySub 4,(5),6 Call MySub Call MySub() Call MySub(3)

Result executing testcall.bas :

Possible error messages sent to stderr:


[<<<] [>>>]