901AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER902LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,903OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE904SOFTWARE.905906*/907908/**909* Get call result910*911* @param {ExpressionItem} obj - data info symbol912* @returns {number} - calc operators
*/function tcalc__evaluate(obj) { switch (obj.type) { case 'number': return parseFloat(obj.value); case '+': return tcalc__evaluate(obj.left) + tcalc__evaluate(obj.right); case '-': return tcalc__evaluate(obj.left) - tcalc__evaluate(obj.right); case '*': return tcalc__evaluate(obj.left) * tcalc__evaluate(obj.right); case '/': return tcalc__evaluate(obj.left) / tcalc__evaluate(obj.right); }}/** * Transmit values in object * * @param {string} formula - formula calc * @returns {ExpressionItem} - update data obj */function tcalc__parse(formula) { /** @type {FormulaOptions} */ var opts = { tokens: tcalc__tokenize(formula), position: 0, }; var result = tcalc__parseExpr(opts); if (opts.position !== opts.tokens.length) { throw new SyntaxError("unexpected '" + tcalc__peek(opts) + "'"); } return result;}/** * Get array formula * * @param {string} formula - formula calc * @returns {Array<string>} - split into an array */function tcalc__tokenize(formula) { var results = []; var tokenRegExp = /\s*([A-Za-z]+|[0-9.]+|\S)\s*/g; var m; while ((m = tokenRegExp.exec(formula))) { results.push(m[1]); } return results;}/** * Parse expr for plus and minus * * @param {FormulaOptions} opts - data object with a position index and array formula * @returns {ExpressionItem} - data formula */function tcalc__parseExpr(opts) { var expr = tcalc__parseMulExpr(opts); var t = tcalc__peek(opts); while (t === '+' || t === '-') { tcalc__consume(opts); var rhs = tcalc__parseMulExpr(opts); expr = { type: t, left: expr, right: rhs, }; t = tcalc__peek(opts); } return expr;}/** * Parse expr for multiplication and division * * @param {FormulaOptions} opts - data object with a position index and array formula * @returns {ExpressionItem} - data formula */function tcalc__parseMulExpr(opts) { var expr = tcalc__parsePrimaryExpr(opts); var t = tcalc__peek(opts); while (t === '*' || t === '/') { tcalc__consume(opts);