1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009 |
- (function webpackUniversalModuleDefinition(root, factory) {
- if(typeof exports === 'object' && typeof module === 'object')
- module.exports = factory();
- else if(typeof define === 'function' && define.amd)
- define([], factory);
- else if(typeof exports === 'object')
- exports["Mexp"] = factory();
- else
- root["Mexp"] = factory();
- })(self, function() {
- return /******/ (() => { // webpackBootstrap
- /******/ var __webpack_modules__ = ({
- /***/ 28:
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- var Mexp=__webpack_require__(733);
- Mexp.prototype.formulaEval = function () {
- "use strict";
- var stack=[],pop1,pop2,pop3;
- var disp=[];
- var temp='';
- var arr=this.value;
- for(var i=0;i<arr.length;i++){
- if(arr[i].type===1||arr[i].type===3){
- disp.push({value:arr[i].type===3?arr[i].show:arr[i].value,type:1});
- }
- else if(arr[i].type===13){
- disp.push({value:arr[i].show,type:1});
- }
- else if(arr[i].type===0){
- disp[disp.length-1]={value:arr[i].show+(arr[i].show!="-"?"(":"")+disp[disp.length-1].value+(arr[i].show!="-"?")":""),type:0};
- }
- else if(arr[i].type===7){
- disp[disp.length-1]={value:(disp[disp.length-1].type!=1?"(":"")+disp[disp.length-1].value+(disp[disp.length-1].type!=1?")":"")+arr[i].show,type:7};
- }
- else if(arr[i].type===10){
- pop1=disp.pop();
- pop2=disp.pop();
- if(arr[i].show==='P'||arr[i].show==='C')disp.push({value:"<sup>"+pop2.value+"</sup>"+arr[i].show+"<sub>"+pop1.value+"</sub>",type:10});
- else disp.push({value:(pop2.type!=1?"(":"")+pop2.value+(pop2.type!=1?")":"")+"<sup>"+pop1.value+"</sup>",type:1});
- }
- else if(arr[i].type===2||arr[i].type===9){
- pop1=disp.pop();
- pop2=disp.pop();
- disp.push({value:(pop2.type!=1?"(":"")+pop2.value+(pop2.type!=1?")":"")+arr[i].show+(pop1.type!=1?"(":"")+pop1.value+(pop1.type!=1?")":""),type:arr[i].type});
- }
- else if(arr[i].type===12){
- pop1=disp.pop();
- pop2=disp.pop();
- pop3=disp.pop();
- disp.push({value:arr[i].show+"("+pop3.value+","+pop2.value+","+pop1.value+")",type:12});
- }
- }
- return disp[0].value;
- };
- module.exports=Mexp;
- /***/ }),
- /***/ 618:
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- var Mexp = __webpack_require__(178)
- function inc (arr, val) {
- for (var i = 0; i < arr.length; i++) {
- arr[i] += val
- }
- return arr
- }
- var token = [
- 'sin',
- 'cos',
- 'tan',
- 'pi',
- '(',
- ')',
- 'P',
- 'C',
- ' ',
- 'asin',
- 'acos',
- 'atan',
- '7',
- '8',
- '9',
- 'int',
- 'cosh',
- 'acosh',
- 'ln',
- '^',
- 'root',
- '4',
- '5',
- '6',
- '/',
- '!',
- 'tanh',
- 'atanh',
- 'Mod',
- '1',
- '2',
- '3',
- '*',
- 'sinh',
- 'asinh',
- 'e',
- 'log',
- '0',
- '.',
- '+',
- '-',
- ',',
- 'Sigma',
- 'n',
- 'Pi',
- 'pow',
- '&'
- ]
- var show = [
- 'sin',
- 'cos',
- 'tan',
- 'π',
- '(',
- ')',
- 'P',
- 'C',
- ' ',
- 'asin',
- 'acos',
- 'atan',
- '7',
- '8',
- '9',
- 'Int',
- 'cosh',
- 'acosh',
- ' ln',
- '^',
- 'root',
- '4',
- '5',
- '6',
- '÷',
- '!',
- 'tanh',
- 'atanh',
- ' Mod ',
- '1',
- '2',
- '3',
- '×',
- 'sinh',
- 'asinh',
- 'e',
- ' log',
- '0',
- '.',
- '+',
- '-',
- ',',
- 'Σ',
- 'n',
- 'Π',
- 'pow',
- '&'
- ]
- var eva = [
- Mexp.math.sin,
- Mexp.math.cos,
- Mexp.math.tan,
- 'PI',
- '(',
- ')',
- Mexp.math.P,
- Mexp.math.C,
- ' '.anchor,
- Mexp.math.asin,
- Mexp.math.acos,
- Mexp.math.atan,
- '7',
- '8',
- '9',
- Math.floor,
- Mexp.math.cosh,
- Mexp.math.acosh,
- Math.log,
- Math.pow,
- Math.sqrt,
- '4',
- '5',
- '6',
- Mexp.math.div,
- Mexp.math.fact,
- Mexp.math.tanh,
- Mexp.math.atanh,
- Mexp.math.mod,
- '1',
- '2',
- '3',
- Mexp.math.mul,
- Mexp.math.sinh,
- Mexp.math.asinh,
- 'E',
- Mexp.math.log,
- '0',
- '.',
- Mexp.math.add,
- Mexp.math.sub,
- ',',
- Mexp.math.sigma,
- 'n',
- Mexp.math.Pi,
- Math.pow,
- Mexp.math.and
- ]
- var preced = {
- 0: 11,
- 1: 0,
- 2: 3,
- 3: 0,
- 4: 0,
- 5: 0,
- 6: 0,
- 7: 11,
- 8: 11,
- 9: 1,
- 10: 10,
- 11: 0,
- 12: 11,
- 13: 0,
- 14: -1 // will be filtered after lexer
- } // stores precedence by types
- var type = [
- 0, 0, 0, 3, 4, 5, 10, 10, 14, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 10, 0, 1, 1, 1, 2, 7, 0, 0, 2, 1, 1,
- 1, 2, 0, 0, 3, 0, 1, 6, 9, 9, 11, 12, 13, 12, 8, 9
- ]
- /*
- 0 : function with syntax function_name(Maths_exp)
- 1 : numbers
- 2 : binary operators like * / Mod left associate and same precedence
- 3 : Math constant values like e,pi,Cruncher ans
- 4 : opening bracket
- 5 : closing bracket
- 6 : decimal
- 7 : function with syntax (Math_exp)function_name
- 8: function with syntax function_name(Math_exp1,Math_exp2)
- 9 : binary operator like +,-
- 10: binary operator like P C or ^
- 11: ,
- 12: function with , seperated three parameters and third parameter is a string that will be mexp string
- 13: variable of Sigma function
- */
- var type0 = {
- 0: true,
- 1: true,
- 3: true,
- 4: true,
- 6: true,
- 8: true,
- 9: true,
- 12: true,
- 13: true,
- 14: true
- } // type2:true,type4:true,type9:true,type11:true,type21:true,type22
- var type1 = {
- 0: true,
- 1: true,
- 2: true,
- 3: true,
- 4: true,
- 5: true,
- 6: true,
- 7: true,
- 8: true,
- 9: true,
- 10: true,
- 11: true,
- 12: true,
- 13: true
- } // type3:true,type5:true,type7:true,type23
- var type1Asterick = {
- 0: true,
- 3: true,
- 4: true,
- 8: true,
- 12: true,
- 13: true
- }
- var empty = {}
- var type3Asterick = {
- 0: true,
- 1: true,
- 3: true,
- 4: true,
- 6: true,
- 8: true,
- 12: true,
- 13: true
- } // type_5:true,type_7:true,type_23
- var type6 = {
- 1: true
- }
- var newAr = [
- [],
- [
- '1',
- '2',
- '3',
- '7',
- '8',
- '9',
- '4',
- '5',
- '6',
- '+',
- '-',
- '*',
- '/',
- '(',
- ')',
- '^',
- '!',
- 'P',
- 'C',
- 'e',
- '0',
- '.',
- ',',
- 'n',
- ' ',
- '&'
- ],
- ['pi', 'ln', 'Pi'],
- ['sin', 'cos', 'tan', 'Del', 'int', 'Mod', 'log', 'pow'],
- ['asin', 'acos', 'atan', 'cosh', 'root', 'tanh', 'sinh'],
- ['acosh', 'atanh', 'asinh', 'Sigma']
- ]
- function match (str1, str2, i, x) {
- for (var f = 0; f < x; f++) {
- if (str1[i + f] !== str2[f]) {
- return false
- }
- }
- return true
- }
- Mexp.addToken = function (tokens) {
- for (var i = 0; i < tokens.length; i++) {
- var x = tokens[i].token.length
- var temp = -1
- // newAr is a specially designed data structure index of 1d array = length of tokens
- newAr[x] = newAr[x] || []
- for (var y = 0; y < newAr[x].length; y++) {
- if (tokens[i].token === newAr[x][y]) {
- temp = token.indexOf(newAr[x][y])
- break
- }
- }
- if (temp === -1) {
- token.push(tokens[i].token)
- type.push(tokens[i].type)
- if (newAr.length <= tokens[i].token.length) {
- newAr[tokens[i].token.length] = []
- }
- newAr[tokens[i].token.length].push(tokens[i].token)
- eva.push(tokens[i].value)
- show.push(tokens[i].show)
- } else {
- // overwrite
- token[temp] = tokens[i].token
- type[temp] = tokens[i].type
- eva[temp] = tokens[i].value
- show[temp] = tokens[i].show
- }
- }
- }
- function tokenize (string) {
- var nodes = []
- var length = string.length
- var key, x, y
- for (var i = 0; i < length; i++) {
- if (i < length - 1 && string[i] === ' ' && string[i + 1] === ' ') {
- continue
- }
- key = ''
- for (
- x = string.length - i > newAr.length - 2 ? newAr.length - 1 : string.length - i;
- x > 0;
- x--
- ) {
- if (newAr[x] === undefined) continue
- for (y = 0; y < newAr[x].length; y++) {
- if (match(string, newAr[x][y], i, x)) {
- key = newAr[x][y]
- y = newAr[x].length
- x = 0
- }
- }
- }
- i += key.length - 1
- if (key === '') {
- throw new Mexp.Exception("Can't understand after " + string.slice(i))
- }
- var index = token.indexOf(key)
- nodes.push({
- index: index,
- token: key,
- type: type[index],
- eval: eva[index],
- precedence: preced[type[index]],
- show: show[index]
- })
- }
- return nodes
- }
- Mexp.lex = function (inp, tokens) {
- 'use strict'
- var changeSignObj = {
- value: Mexp.math.changeSign,
- type: 0,
- pre: 21,
- show: '-'
- }
- var closingParObj = {
- value: ')',
- show: ')',
- type: 5,
- pre: 0
- }
- var openingParObj = {
- value: '(',
- type: 4,
- pre: 0,
- show: '('
- }
- var str = [openingParObj]
- var ptc = [] // Parenthesis to close at the beginning is after one token
- var inpStr = inp
- var allowed = type0
- var bracToClose = 0
- var asterick = empty
- var prevKey = ''
- var i
- if (typeof tokens !== 'undefined') {
- Mexp.addToken(tokens)
- }
- var obj = {}
- var nodes = tokenize(inpStr)
- for (i = 0; i < nodes.length; i++) {
- var node = nodes[i]
- if (node.type === 14) {
- if (
- i > 0 &&
- i < nodes.length - 1 &&
- nodes[i + 1].type === 1 &&
- (nodes[i - 1].type === 1 || nodes[i - 1].type === 6)
- ) { throw new Mexp.Exception('Unexpected Space') }
- continue
- }
- var cToken = node.token
- var cType = node.type
- var cEv = node.eval
- var cPre = node.precedence
- var cShow = node.show
- var pre = str[str.length - 1]
- var j
- for (j = ptc.length; j--;) {
- // loop over ptc
- if (ptc[j] === 0) {
- if ([0, 2, 3, 4, 5, 9, 11, 12, 13].indexOf(cType) !== -1) {
- if (allowed[cType] !== true) {
- throw new Mexp.Exception(cToken + ' is not allowed after ' + prevKey)
- }
- str.push(closingParObj)
- allowed = type1
- asterick = type3Asterick
- ptc.pop()
- }
- } else break
- }
- if (allowed[cType] !== true) {
- throw new Mexp.Exception(cToken + ' is not allowed after ' + prevKey)
- }
- if (asterick[cType] === true) {
- cType = 2
- cEv = Mexp.math.mul
- cShow = '×'
- cPre = 3
- i = i - 1
- }
- obj = {
- value: cEv,
- type: cType,
- pre: cPre,
- show: cShow
- }
- if (cType === 0) {
- allowed = type0
- asterick = empty
- inc(ptc, 2)
- str.push(obj)
- if (nodes[i + 1].type !== 4) {
- str.push(openingParObj)
- ptc.push(2)
- }
- // bracToClose++
- } else if (cType === 1) {
- if (pre.type === 1) {
- pre.value += cEv
- inc(ptc, 1)
- } else {
- str.push(obj)
- }
- allowed = type1
- asterick = type1Asterick
- } else if (cType === 2) {
- allowed = type0
- asterick = empty
- inc(ptc, 2)
- str.push(obj)
- } else if (cType === 3) {
- // constant
- str.push(obj)
- allowed = type1
- asterick = type3Asterick
- } else if (cType === 4) {
- inc(ptc, 1)
- bracToClose++
- allowed = type0
- asterick = empty
- str.push(obj)
- } else if (cType === 5) {
- if (!bracToClose) {
- throw new Mexp.Exception('Closing parenthesis are more than opening one, wait What!!!')
- }
- bracToClose--
- allowed = type1
- asterick = type3Asterick
- str.push(obj)
- inc(ptc, 1)
- } else if (cType === 6) {
- if (pre.hasDec) {
- throw new Mexp.Exception('Two decimals are not allowed in one number')
- }
- if (pre.type !== 1) {
- pre = {
- value: 0,
- type: 1,
- pre: 0
- } // pre needs to be changed as it will the last value now to be safe in later code
- str.push(pre)
- // inc(ptc, 1)
- }
- allowed = type6
- inc(ptc, 1)
- asterick = empty
- pre.value += cEv
- pre.hasDec = true
- } else if (cType === 7) {
- allowed = type1
- asterick = type3Asterick
- inc(ptc, 1)
- str.push(obj)
- }
- if (cType === 8) {
- allowed = type0
- asterick = empty
- inc(ptc, 4)
- str.push(obj)
- // str.push(openingParObj)
- if (nodes[i + 1].type !== 4) {
- str.push(openingParObj)
- ptc.push(4)
- }
- } else if (cType === 9) {
- if (pre.type === 9) {
- if (pre.value === Mexp.math.add) {
- pre.value = cEv
- pre.show = cShow
- inc(ptc, 1)
- } else if (pre.value === Mexp.math.sub && cShow === '-') {
- pre.value = Mexp.math.add
- pre.show = '+'
- inc(ptc, 1)
- }
- } else if (
- pre.type !== 5 &&
- pre.type !== 7 &&
- pre.type !== 1 &&
- pre.type !== 3 &&
- pre.type !== 13
- ) {
- // changesign only when negative is found
- if (cToken === '-') {
- // do nothing for + token
- // don't add with the above if statement as that will run the else statement of parent if on Ctoken +
- allowed = type0
- asterick = empty
- inc(ptc, 2).push(2)
- str.push(changeSignObj)
- str.push(openingParObj)
- }
- } else {
- str.push(obj)
- inc(ptc, 2)
- }
- allowed = type0
- asterick = empty
- } else if (cType === 10) {
- allowed = type0
- asterick = empty
- inc(ptc, 2)
- str.push(obj)
- } else if (cType === 11) {
- allowed = type0
- asterick = empty
- str.push(obj)
- } else if (cType === 12) {
- allowed = type0
- asterick = empty
- inc(ptc, 6)
- str.push(obj)
- if (nodes[i + 1].type !== 4) {
- str.push(openingParObj)
- ptc.push(6)
- }
- } else if (cType === 13) {
- allowed = type1
- asterick = type3Asterick
- str.push(obj)
- }
- inc(ptc, -1)
- prevKey = cToken
- }
- for (j = ptc.length; j--;) {
- // loop over ptc
- str.push(closingParObj)
- }
- if (allowed[5] !== true) {
- throw new Mexp.Exception('complete the expression')
- }
- while (bracToClose--) {
- str.push(closingParObj)
- }
- str.push(closingParObj)
- // console.log(str);
- return new Mexp(str)
- }
- module.exports = Mexp
- /***/ }),
- /***/ 178:
- /***/ ((module) => {
- "use strict";
- var Mexp = function (parsed) {
- this.value = parsed
- }
- Mexp.math = {
- isDegree: true, // mode of calculator
- acos: function (x) {
- return (Mexp.math.isDegree ? 180 / Math.PI * Math.acos(x) : Math.acos(x))
- },
- add: function (a, b) {
- return a + b
- },
- asin: function (x) {
- return (Mexp.math.isDegree ? 180 / Math.PI * Math.asin(x) : Math.asin(x))
- },
- atan: function (x) {
- return (Mexp.math.isDegree ? 180 / Math.PI * Math.atan(x) : Math.atan(x))
- },
- acosh: function (x) {
- return Math.log(x + Math.sqrt(x * x - 1))
- },
- asinh: function (x) {
- return Math.log(x + Math.sqrt(x * x + 1))
- },
- atanh: function (x) {
- return Math.log((1 + x) / (1 - x))
- },
- C: function (n, r) {
- var pro = 1
- var other = n - r
- var choice = r
- if (choice < other) {
- choice = other
- other = r
- }
- for (var i = choice + 1; i <= n; i++) {
- pro *= i
- }
- return pro / Mexp.math.fact(other)
- },
- changeSign: function (x) {
- return -x
- },
- cos: function (x) {
- if (Mexp.math.isDegree) x = Mexp.math.toRadian(x)
- return Math.cos(x)
- },
- cosh: function (x) {
- return (Math.pow(Math.E, x) + Math.pow(Math.E, -1 * x)) / 2
- },
- div: function (a, b) {
- return a / b
- },
- fact: function (n) {
- if (n % 1 !== 0) return 'NaN'
- var pro = 1
- for (var i = 2; i <= n; i++) {
- pro *= i
- }
- return pro
- },
- inverse: function (x) {
- return 1 / x
- },
- log: function (i) {
- return Math.log(i) / Math.log(10)
- },
- mod: function (a, b) {
- return a % b
- },
- mul: function (a, b) {
- return a * b
- },
- P: function (n, r) {
- var pro = 1
- for (var i = Math.floor(n) - Math.floor(r) + 1; i <= Math.floor(n); i++) {
- pro *= i
- }
- return pro
- },
- Pi: function (low, high, ex) {
- var pro = 1
- for (var i = low; i <= high; i++) {
- pro *= Number(ex.postfixEval({
- n: i
- }))
- }
- return pro
- },
- pow10x: function (e) {
- var x = 1
- while (e--) {
- x *= 10
- }
- return x
- },
- sigma: function (low, high, ex) {
- var sum = 0
- for (var i = low; i <= high; i++) {
- sum += Number(ex.postfixEval({
- n: i
- }))
- }
- return sum
- },
- sin: function (x) {
- if (Mexp.math.isDegree) x = Mexp.math.toRadian(x)
- return Math.sin(x)
- },
- sinh: function (x) {
- return (Math.pow(Math.E, x) - Math.pow(Math.E, -1 * x)) / 2
- },
- sub: function (a, b) {
- return a - b
- },
- tan: function (x) {
- if (Mexp.math.isDegree) x = Mexp.math.toRadian(x)
- return Math.tan(x)
- },
- tanh: function (x) {
- return Mexp.sinha(x) / Mexp.cosha(x)
- },
- toRadian: function (x) {
- return x * Math.PI / 180
- },
- and: function (a, b) {
- return a & b
- }
- }
- Mexp.Exception = function (message) {
- this.message = message
- }
- module.exports = Mexp
- /***/ }),
- /***/ 477:
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- var Mexp = __webpack_require__(618);
- Mexp.prototype.toPostfix = function () {
- 'use strict';
- var post = [], elem, popped, prep, pre, ele;
- var stack = [{ value: "(", type: 4, pre: 0 }];
- var arr = this.value;
- for (var i = 1; i < arr.length; i++) {
- if (arr[i].type === 1 || arr[i].type === 3 || arr[i].type === 13) { //if token is number,constant,or n(which is also a special constant in our case)
- if (arr[i].type === 1)
- arr[i].value = Number(arr[i].value);
- post.push(arr[i]);
- }
- else if (arr[i].type === 4) {
- stack.push(arr[i]);
- }
- else if (arr[i].type === 5) {
- while ((popped = stack.pop()).type !== 4) {
- post.push(popped);
- }
- }
- else if (arr[i].type === 11) {
- while ((popped = stack.pop()).type !== 4) {
- post.push(popped);
- }
- stack.push(popped);
- }
- else {
- elem = arr[i];
- pre = elem.pre;
- ele = stack[stack.length - 1];
- prep = ele.pre;
- var flag = ele.value == 'Math.pow' && elem.value == 'Math.pow';
- if (pre > prep) stack.push(elem);
- else {
- while (prep >= pre && !flag || flag && pre < prep) {
- popped = stack.pop();
- ele = stack[stack.length - 1];
- post.push(popped);
- prep = ele.pre;
- flag = elem.value == 'Math.pow' && ele.value == 'Math.pow';
- }
- stack.push(elem);
- }
- }
- }
- return new Mexp(post);
- };
- module.exports = Mexp;
- /***/ }),
- /***/ 733:
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- var Mexp=__webpack_require__(477);
- Mexp.prototype.postfixEval = function (UserDefined) {
- 'use strict';
- UserDefined=UserDefined||{};
- UserDefined.PI=Math.PI;
- UserDefined.E=Math.E;
- var stack=[],pop1,pop2,pop3;
- var disp=[];
- var temp='';
- var arr=this.value;
- var bool=(typeof UserDefined.n!=="undefined");
- for(var i=0;i<arr.length;i++){
- if(arr[i].type===1){
- stack.push({value:arr[i].value,type:1});
- }
- else if(arr[i].type===3){
- stack.push({value:UserDefined[arr[i].value],type:1});
- }
- else if(arr[i].type===0){
- if(typeof stack[stack.length-1].type==="undefined"){
- stack[stack.length-1].value.push(arr[i]);
- }
- else stack[stack.length-1].value=arr[i].value(stack[stack.length-1].value);
- }
- else if(arr[i].type===7){
- if(typeof stack[stack.length-1].type==="undefined"){
- stack[stack.length-1].value.push(arr[i]);
- }
- else stack[stack.length-1].value=arr[i].value(stack[stack.length-1].value);
- }
- else if(arr[i].type===8){
- pop1=stack.pop();
- pop2=stack.pop();
- stack.push({type:1,value:arr[i].value(pop2.value,pop1.value)});
- }
- else if(arr[i].type===10){
- pop1=stack.pop();
- pop2=stack.pop();
- if(typeof pop2.type==="undefined"){
- pop2.value=pop2.concat(pop1);
- pop2.value.push(arr[i]);
- stack.push(pop2);
- }
- else if (typeof pop1.type==="undefined") {
- pop1.unshift(pop2);
- pop1.push(arr[i]);
- stack.push(pop1);
- }
- else{
- stack.push({type:1,value:arr[i].value(pop2.value,pop1.value)});
- }
- }
- else if(arr[i].type===2||arr[i].type===9){
- pop1=stack.pop();
- pop2=stack.pop();
- if(typeof pop2.type==="undefined"){
- pop2=pop2.concat(pop1);
- pop2.push(arr[i]);
- stack.push(pop2);
- }
- else if (typeof pop1.type==="undefined") {
- pop1.unshift(pop2);
- pop1.push(arr[i]);
- stack.push(pop1);
- }
- else{
- stack.push({type:1,value:arr[i].value(pop2.value,pop1.value)});
- }
- }
- else if(arr[i].type===12){
- pop1=stack.pop();
- if (typeof pop1.type!=="undefined") {
- pop1=[pop1];
- }
- pop2=stack.pop();
- pop3=stack.pop();
- stack.push({type:1,value:arr[i].value(pop3.value,pop2.value,new Mexp(pop1))});
- }
- else if(arr[i].type===13){
- if(bool){
- stack.push({value:UserDefined[arr[i].value],type:3});
- }
- else stack.push([arr[i]]);
- }
- }
- if (stack.length>1) {
- throw(new Mexp.Exception("Uncaught Syntax error"));
- }
- return stack[0].value>1000000000000000?"Infinity":parseFloat(stack[0].value.toFixed(15));
- };
- Mexp.eval=function(str,tokens,obj){
- if (typeof tokens==="undefined") {
- return this.lex(str).toPostfix().postfixEval();
- }
- else if (typeof obj==="undefined") {
- if (typeof tokens.length!=="undefined")
- return this.lex(str,tokens).toPostfix().postfixEval();
- else
- return this.lex(str).toPostfix().postfixEval(tokens);
- }
- else
- return this.lex(str,tokens).toPostfix().postfixEval(obj);
- };
- module.exports=Mexp;
- /***/ })
- /******/ });
- /************************************************************************/
- /******/ // The module cache
- /******/ var __webpack_module_cache__ = {};
- /******/
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/ // Check if module is in cache
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
- /******/ if (cachedModule !== undefined) {
- /******/ return cachedModule.exports;
- /******/ }
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = __webpack_module_cache__[moduleId] = {
- /******/ // no module.id needed
- /******/ // no module.loaded needed
- /******/ exports: {}
- /******/ };
- /******/
- /******/ // Execute the module function
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
- /******/
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/
- /************************************************************************/
- /******/
- /******/ // startup
- /******/ // Load entry module and return exports
- /******/ // This entry module is referenced by other modules so it can't be inlined
- /******/ var __webpack_exports__ = __webpack_require__(28);
- /******/
- /******/ return __webpack_exports__;
- /******/ })()
- ;
- });
|