WOLFRAM SYSTEM MODELER
calculatorInterpreter to evaluate simple expressions consisting of +, -, *, /, (), sin(), cos(), tan(), sqrt(), asin(), acos(), atan(), exp(), log(), pi |
SystemModel["Modelica.Utilities.Examples.calculator"]
This information is part of the Modelica Standard Library maintained by the Modelica Association.
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
string |
Type: String Description: Expression that is evaluated |
---|
result |
Type: Real Description: Value of expression |
---|