QScript - runtime expression and algorithm evaluator

I am pleased to announce the release of a new library - QScript.

This is a very powerful and extensible scripting language that can be used to evaluate mathematical expressions and algorithms at runtime e.g.

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.

The library is feature rich and extensible - visit the website for comprehensive guides to this library.

Until it is available through the PDE you can download it from here and follow the installation instructions here.

Have fun!

Comments

  • edited October 2013

    Impressive, although I am always skeptical when somebody comes up with yet another scripting language... :-)

    Another thing to learn (even if simple), when we have already lot of powerful scripting languages, from the built-in JavaScript (Rhino engine) to Lua (several implementations), from the venerable BeanShell to Groovy, and so on.

    Of course, I suppose your library has probably in its favor simplicity and being lightweight.

    And making a language is always fun and interesting. :-D

    Anyway, I am sure lot of Processing users will find it useful, given the number of people asking for expression evaluators!

  • I did not create it to compete with existing scripting languages - it is never going to be that good :)

    As you noticed the the library is very simple to use and is lightweight (just 139k) and as an expression evaluator perhaps that will satisfy most users.

    I think its strength lies in the ease of adding new operators/functions and scripting events (even for quite novice programmers) means that it can be flavoured for a particular discipline. Also the new operators don't have to be mathematical, they could have graphical or game control output. I could imagine it being used in an application to teach sequence / selection/ iteration through game play. Just needs someone with the imagination to do something different.

    But as you suggest it was something I fancied creating for a long-long time and the journey was challenging, interesting and above all great fun. :D

  • edited February 2014

    Sorry to revive an old post, but I was wondering how you successfully got QScriptIDE.pde to work in the Javascript environment. The sketch is uploaded to OpenProcessing, so I have to assume you were able to get it to run locally in Javascript, but whenever I attempt to do so I'm met with a blank frame where the gui should be, even though all of the instructions and flavor text appear at the bottom. I'd really like to use your library as an expression parser in a student project I'm working on, but I need it to work in Javascript, and it'd be nice to have something that works as a starting point. Thanks in advance!

    Edit: I know that processing.js generally doesn't handle importing java libraries (QScript for example) very well, which is mostly what I'm wondering about.

  • The sketch is uploaded to OpenProcessing, so I have to assume you were able to get it to run locally in Javascript

    False assumption, OpenProcessing still accepts Java applets and the sketch on OpenProcessing is a Java applet.

    all of the instructions and flavor text appear at the bottom

    Processing does this by parsing the comments placed at the start of the sketch code.

Sign In or Register to comment.