Evaluate

by Yota
Evaluate
An expression parser that supplies reusable machines, similar to Regex.
ID:110482
 
This evaluation library is intended for games that have to reuse a single expression many times with changing variables.

Full documentation is included. (Unless I forgot something.)

Operations supported:
( ) ?: + - * ** / \ % & | ^ ~ ! && || < > = == != <= >= d e (Multiplication may be implicit.)
'd' is a dice roll operator, 'e' is a scientific notation operator.
= is the same as ==.

There are a number of basic functions pre-packaged with the library, and you can add your own.

So in closing, please report any and all bugs or problems on the forum. Thank you!


A quick example of the Evaluate procedures in code.

var/expr = expr_Parse("(\[strength]+\[weaponBonus]+3d6)*\[pi]") // Parse the expression.
expr = expr_Optimize(expr, commonVars) // Optimize the expression.
return expr_Evaluate(expr, myVars) // Evaluate the expression.

var/expr = expr_ParseOptimize("...", commonVars) // Shorthand procedures.

return expr_ParseEvaluate("...", myVars) // Evaluate a one-time expression.


Each of these procedures have multiple types of return values, so I highly suggest you read through EvaluateHelp.htm (included) before you implement anything so you don't get caught off guard.