diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:58:02 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:58:02 +0800 |
| commit | fee47f6414cc3ae9a88f3ee0ed20f1d6f2d9f556 (patch) | |
| tree | 2b99dd57fc676a3819ef3cc46ac43df0043c2bb3 /node_modules/math-expression-evaluator/src/postfix.js | |
| parent | 0379526e20e1ff212df23e6326741aa9c06df204 (diff) | |
added plugin from postcss: postcss-fixes rucksack-css
Diffstat (limited to 'node_modules/math-expression-evaluator/src/postfix.js')
| -rw-r--r-- | node_modules/math-expression-evaluator/src/postfix.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/node_modules/math-expression-evaluator/src/postfix.js b/node_modules/math-expression-evaluator/src/postfix.js new file mode 100644 index 00000000..14d1ee0b --- /dev/null +++ b/node_modules/math-expression-evaluator/src/postfix.js @@ -0,0 +1,50 @@ +
+var Mexp = require('./lexer.js');
+
+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;
\ No newline at end of file |
