We are about to switch to a new forum software. Until then we have removed the registration on this forum.
QScript is a very powerful and extensible scripting language that can be used to
1) evaluate mathematical expressions
2) evaluate simple algorithms (supports variables, conditional statements and iteration)
3) enables scripting of game objects and algorithms (see it in action here)
This library has gone through a complete refactoring so that this version is ~40% faster and will still will evaluate scripts created with V1.
Variable identifiers no longer have to be prefixed with the $ symbol and the examples have been updated to reflect this. New examples showing how to 'add a constant to the operator set' and how to 'script game objects' have been added.
The website has been completely updated and extended for version 2
println(Solver.evaluate("sqrt(5^2 + 12^2)"));
will calculate the hypotenuse of a triangle with sides 5 and 12.
This will calculate and display the prime numbers up to 100
String[] lines = {
"maxPrime = 90",
"println('Prime numbers <= ' + maxPrime)",
"println('2')",
"n = 3",
"REPEAT",
" rootN = int(sqrt(n))",
" notPrime = false;",
" i = 3",
" WHILE(i <= $rootN && NOT(notPrime))",
" notPrime = (n % i == 0)",
" i = i + 1",
" WEND",
" IF(notPrime == false)",
" println(n)",
" ENDIF",
" n = n + 2",
"UNTIL(n > maxPrime)"
};
Solver.evaluate(lines);
Some of the examples that come with the library use the G4P and Graphica libraries.
BTW in the next version I was thinking of including a complex number data type also operators to perform basic calculations(+-*/) and trigonometric / logarithmic functions. Do you think?
Comments
Hey quark its cool! Your real name is Peter? That's a nice name!
"Do you think?"
Yes, I do, sometime... ;-)
Since complex numbers are mostly used (in computer science) to represent a 2D coordinate, perhaps you should instead include a vector (and perhaps matrix?) type, no?
Ooops not sure why I missed the what but I know where and when :D
As a kid I was always very good at maths, it all seemed so logical and real I still remember the excitement at learning that there were imaginary numbers. Since then they have always had a facination for me, but you are right a vector data type would be better. Better still would be both. :)