import ndef.parser.*;
var parser:Parser=new Parser(["x", "y", "z"]);
var expression:String="2*PI*sin(x)*(y+z)^2";
var parsedexpression:Array=parser.parse(expression);
if (parser.success) {
parsedexpression=parser.simplify(parsedexpression); //optional
var result1:Number=parser.eval(parsedexpression, [1,2,3]);
var result2:Number=parser.eval(parsedexpression, [3,2,1]);
...
}
else{
trace(parser.errormsg);
}
variable names:
alphanumeric, first character alphabetic.
the simplify()-method is useful when an expression is evaluated multiple times.
in the above example, 2*PI would be simplified (6.28..) making evaluation faster!