A simple parse-from-text way to make calculation in C#. Supports variables too
// SYNTAX:
// accepted symbols:
// > numbers (0-9)
// > variables name in format of $NAME (ie only uppercase, literal, and start with $ string)
// > operators such as +, -, *, and /
// > array declaration in the format of @ARRAY=[ <elements> ] where elements are numbers separated by commas and no space (ie @ARRAY=[ 1,2 ])
// > array index extraction in format of ARRAY[<index>] where <index> is a decimal integer number
// every symbols must be separated by only ONE space
// to assign a variable syntax is:
// $VARNAME=( <expression> )
// nested variables assignment are forbidden
// parentheses are not accepted as precedence operator, to simulate that define a temp variable and process that variable in the next line. eg to make 2 / ( 2 + 9 ):
// $PRECEDENCE=( 2 + 9 )
// 2 / $PRECEDENCE
// CALLER OPTIONS:
// > create an Environment object
// > if wanted it''s possible to use the registerVariable(), unregisterVariable() and getVariableValue() to get and set entual variables name and value. Those variables name must have the correct syntax as specified above.
// > create an Evaluator object. Constructor wants an Environment to resolve variables names and other functionality. Use the created Environment object. If no Environment are setted an empty one will be generated by the evaluator itself.
// > the evaluate() function in the Evaluator context provides the evaluation function itself. To use that it's needed to create a Line object which rapresent a line of scripting code. That line needs to comply with the syntax above or Exceptions are thrown. That function returns a string rapresenting the result. Eventual assigned variables are setted in the provided environment. NOTE that eventual environment changes override previous variable setings.
// UML:
// <<abstract>>
// Syntax <----------------<<use>> --------- Line <-------<<use>>------- Evaluator --------<<use>>-------> Environment
// + _of()_ + AssignmentType + environment + getVariableValue()
// | + AssignmentVar + evaluate() + registerVariable()
// ______|___________________________ + unregisterVariable()
// | | | |
// Number Operand IndirectValue Assignment
// |
// _______|_________
// | |
// Variable ArrayValue
//
//
// INSIDE Environment nested class are defined (as private)
// <<abstract>>
// Object
// ____|______
// | |
// ArrayObj VariableObj
//
//
//