Code: Select all
var s = "\"Hello World\"";
print( s );
s = "Hello \n World";
print( s );
Code: Select all
var s = "\"Hello World\"";
print( s );
s = "Hello \n World";
print( s );
Code: Select all
var a = 88
var b = 99
var c = a + b
Code: Select all
var b 44;
print(b);
Code: Select all
var 44;
print(b);
print(c);
print(h);
var c = 99;
print(c);
Illegal Function Call Number
b
c
h
99
0.01092517290982586
Code: Select all
var b 44;
print(b);
Code: Select all
var b 44+44;
print(b);
Code: Select all
var 44;
The line that contains an error does not get executed but the line that relies upon correct execution of the
erroneous line does. That's not good.
Code: Select all
? curLine.tostring : sleep
Code: Select all
var arr = [1,2,3,4,5];
var x = fix( rnd*arr.length );
print( x );
Code: Select all
var arr = [1,2,3,4,5];
var idx = rnd*arr.length;
print( arr[ fix(idx) ] );
jsb_parser.pp.exe >jsb_parser.output
Code: Select all
function is_jsb_func( byref s as string ) as integer
[/quote]
What is_jsb_func does is lookup a string in a list of strings using instr. And before the search is performed it performs string concatenation. String concatenation is expensive. And the algorithm behind instr (boyer moore) does well with long patterns but isn't so hot when used in combination with short strings.
Most if not all compiler/interpreter packages resort to using hash tables to perform lookup of a string in a table of strings. In case of is_jsb_func you can also use a static solution that could look something like this
[code]
function check_func(byref s as string) as integer
select case as const s[0]
case asc("+"),asc("/"),asc("*"),asc("^"),asc("%")
select case s
case "+","/","*","^","%":return 1
end select
case asc("a")
select case s
case "abs","acos","asc","asin","atan","atan2": return 1
end select
case asc("b")
if s = "beep" then return 1
case asc("c")
select case s
case "chr","clear","cls","cos":return 1
end select
case asc("f")
select case s
case "first","fix","frac","function": return 1
end select
case asc("i")
select case s
case "instr","int": return 1
end select
case asc("l")
select case s
case "last","lcase","left","len","length","load_file_as_string","log": return 1
end select
case asc("m")
select case s
case "mid","mod":return 1
end select
case asc("p")
select case s
case "pluck","pop","print","push","push_back":return 1
end select
case asc("r")
select case s
case "right","rnd": return 1
end select
case asc("s")
select case s
case "sgn","sin","size","sleep","slice","split","sqr":return 1
end select
case asc("t")
select case s
case "tan","typeof": return 1
end select
case asc("u")
if s = "ucase" then return 1
case asc("v")
if s = "var" then return 1
case else
return 0
end select
return 0
end function
Code: Select all
Function InStr_Naive ( byref strbig As String, byref strlittle As String ) As Integer
Dim As Integer ll = Len(strlittle)-1, lb = Len(strbig)-1
Dim As Integer OK = 0
For i As Integer = 0 To lb
If strbig[i] = strlittle[0] Then
If strbig[i+ll] = strlittle[ll] Then
OK = i+1
For ii As Integer = i To i+ll
If strbig[ii] <> strlittle[ ii - i ] Then OK = 0:Exit For
Next
Else
i+=ll
Endif
Endif
If OK Then Return OK
Next
Return OK
End Function
dim as string all_func_names = ",var,function,print,sqr,+,/,*,^,%," _
+ "sin,cos,tan,asin,acos,atan,atan2,sqr,abs," _
+ "log,fix,int,frac,sgn,rnd,mod," _
+ "len,asc,chr,left,right,mid,lcase,ucase,instr," _
+ "pluck,load_file_as_string,beep," _
+ "length,pop,push,sleep,push_back,last,first," _
+ "size,split,slice,typeof,clear,cls," _
+ ""
dim as double tnow
dim as integer idx
tnow = timer
for i as integer = 0 to 100000
idx = instr_naive( all_func_names, ",cls," )
next i
? timer - tnow
? idx
sleep
tnow = timer
for i as integer = 0 to 100000
idx = instr( all_func_names, ",cls," )
next i
? timer - tnow
? idx
sleep
Code: Select all
case asc("+"), asc("/"), asc("*"), asc("%"), asc("^")
check_quotes()
if check1 <> "" then
var_or_func(tokens)
endif
addToken(_MATHOP_,ascii(s[i]),tokens)
case 9, 10, 13, 32
check_quotes()
Code: Select all
case asc("+"), asc("/"), asc("*"), asc("%"), asc("^")
Code: Select all
case 9, 10, 13, 32
check_quotes()
Code: Select all
case asc(!"\t"), asc(!"\n"),asc(!"\r"),asc(!"\"")
check_quotes()
Code: Select all
case 34
if inQuotes = 0 then inQuotes = 1 else inQuotes = 0
Code: Select all
case asc(!"\"")
if inQuotes = 0 then inQuotes = 1 else inQuotes = 0
Code: Select all
while (1) ;
Code: Select all
while (1) {;};
Code: Select all
var s = "hello world";
var a = [sin(55),len(s),s];
Code: Select all
var s = "hello";
var t = "world";
var a = {s:t};
Why not use asc for the values at the second case label as well
Code: Select all
var a = [];
var s = "hello world";
array.push_back( sin(55) );
array.push_back( len(s) );
array.push_back( s );
Code: Select all
var s = "hello";
var t = "world";
var a = {s:t};
Users browsing this forum: No registered users and 7 guests