pimath 0.0.119 → 0.0.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/.eslintrc.js +23 -23
  2. package/.idea/PI.iml +7 -1
  3. package/dev/pimath.js +7929 -0
  4. package/dev/pimath.js.map +1 -0
  5. package/dist/{pi.js → pimath.js} +7612 -7829
  6. package/dist/pimath.js.map +1 -0
  7. package/dist/pimath.min.js +2 -0
  8. package/dist/pimath.min.js.map +1 -0
  9. package/docs/assets/main.js +3 -3
  10. package/docs/assets/search.js +1 -1
  11. package/docs/assets/style.css +450 -363
  12. package/docs/classes/Logicalset.Logicalset.html +119 -110
  13. package/docs/classes/Polynom.Rational.html +230 -227
  14. package/docs/classes/Vector-1.Vector.html +319 -273
  15. package/docs/classes/Vector.Point.html +189 -190
  16. package/docs/classes/algebra_equation.Equation.html +489 -446
  17. package/docs/classes/algebra_linearSystem.LinearSystem.html +228 -217
  18. package/docs/classes/algebra_monom.Monom.html +564 -507
  19. package/docs/classes/algebra_polynom.Polynom.html +774 -753
  20. package/docs/classes/coefficients_fraction.Fraction.html +573 -565
  21. package/docs/classes/geometry_circle.Circle.html +299 -299
  22. package/docs/classes/geometry_line.Line.html +511 -451
  23. package/docs/classes/geometry_triangle.Triangle.html +273 -264
  24. package/docs/classes/numeric.Numeric.html +138 -132
  25. package/docs/classes/shutingyard.Shutingyard.html +144 -133
  26. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +47 -46
  27. package/docs/enums/geometry_line.LinePropriety.html +58 -58
  28. package/docs/enums/shutingyard.ShutingyardMode.html +62 -58
  29. package/docs/enums/shutingyard.ShutingyardType.html +74 -70
  30. package/docs/index.html +31 -33
  31. package/docs/interfaces/algebra_equation.ISolution.html +61 -59
  32. package/docs/interfaces/algebra_polynom.IEuclidian.html +47 -46
  33. package/docs/interfaces/geometry_triangle.remarquableLines.html +74 -74
  34. package/docs/modules/Logicalset.html +33 -38
  35. package/docs/modules/Polynom.html +33 -38
  36. package/docs/modules/Vector-1.html +33 -38
  37. package/docs/modules/Vector.html +33 -38
  38. package/docs/modules/algebra_equation.html +35 -41
  39. package/docs/modules/algebra_linearSystem.html +31 -37
  40. package/docs/modules/algebra_monom.html +33 -39
  41. package/docs/modules/algebra_polynom.html +35 -41
  42. package/docs/modules/coefficients_fraction.html +33 -39
  43. package/docs/modules/geometry_circle.html +31 -37
  44. package/docs/modules/geometry_line.html +33 -39
  45. package/docs/modules/geometry_triangle.html +33 -39
  46. package/docs/modules/numeric.html +31 -37
  47. package/docs/modules/shutingyard.html +41 -47
  48. package/docs/types/algebra_monom.literalType.html +33 -37
  49. package/docs/types/algebra_polynom.PolynomParsingType.html +33 -37
  50. package/docs/types/coefficients_fraction.FractionParsingType.html +32 -36
  51. package/docs/types/shutingyard.Token.html +38 -42
  52. package/docs/types/shutingyard.tokenType.html +40 -44
  53. package/docs/variables/shutingyard.tokenConstant.html +37 -41
  54. package/esm/index.d.ts +38 -41
  55. package/esm/index.js +43 -46
  56. package/esm/index.js.map +1 -1
  57. package/esm/maths/algebra/equation.d.ts +119 -117
  58. package/esm/maths/algebra/equation.js +796 -785
  59. package/esm/maths/algebra/equation.js.map +1 -1
  60. package/esm/maths/algebra/linearSystem.d.ts +39 -38
  61. package/esm/maths/algebra/linearSystem.js +278 -262
  62. package/esm/maths/algebra/linearSystem.js.map +1 -1
  63. package/esm/maths/algebra/logicalset.d.ts +28 -28
  64. package/esm/maths/algebra/logicalset.js +157 -157
  65. package/esm/maths/algebra/monom.d.ts +206 -206
  66. package/esm/maths/algebra/monom.js +908 -908
  67. package/esm/maths/algebra/monom.js.map +1 -1
  68. package/esm/maths/algebra/polynom.d.ts +157 -157
  69. package/esm/maths/algebra/polynom.js +1277 -1277
  70. package/esm/maths/algebra/rational.d.ts +45 -45
  71. package/esm/maths/algebra/rational.js +183 -183
  72. package/esm/maths/algebra/study/rationalStudy.d.ts +28 -28
  73. package/esm/maths/algebra/study/rationalStudy.js +243 -243
  74. package/esm/maths/algebra/study.d.ts +142 -142
  75. package/esm/maths/algebra/study.js +377 -377
  76. package/esm/maths/algebra/study.js.map +1 -1
  77. package/esm/maths/coefficients/fraction.d.ts +90 -90
  78. package/esm/maths/coefficients/fraction.js +516 -516
  79. package/esm/maths/coefficients/fraction.js.map +1 -1
  80. package/esm/maths/coefficients/nthRoot.d.ts +23 -23
  81. package/esm/maths/coefficients/nthRoot.js +136 -136
  82. package/esm/maths/geometry/circle.d.ts +45 -45
  83. package/esm/maths/geometry/circle.js +323 -323
  84. package/esm/maths/geometry/line.d.ts +99 -99
  85. package/esm/maths/geometry/line.js +481 -481
  86. package/esm/maths/geometry/line.js.map +1 -1
  87. package/esm/maths/geometry/point.d.ts +34 -34
  88. package/esm/maths/geometry/point.js +166 -166
  89. package/esm/maths/geometry/point.js.map +1 -1
  90. package/esm/maths/geometry/triangle.d.ts +85 -85
  91. package/esm/maths/geometry/triangle.js +268 -268
  92. package/esm/maths/geometry/vector.d.ts +41 -41
  93. package/esm/maths/geometry/vector.js +197 -197
  94. package/esm/maths/geometry/vector.js.map +1 -1
  95. package/esm/maths/numeric.d.ts +28 -28
  96. package/esm/maths/numeric.js +180 -169
  97. package/esm/maths/numeric.js.map +1 -1
  98. package/esm/maths/numexp.d.ts +19 -0
  99. package/esm/maths/numexp.js +186 -0
  100. package/esm/maths/numexp.js.map +1 -0
  101. package/esm/maths/randomization/random.d.ts +23 -23
  102. package/esm/maths/randomization/random.js +78 -78
  103. package/esm/maths/randomization/random.js.map +1 -1
  104. package/esm/maths/randomization/randomCore.d.ts +7 -7
  105. package/esm/maths/randomization/randomCore.js +21 -21
  106. package/esm/maths/randomization/rndFraction.d.ts +12 -12
  107. package/esm/maths/randomization/rndFraction.js +43 -43
  108. package/esm/maths/randomization/rndGeometryLine.d.ts +12 -12
  109. package/esm/maths/randomization/rndGeometryLine.js +45 -45
  110. package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -12
  111. package/esm/maths/randomization/rndGeometryPoint.js +60 -60
  112. package/esm/maths/randomization/rndHelpers.d.ts +23 -23
  113. package/esm/maths/randomization/rndHelpers.js +76 -76
  114. package/esm/maths/randomization/rndMonom.d.ts +12 -12
  115. package/esm/maths/randomization/rndMonom.js +52 -52
  116. package/esm/maths/randomization/rndPolynom.d.ts +13 -13
  117. package/esm/maths/randomization/rndPolynom.js +74 -74
  118. package/esm/maths/randomization/rndTypes.d.ts +34 -34
  119. package/esm/maths/randomization/rndTypes.js +2 -2
  120. package/esm/maths/shutingyard.d.ts +59 -59
  121. package/esm/maths/shutingyard.js +442 -442
  122. package/esm/maths/shutingyard.js.map +1 -1
  123. package/package.json +11 -11
  124. package/public/index.html +50 -81
  125. package/public/playground.html +7 -8
  126. package/src/index.ts +2 -5
  127. package/src/maths/algebra/equation.ts +16 -0
  128. package/src/maths/algebra/linearSystem.ts +20 -0
  129. package/src/maths/algebra/study.ts +1 -1
  130. package/src/maths/numeric.ts +49 -48
  131. package/src/maths/{expressions/numexp.ts → numexp.ts} +2 -2
  132. package/tests/algebra/equation.test.ts +19 -5
  133. package/tests/algebra/linear.test.ts +3 -11
  134. package/tests/algebra/polynom.test.ts +7 -8
  135. package/tests/algebra/rationnal.test.ts +1 -1
  136. package/tests/algebra/study.test.ts +2 -9
  137. package/tests/coefficients/fraction.test.ts +8 -8
  138. package/tests/custom.test.ts +33 -37
  139. package/tests/numeric.test.ts +1 -2
  140. package/tests/numexp.test.ts +1 -5
  141. package/tests/shutingyard.test.ts +3 -3
  142. package/webpack-production-min.config.js +1 -1
  143. package/webpack-production.config.js +1 -1
  144. package/webpack.config.js +1 -1
  145. package/dist/pi.js.map +0 -1
  146. package/dist/pi.min.js +0 -2
  147. package/dist/pi.min.js.map +0 -1
  148. package/docs/classes/expressions_numexp.NumExp.html +0 -236
  149. package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +0 -317
  150. package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +0 -285
  151. package/docs/modules/expressions_numexp.html +0 -71
  152. package/docs/modules/expressions_polynomexp.html +0 -73
  153. package/docs/modules.html +0 -76
  154. package/graph.svg +0 -1033
  155. package/src/maths/expressions/ExpressionTree.ts +0 -172
  156. package/src/maths/expressions/expression.ts +0 -286
  157. package/src/maths/expressions/expressionFactor.ts +0 -190
  158. package/src/maths/expressions/expressionMember.ts +0 -233
  159. package/src/maths/expressions/expressionOperators.ts +0 -49
  160. package/src/maths/expressions/expressionParser.ts +0 -295
  161. package/src/maths/expressions/factors/ExpFactor.ts +0 -39
  162. package/src/maths/expressions/factors/ExpFactorConstant.ts +0 -60
  163. package/src/maths/expressions/factors/ExpFactorExponential.ts +0 -26
  164. package/src/maths/expressions/factors/ExpFactorNumber.ts +0 -72
  165. package/src/maths/expressions/factors/ExpFactorPower.ts +0 -42
  166. package/src/maths/expressions/factors/ExpFactorTrigo.ts +0 -53
  167. package/src/maths/expressions/factors/ExpFactorVariable.ts +0 -45
  168. package/src/maths/expressions/internals.ts +0 -14
  169. package/src/maths/expressions/polynomexp.bkp.ts +0 -221
  170. package/src/maths/expressions/polynomexp.ts +0 -310
  171. package/tests/expressions/expressions.test.ts +0 -145
  172. package/tests/expressions/expressiontree.test.ts +0 -11
  173. package/tests/polynomexp.test.ts +0 -12
@@ -1,443 +1,443 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Shutingyard = exports.ShutingyardMode = exports.ShutingyardType = exports.tokenConstant = void 0;
4
- exports.tokenConstant = {
5
- pi: Math.PI,
6
- e: Math.exp(1)
7
- };
8
- var ShutingyardType;
9
- (function (ShutingyardType) {
10
- ShutingyardType["VARIABLE"] = "variable";
11
- ShutingyardType["COEFFICIENT"] = "coefficient";
12
- ShutingyardType["OPERATION"] = "operation";
13
- ShutingyardType["CONSTANT"] = "constant";
14
- ShutingyardType["FUNCTION"] = "function";
15
- ShutingyardType["MONOM"] = "monom";
16
- })(ShutingyardType = exports.ShutingyardType || (exports.ShutingyardType = {}));
17
- var ShutingyardMode;
18
- (function (ShutingyardMode) {
19
- ShutingyardMode["EXPRESSION"] = "expression";
20
- ShutingyardMode["POLYNOM"] = "polynom";
21
- ShutingyardMode["SET"] = "set";
22
- ShutingyardMode["NUMERIC"] = "numeric";
23
- })(ShutingyardMode = exports.ShutingyardMode || (exports.ShutingyardMode = {}));
24
- class Shutingyard {
25
- constructor(mode) {
26
- this._rpn = [];
27
- this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
28
- this.tokenConfigInitialization();
29
- }
30
- // Getter
31
- get rpn() {
32
- // console.log(this._rpn)
33
- return this._rpn;
34
- }
35
- get rpnToken() {
36
- return this._rpn.map(x => x.token);
37
- }
38
- /**
39
- * Determin if the token is a defined operation
40
- * Defined operations: + - * / ^ sin cos tan
41
- * @param token
42
- */
43
- // isOperation(token: string): boolean {
44
- // if (token[0].match(/[+\-*/^]/g)) {
45
- // return true;
46
- // }
47
- // //
48
- // // if (token.match(/^sin|cos|tan/g)) {
49
- // // return true;
50
- // // }
51
- //
52
- // return false;
53
- // }
54
- tokenConfigInitialization() {
55
- if (this._mode === ShutingyardMode.SET) {
56
- this._tokenConfig = {
57
- '&': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
58
- '|': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
59
- '!': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
60
- '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION }
61
- };
62
- this._uniformize = false;
63
- }
64
- else if (this._mode === ShutingyardMode.NUMERIC) {
65
- this._tokenConfig = {
66
- '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
67
- '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
68
- '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
69
- '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
70
- '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
71
- '%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
72
- 'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
73
- 'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
74
- 'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
75
- 'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
76
- 'nthrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
77
- 'ln': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
78
- 'log': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
79
- };
80
- this._uniformize = false;
81
- }
82
- else if (this._mode === ShutingyardMode.EXPRESSION) {
83
- this._tokenConfig = {
84
- '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
85
- '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
86
- '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
87
- '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
88
- '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
89
- '%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
90
- 'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
91
- 'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
92
- 'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
93
- 'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
94
- 'nthrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
95
- };
96
- this._uniformize = true;
97
- }
98
- else {
99
- this._tokenConfig = {
100
- '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
101
- '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
102
- '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
103
- '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
104
- '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
105
- };
106
- this._uniformize = true;
107
- }
108
- this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length);
109
- return this._tokenConfig;
110
- }
111
- /**
112
- * Get the next token to analyse.
113
- * @param expr (string) Expression to analyse
114
- * @param start (number) CUrrent position in the expr string.
115
- */
116
- NextToken(expr, start) {
117
- let token, tokenType;
118
- token = '';
119
- tokenType = '';
120
- // Case of parenthesis or comma (generic items)
121
- if (expr[start] === '(') {
122
- token = '(';
123
- tokenType = '(';
124
- }
125
- // It's a closing parenthese
126
- else if (expr[start] === ')') {
127
- token = ')';
128
- tokenType = ')';
129
- }
130
- // It's an argument separator for a function
131
- else if (expr[start] === ',') {
132
- token = ',';
133
- tokenType = 'function-argument';
134
- }
135
- else {
136
- // Extract operation and function tokens
137
- for (let key of this._tokenKeys) {
138
- if (expr.substring(start, start + key.length) === key) {
139
- token += key;
140
- tokenType = this._tokenConfig[key].type;
141
- break;
142
- }
143
- }
144
- // Extract constant
145
- for (let key in exports.tokenConstant) {
146
- if (expr.substring(start, start + key.length) === key) {
147
- token += key;
148
- tokenType = ShutingyardType.CONSTANT;
149
- break;
150
- }
151
- }
152
- if (token === '') {
153
- // No function found ! Might be a coefficient !
154
- if (expr[start].match(/[0-9]/)) {
155
- if (this._mode === ShutingyardMode.POLYNOM && false) {
156
- token = expr.substring(start).match(/^([0-9.,/]+)/)[0];
157
- }
158
- else {
159
- token = expr.substring(start).match(/^([0-9.]+)/)[0];
160
- }
161
- tokenType = ShutingyardType.COEFFICIENT;
162
- }
163
- else if (expr[start].match(/[a-zA-Z]/)) {
164
- token = expr.substring(start).match(/^([a-zA-Z])/)[0];
165
- tokenType = ShutingyardType.VARIABLE;
166
- }
167
- else {
168
- console.log('Unidentified token', expr[start], expr, start);
169
- token = expr[start];
170
- tokenType = ShutingyardType.MONOM;
171
- }
172
- }
173
- }
174
- return [token, start + token.length, tokenType];
175
- }
176
- normalize(expr) {
177
- if (expr.length === 1) {
178
- return expr;
179
- }
180
- // Get the list of function token.
181
- let fnToken = [], kToken = [];
182
- for (let token in this._tokenConfig) {
183
- if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
184
- fnToken.push(token);
185
- }
186
- }
187
- // sort if from the lengthy to the smallest function
188
- fnToken.sort((a, b) => b.length - a.length);
189
- for (let token in exports.tokenConstant) {
190
- kToken.push(token);
191
- }
192
- // sort if from the lengthy to the smallest function
193
- kToken.sort((a, b) => b.length - a.length);
194
- let normalizedExpr = "", i = 0, crtToken, nextToken;
195
- while (i < expr.length - 1) {
196
- // Check if we have a function token.
197
- // The function MUST have an open parentheses
198
- let tokenIdx = 0;
199
- while (tokenIdx < fnToken.length) {
200
- let token = fnToken[tokenIdx];
201
- if (expr.slice(i, i + token.length + 1) === token + '(') {
202
- normalizedExpr += token + '(';
203
- i += token.length + 1;
204
- // Restart the scan for the function token
205
- tokenIdx = 0;
206
- }
207
- else {
208
- // scan for a next function token
209
- tokenIdx++;
210
- }
211
- }
212
- // Check for a constant
213
- tokenIdx = 0;
214
- while (tokenIdx < kToken.length) {
215
- let token = kToken[tokenIdx];
216
- if (expr.slice(i, i + token.length) === token) {
217
- // We have found a constant.
218
- // add it, but with remove the last letter
219
- normalizedExpr += token.slice(0, -1);
220
- i += token.length - 1;
221
- // Exit the loop
222
- break;
223
- }
224
- tokenIdx++;
225
- }
226
- // The function token are solved.
227
- crtToken = expr[i];
228
- nextToken = expr[i + 1];
229
- normalizedExpr += crtToken;
230
- if (crtToken.match(/[a-zA-Z]/g)) {
231
- // Current element is a letter.
232
- // if the next element is a letter, a number or an opening parentheses, add the multiplication sign.
233
- if (nextToken.match(/[a-zA-Z\d(]/)) {
234
- normalizedExpr += '*';
235
- }
236
- }
237
- else if (crtToken.match(/\d/)) {
238
- // Current element is a number.
239
- // if the next element is a letter or a parentheses, add the multiplication sign.
240
- if (nextToken.match(/[a-zA-Z(]/)) {
241
- normalizedExpr += '*';
242
- }
243
- }
244
- else if (crtToken === ')') {
245
- // Current element is a closing parentheses.
246
- // if the next element is a letter, a number or an opening parentheses, add the multiplication sign
247
- if (nextToken.match(/[a-zA-Z\d(]/)) {
248
- normalizedExpr += '*';
249
- }
250
- }
251
- // Go to next token
252
- i++;
253
- }
254
- // add the last token
255
- return normalizedExpr + nextToken;
256
- }
257
- // /**
258
- // * Sanitize an expression by adding missing common operation (multiplication between parentheseses)
259
- // * @param expr
260
- // * @constructor
261
- // */
262
- // Uniformizer(expr: string): string {
263
- // // TODO: Delete this old version
264
- // // Prefere "normalize", much more robust !
265
- // // Determiner if need to be uniformized
266
- // if (!this._uniformize) {
267
- // return expr
268
- // }
269
- //
270
- // // Generate the list of function token.
271
- // let fnToken: string[] = []
272
- // for (let token in this._tokenConfig) {
273
- // if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
274
- // fnToken.push(token)
275
- // }
276
- // }
277
- // // sort if from the lengthy to the smallest function
278
- // fnToken.sort((a, b) => b.length - a.length)
279
- // let tokenRegExp = new RegExp(`(${fnToken.join('|')})`, 'g')
280
- // let functionTokenOrder = Array.from(expr.matchAll(tokenRegExp))
281
- //
282
- //
283
- // let expr2;
284
- //
285
- // // Replace all function by @
286
- // expr2 = expr.replace(tokenRegExp, '@')
287
- // // Add * before @ (functionn)
288
- // expr2 = expr2.replace(/([\da-zA-Z])(@)/g, "$1*$2");
289
- //
290
- // // Replace missing multiplication between two parenthese
291
- // expr2 = expr2.replace(/\)\(/g, ')*(');
292
- //
293
- // // Replace missing multiplication between number or setLetter and parenthese.
294
- //
295
- // // 3x(x-4) => 3x*(x-4)
296
- // expr2 = expr2.replace(/([\da-zA-Z])(\()/g, "$1*$2");
297
- //
298
- // // (x-4)3x => (x-4)*3x
299
- // expr2 = expr2.replace(/(\))([\da-zA-Z])/g, "$1*$2");
300
- //
301
- // // Add multiplication between number and letters.
302
- // // 3x => 3*x
303
- // expr2 = expr2.replace(/([0-9])([a-zA-Z])/g, "$1*$2");
304
- // expr2 = expr2.replace(/([a-zA-Z])([0-9])/g, "$1*$2");
305
- //
306
- // // Remove letter between function token and it's parenthese.
307
- // // for (let token of fnToken) {
308
- // // // Remove
309
- // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
310
- // // }
311
- // // Add multiplication between letters ?
312
- // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
313
- // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
314
- //
315
- // // Restore operation auto formatting (prevent adding the multiplication star)
316
- // let exprAsArray = expr2.split('@')
317
- //
318
- // if (exprAsArray.length > 0) {
319
- // expr2 = ""
320
- // for (let idx in exprAsArray) {
321
- // }
322
- // for (let token of fnToken) {
323
- // // Remove
324
- //
325
- // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
326
- // }
327
- // }
328
- //
329
- // return expr2;
330
- // }
331
- /**
332
- * Parse an expression using the shutting yard tree algorithms
333
- * @param expr (string) Expression to analyse
334
- * Returns a RPN list of items.
335
- * @param uniformize
336
- */
337
- parse(expr, uniformize) {
338
- let outQueue = [], // Output queue
339
- opStack = [], // Operation queue
340
- token = '', tokenPos = 0, tokenType = '', previousOpStatckLength = 0;
341
- // Normalize the input if required.
342
- if (uniformize || this._uniformize)
343
- expr = this.normalize(expr);
344
- let securityLoopLvl1 = 50, securityLoopLvl2_default = 50, securityLoopLvl2;
345
- while (tokenPos < expr.length) {
346
- securityLoopLvl1--;
347
- if (securityLoopLvl1 === 0) {
348
- console.log('SECURITY LEVEL 1 EXIT');
349
- break;
350
- }
351
- // Get the next token and the corresponding new (ending) position
352
- [token, tokenPos, tokenType] = this.NextToken(expr, tokenPos);
353
- switch (tokenType) {
354
- case 'monom':
355
- case 'coefficient':
356
- case 'variable':
357
- case 'constant':
358
- outQueue.push({
359
- token,
360
- tokenType
361
- });
362
- break;
363
- case 'operation':
364
- previousOpStatckLength = opStack.length;
365
- //If the token is an operator, o1, then:
366
- if (opStack.length > 0) {
367
- let opTop = opStack[opStack.length - 1];
368
- securityLoopLvl2 = +securityLoopLvl2_default;
369
- //while there is an operator token o2, at the top of the operator stack and
370
- while (opTop.token in this._tokenConfig && (
371
- //either o1 is left-associative and its precedence is less than or equal to that of o2,
372
- (this._tokenConfig[token].associative === 'left' && this._tokenConfig[token].precedence <= this._tokenConfig[opTop.token].precedence)
373
- ||
374
- //or o1 is right associative, and has precedence less than that of o2,
375
- (this._tokenConfig[token].associative === 'right' && this._tokenConfig[token].precedence < this._tokenConfig[opTop.token].precedence))) {
376
- /* Security exit ! */
377
- securityLoopLvl2--;
378
- if (securityLoopLvl2 === 0) {
379
- console.log('SECURITY LEVEL 2 OPERATION EXIT');
380
- break;
381
- }
382
- // Add the operation to the queue
383
- outQueue.push((opStack.pop()) || { token: '', tokenType: 'operation' });
384
- // Get the next operation on top of the Stack.
385
- if (opStack.length === 0) {
386
- break;
387
- }
388
- opTop = opStack[opStack.length - 1];
389
- }
390
- }
391
- //at the end of iteration push o1 onto the operator stack
392
- opStack.push({ token, tokenType });
393
- break;
394
- case 'function-argument':
395
- // TODO: check if the opStack exist.
396
- securityLoopLvl2 = +securityLoopLvl2_default;
397
- while (opStack[opStack.length - 1].token !== '(' && opStack.length > 0) {
398
- securityLoopLvl2--;
399
- if (securityLoopLvl2 === 0) {
400
- console.log('SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT');
401
- break;
402
- }
403
- outQueue.push((opStack.pop()) || { token, tokenType });
404
- }
405
- break;
406
- case '(':
407
- opStack.push({ token, tokenType });
408
- // Add an empty value if next element is negative.
409
- if (expr[tokenPos] === '-') {
410
- outQueue.push({ token: '0', tokenType: 'coefficient' });
411
- }
412
- break;
413
- case ')':
414
- securityLoopLvl2 = +securityLoopLvl2_default;
415
- //Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output queue.
416
- while (opStack[opStack.length - 1].token !== '(' && opStack.length > 1 /*Maybe zero !? */) {
417
- securityLoopLvl2--;
418
- if (securityLoopLvl2 === 0) {
419
- console.log('SECURITY LEVEL 2 CLOSING PARENTHESE EXIT');
420
- break;
421
- }
422
- outQueue.push((opStack.pop()) || { token, tokenType });
423
- }
424
- //Pop the left parenthesis from the stack, but not onto the output queue.
425
- opStack.pop();
426
- break;
427
- case 'function':
428
- opStack.push({ token, tokenType });
429
- break;
430
- default:
431
- // In theory, everything should be handled.
432
- console.log(`SHUTING YARD: ${tokenType} : ${token} `);
433
- }
434
- // Output
435
- // console.log(outQueue.concat(opStack.reverse()).join(" "));
436
- }
437
- // console.log(outQueue.concat(opStack.reverse()));
438
- this._rpn = outQueue.concat(opStack.reverse());
439
- return this;
440
- }
441
- }
442
- exports.Shutingyard = Shutingyard;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Shutingyard = exports.ShutingyardMode = exports.ShutingyardType = exports.tokenConstant = void 0;
4
+ exports.tokenConstant = {
5
+ pi: Math.PI,
6
+ e: Math.exp(1)
7
+ };
8
+ var ShutingyardType;
9
+ (function (ShutingyardType) {
10
+ ShutingyardType["VARIABLE"] = "variable";
11
+ ShutingyardType["COEFFICIENT"] = "coefficient";
12
+ ShutingyardType["OPERATION"] = "operation";
13
+ ShutingyardType["CONSTANT"] = "constant";
14
+ ShutingyardType["FUNCTION"] = "function";
15
+ ShutingyardType["MONOM"] = "monom";
16
+ })(ShutingyardType || (exports.ShutingyardType = ShutingyardType = {}));
17
+ var ShutingyardMode;
18
+ (function (ShutingyardMode) {
19
+ ShutingyardMode["EXPRESSION"] = "expression";
20
+ ShutingyardMode["POLYNOM"] = "polynom";
21
+ ShutingyardMode["SET"] = "set";
22
+ ShutingyardMode["NUMERIC"] = "numeric";
23
+ })(ShutingyardMode || (exports.ShutingyardMode = ShutingyardMode = {}));
24
+ class Shutingyard {
25
+ constructor(mode) {
26
+ this._rpn = [];
27
+ this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
28
+ this.tokenConfigInitialization();
29
+ }
30
+ // Getter
31
+ get rpn() {
32
+ // console.log(this._rpn)
33
+ return this._rpn;
34
+ }
35
+ get rpnToken() {
36
+ return this._rpn.map(x => x.token);
37
+ }
38
+ /**
39
+ * Determin if the token is a defined operation
40
+ * Defined operations: + - * / ^ sin cos tan
41
+ * @param token
42
+ */
43
+ // isOperation(token: string): boolean {
44
+ // if (token[0].match(/[+\-*/^]/g)) {
45
+ // return true;
46
+ // }
47
+ // //
48
+ // // if (token.match(/^sin|cos|tan/g)) {
49
+ // // return true;
50
+ // // }
51
+ //
52
+ // return false;
53
+ // }
54
+ tokenConfigInitialization() {
55
+ if (this._mode === ShutingyardMode.SET) {
56
+ this._tokenConfig = {
57
+ '&': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
58
+ '|': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
59
+ '!': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
60
+ '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION }
61
+ };
62
+ this._uniformize = false;
63
+ }
64
+ else if (this._mode === ShutingyardMode.NUMERIC) {
65
+ this._tokenConfig = {
66
+ '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
67
+ '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
68
+ '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
69
+ '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
70
+ '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
71
+ '%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
72
+ 'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
73
+ 'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
74
+ 'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
75
+ 'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
76
+ 'nthrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
77
+ 'ln': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
78
+ 'log': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
79
+ };
80
+ this._uniformize = false;
81
+ }
82
+ else if (this._mode === ShutingyardMode.EXPRESSION) {
83
+ this._tokenConfig = {
84
+ '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
85
+ '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
86
+ '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
87
+ '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
88
+ '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
89
+ '%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
90
+ 'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
91
+ 'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
92
+ 'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
93
+ 'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
94
+ 'nthrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
95
+ };
96
+ this._uniformize = true;
97
+ }
98
+ else {
99
+ this._tokenConfig = {
100
+ '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
101
+ '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
102
+ '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
103
+ '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
104
+ '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
105
+ };
106
+ this._uniformize = true;
107
+ }
108
+ this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length);
109
+ return this._tokenConfig;
110
+ }
111
+ /**
112
+ * Get the next token to analyse.
113
+ * @param expr (string) Expression to analyse
114
+ * @param start (number) CUrrent position in the expr string.
115
+ */
116
+ NextToken(expr, start) {
117
+ let token, tokenType;
118
+ token = '';
119
+ tokenType = '';
120
+ // Case of parenthesis or comma (generic items)
121
+ if (expr[start] === '(') {
122
+ token = '(';
123
+ tokenType = '(';
124
+ }
125
+ // It's a closing parenthese
126
+ else if (expr[start] === ')') {
127
+ token = ')';
128
+ tokenType = ')';
129
+ }
130
+ // It's an argument separator for a function
131
+ else if (expr[start] === ',') {
132
+ token = ',';
133
+ tokenType = 'function-argument';
134
+ }
135
+ else {
136
+ // Extract operation and function tokens
137
+ for (let key of this._tokenKeys) {
138
+ if (expr.substring(start, start + key.length) === key) {
139
+ token += key;
140
+ tokenType = this._tokenConfig[key].type;
141
+ break;
142
+ }
143
+ }
144
+ // Extract constant
145
+ for (let key in exports.tokenConstant) {
146
+ if (expr.substring(start, start + key.length) === key) {
147
+ token += key;
148
+ tokenType = ShutingyardType.CONSTANT;
149
+ break;
150
+ }
151
+ }
152
+ if (token === '') {
153
+ // No function found ! Might be a coefficient !
154
+ if (expr[start].match(/[0-9]/)) {
155
+ if (this._mode === ShutingyardMode.POLYNOM && false) {
156
+ token = expr.substring(start).match(/^([0-9.,/]+)/)[0];
157
+ }
158
+ else {
159
+ token = expr.substring(start).match(/^([0-9.]+)/)[0];
160
+ }
161
+ tokenType = ShutingyardType.COEFFICIENT;
162
+ }
163
+ else if (expr[start].match(/[a-zA-Z]/)) {
164
+ token = expr.substring(start).match(/^([a-zA-Z])/)[0];
165
+ tokenType = ShutingyardType.VARIABLE;
166
+ }
167
+ else {
168
+ console.log('Unidentified token', expr[start], expr, start);
169
+ token = expr[start];
170
+ tokenType = ShutingyardType.MONOM;
171
+ }
172
+ }
173
+ }
174
+ return [token, start + token.length, tokenType];
175
+ }
176
+ normalize(expr) {
177
+ if (expr.length === 1) {
178
+ return expr;
179
+ }
180
+ // Get the list of function token.
181
+ let fnToken = [], kToken = [];
182
+ for (let token in this._tokenConfig) {
183
+ if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
184
+ fnToken.push(token);
185
+ }
186
+ }
187
+ // sort if from the lengthy to the smallest function
188
+ fnToken.sort((a, b) => b.length - a.length);
189
+ for (let token in exports.tokenConstant) {
190
+ kToken.push(token);
191
+ }
192
+ // sort if from the lengthy to the smallest function
193
+ kToken.sort((a, b) => b.length - a.length);
194
+ let normalizedExpr = "", i = 0, crtToken, nextToken;
195
+ while (i < expr.length - 1) {
196
+ // Check if we have a function token.
197
+ // The function MUST have an open parentheses
198
+ let tokenIdx = 0;
199
+ while (tokenIdx < fnToken.length) {
200
+ let token = fnToken[tokenIdx];
201
+ if (expr.slice(i, i + token.length + 1) === token + '(') {
202
+ normalizedExpr += token + '(';
203
+ i += token.length + 1;
204
+ // Restart the scan for the function token
205
+ tokenIdx = 0;
206
+ }
207
+ else {
208
+ // scan for a next function token
209
+ tokenIdx++;
210
+ }
211
+ }
212
+ // Check for a constant
213
+ tokenIdx = 0;
214
+ while (tokenIdx < kToken.length) {
215
+ let token = kToken[tokenIdx];
216
+ if (expr.slice(i, i + token.length) === token) {
217
+ // We have found a constant.
218
+ // add it, but with remove the last letter
219
+ normalizedExpr += token.slice(0, -1);
220
+ i += token.length - 1;
221
+ // Exit the loop
222
+ break;
223
+ }
224
+ tokenIdx++;
225
+ }
226
+ // The function token are solved.
227
+ crtToken = expr[i];
228
+ nextToken = expr[i + 1];
229
+ normalizedExpr += crtToken;
230
+ if (crtToken.match(/[a-zA-Z]/g)) {
231
+ // Current element is a letter.
232
+ // if the next element is a letter, a number or an opening parentheses, add the multiplication sign.
233
+ if (nextToken.match(/[a-zA-Z\d(]/)) {
234
+ normalizedExpr += '*';
235
+ }
236
+ }
237
+ else if (crtToken.match(/\d/)) {
238
+ // Current element is a number.
239
+ // if the next element is a letter or a parentheses, add the multiplication sign.
240
+ if (nextToken.match(/[a-zA-Z(]/)) {
241
+ normalizedExpr += '*';
242
+ }
243
+ }
244
+ else if (crtToken === ')') {
245
+ // Current element is a closing parentheses.
246
+ // if the next element is a letter, a number or an opening parentheses, add the multiplication sign
247
+ if (nextToken.match(/[a-zA-Z\d(]/)) {
248
+ normalizedExpr += '*';
249
+ }
250
+ }
251
+ // Go to next token
252
+ i++;
253
+ }
254
+ // add the last token
255
+ return normalizedExpr + nextToken;
256
+ }
257
+ // /**
258
+ // * Sanitize an expression by adding missing common operation (multiplication between parentheseses)
259
+ // * @param expr
260
+ // * @constructor
261
+ // */
262
+ // Uniformizer(expr: string): string {
263
+ // // TODO: Delete this old version
264
+ // // Prefere "normalize", much more robust !
265
+ // // Determiner if need to be uniformized
266
+ // if (!this._uniformize) {
267
+ // return expr
268
+ // }
269
+ //
270
+ // // Generate the list of function token.
271
+ // let fnToken: string[] = []
272
+ // for (let token in this._tokenConfig) {
273
+ // if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
274
+ // fnToken.push(token)
275
+ // }
276
+ // }
277
+ // // sort if from the lengthy to the smallest function
278
+ // fnToken.sort((a, b) => b.length - a.length)
279
+ // let tokenRegExp = new RegExp(`(${fnToken.join('|')})`, 'g')
280
+ // let functionTokenOrder = Array.from(expr.matchAll(tokenRegExp))
281
+ //
282
+ //
283
+ // let expr2;
284
+ //
285
+ // // Replace all function by @
286
+ // expr2 = expr.replace(tokenRegExp, '@')
287
+ // // Add * before @ (functionn)
288
+ // expr2 = expr2.replace(/([\da-zA-Z])(@)/g, "$1*$2");
289
+ //
290
+ // // Replace missing multiplication between two parenthese
291
+ // expr2 = expr2.replace(/\)\(/g, ')*(');
292
+ //
293
+ // // Replace missing multiplication between number or setLetter and parenthese.
294
+ //
295
+ // // 3x(x-4) => 3x*(x-4)
296
+ // expr2 = expr2.replace(/([\da-zA-Z])(\()/g, "$1*$2");
297
+ //
298
+ // // (x-4)3x => (x-4)*3x
299
+ // expr2 = expr2.replace(/(\))([\da-zA-Z])/g, "$1*$2");
300
+ //
301
+ // // Add multiplication between number and letters.
302
+ // // 3x => 3*x
303
+ // expr2 = expr2.replace(/([0-9])([a-zA-Z])/g, "$1*$2");
304
+ // expr2 = expr2.replace(/([a-zA-Z])([0-9])/g, "$1*$2");
305
+ //
306
+ // // Remove letter between function token and it's parenthese.
307
+ // // for (let token of fnToken) {
308
+ // // // Remove
309
+ // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
310
+ // // }
311
+ // // Add multiplication between letters ?
312
+ // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
313
+ // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
314
+ //
315
+ // // Restore operation auto formatting (prevent adding the multiplication star)
316
+ // let exprAsArray = expr2.split('@')
317
+ //
318
+ // if (exprAsArray.length > 0) {
319
+ // expr2 = ""
320
+ // for (let idx in exprAsArray) {
321
+ // }
322
+ // for (let token of fnToken) {
323
+ // // Remove
324
+ //
325
+ // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
326
+ // }
327
+ // }
328
+ //
329
+ // return expr2;
330
+ // }
331
+ /**
332
+ * Parse an expression using the shutting yard tree algorithms
333
+ * @param expr (string) Expression to analyse
334
+ * Returns a RPN list of items.
335
+ * @param uniformize
336
+ */
337
+ parse(expr, uniformize) {
338
+ let outQueue = [], // Output queue
339
+ opStack = [], // Operation queue
340
+ token = '', tokenPos = 0, tokenType = '', previousOpStatckLength = 0;
341
+ // Normalize the input if required.
342
+ if (uniformize || this._uniformize)
343
+ expr = this.normalize(expr);
344
+ let securityLoopLvl1 = 50, securityLoopLvl2_default = 50, securityLoopLvl2;
345
+ while (tokenPos < expr.length) {
346
+ securityLoopLvl1--;
347
+ if (securityLoopLvl1 === 0) {
348
+ console.log('SECURITY LEVEL 1 EXIT');
349
+ break;
350
+ }
351
+ // Get the next token and the corresponding new (ending) position
352
+ [token, tokenPos, tokenType] = this.NextToken(expr, tokenPos);
353
+ switch (tokenType) {
354
+ case 'monom':
355
+ case 'coefficient':
356
+ case 'variable':
357
+ case 'constant':
358
+ outQueue.push({
359
+ token,
360
+ tokenType
361
+ });
362
+ break;
363
+ case 'operation':
364
+ previousOpStatckLength = opStack.length;
365
+ //If the token is an operator, o1, then:
366
+ if (opStack.length > 0) {
367
+ let opTop = opStack[opStack.length - 1];
368
+ securityLoopLvl2 = +securityLoopLvl2_default;
369
+ //while there is an operator token o2, at the top of the operator stack and
370
+ while (opTop.token in this._tokenConfig && (
371
+ //either o1 is left-associative and its precedence is less than or equal to that of o2,
372
+ (this._tokenConfig[token].associative === 'left' && this._tokenConfig[token].precedence <= this._tokenConfig[opTop.token].precedence)
373
+ ||
374
+ //or o1 is right associative, and has precedence less than that of o2,
375
+ (this._tokenConfig[token].associative === 'right' && this._tokenConfig[token].precedence < this._tokenConfig[opTop.token].precedence))) {
376
+ /* Security exit ! */
377
+ securityLoopLvl2--;
378
+ if (securityLoopLvl2 === 0) {
379
+ console.log('SECURITY LEVEL 2 OPERATION EXIT');
380
+ break;
381
+ }
382
+ // Add the operation to the queue
383
+ outQueue.push((opStack.pop()) || { token: '', tokenType: 'operation' });
384
+ // Get the next operation on top of the Stack.
385
+ if (opStack.length === 0) {
386
+ break;
387
+ }
388
+ opTop = opStack[opStack.length - 1];
389
+ }
390
+ }
391
+ //at the end of iteration push o1 onto the operator stack
392
+ opStack.push({ token, tokenType });
393
+ break;
394
+ case 'function-argument':
395
+ // TODO: check if the opStack exist.
396
+ securityLoopLvl2 = +securityLoopLvl2_default;
397
+ while (opStack[opStack.length - 1].token !== '(' && opStack.length > 0) {
398
+ securityLoopLvl2--;
399
+ if (securityLoopLvl2 === 0) {
400
+ console.log('SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT');
401
+ break;
402
+ }
403
+ outQueue.push((opStack.pop()) || { token, tokenType });
404
+ }
405
+ break;
406
+ case '(':
407
+ opStack.push({ token, tokenType });
408
+ // Add an empty value if next element is negative.
409
+ if (expr[tokenPos] === '-') {
410
+ outQueue.push({ token: '0', tokenType: 'coefficient' });
411
+ }
412
+ break;
413
+ case ')':
414
+ securityLoopLvl2 = +securityLoopLvl2_default;
415
+ //Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output queue.
416
+ while (opStack[opStack.length - 1].token !== '(' && opStack.length > 1 /*Maybe zero !? */) {
417
+ securityLoopLvl2--;
418
+ if (securityLoopLvl2 === 0) {
419
+ console.log('SECURITY LEVEL 2 CLOSING PARENTHESE EXIT');
420
+ break;
421
+ }
422
+ outQueue.push((opStack.pop()) || { token, tokenType });
423
+ }
424
+ //Pop the left parenthesis from the stack, but not onto the output queue.
425
+ opStack.pop();
426
+ break;
427
+ case 'function':
428
+ opStack.push({ token, tokenType });
429
+ break;
430
+ default:
431
+ // In theory, everything should be handled.
432
+ console.log(`SHUTING YARD: ${tokenType} : ${token} `);
433
+ }
434
+ // Output
435
+ // console.log(outQueue.concat(opStack.reverse()).join(" "));
436
+ }
437
+ // console.log(outQueue.concat(opStack.reverse()));
438
+ this._rpn = outQueue.concat(opStack.reverse());
439
+ return this;
440
+ }
441
+ }
442
+ exports.Shutingyard = Shutingyard;
443
443
  //# sourceMappingURL=shutingyard.js.map