@@ -27,8 +27,7 @@ function calc(exp, isDeg = false) {
if (res.length === 1 || !isNaN(resNum)) {
stack.push(resNum);
} else {
- console.log(resNum, +parser.parse(resNum));
- stack.push(parser.parse(resNum));
+ stack.push(parser.parse(resNum) + '');
}
res = [];
- // console.log(resNum, +parser.parse(resNum));
@@ -1,3 +1,10 @@
+/**
+ * jison 编译计算器库
+ * 参考:https://github.com/GerHobbelt/jison
+ * 安装编译库:npm install jison-gho -g
+ * 编译:jison calculator.jison 生成calculator.js
+ * 按需修改为module export
+*/
/* description: Parses and executes mathematical expressions. */
%{
@@ -104,5 +104,9 @@ module.exports = [
{
value: '0√(4) / 3',
result: 'Infinity',
+ },
+ {
+ value: 'tan(tan(tan(tan(π))))',
+ result: 0,
];