result = calculator(expression);
This function demonstrates how a simple expression calculator can be implemented in form of a recursive decent parser using basically the Strings.scanToken(..) and Strings.scanDelimiter(..) function.
The following operations are supported (pi=3.14.. is a predefined constant):
+, - *, / (expression) sin(expression) cos(expression) tan(expression) sqrt(expression) asin(expression) acos(expression) atan(expression) exp(expression) log(expression) pi
calculator("2+3*(4-1)"); // returns 11 calculator("sin(pi/6)"); // returns 0.5
function calculator import Modelica.Utilities.Strings; extends Modelica.Icons.Function; input String string "Expression that is evaluated"; output Real result "Value of expression"; end calculator;