From 84ecac417f27aa0806ba8163707dc3f2a17c137c Mon Sep 17 00:00:00 2001 From: a3boot Date: Wed, 23 Mar 2022 17:54:49 +0300 Subject: [PATCH] v0.0.39 fix funny bugs --- lib/interpretator.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/interpretator.js b/lib/interpretator.js index 3275a54..fd18ea2 100644 --- a/lib/interpretator.js +++ b/lib/interpretator.js @@ -1231,8 +1231,8 @@ function checkCondition(expression, programName) { } const check_redundant_brackets = (str) => { - const left = str.substring(0, str.indexOf(str.match(/[<>=]/)[0])) - const right = str.substring(str.lastIndexOf(str.match(/[<>=]/g)[str.match(/[<>=]/g).length - 1]) + 1) + const left = str.substring(0, str.indexOf(str.match(/[<>=!]/)[0])) + const right = str.substring(str.lastIndexOf(str.match(/[<>=!]/g)[str.match(/[<>=]/g).length - 1]) + 1) const left_redundant = (left.match(/\(/g) ? left.match(/\(/g).length : 0) - @@ -1250,7 +1250,7 @@ function checkCondition(expression, programName) { const add_1e = (part_condidion) => { - if (part_condidion.match('=') || part_condidion.match('<>')) return part_condidion + if (part_condidion.match('=')) return part_condidion //TODO переделать с учетом открывающих и закрывающих скобочек в левой и правой частях const bracket = (part_condidion.trim()[0] === '(' && part_condidion.trim()[part_condidion.trim().length - 1] === ')') @@ -1266,14 +1266,15 @@ function checkCondition(expression, programName) { //Вот тут вычисляем лево и право, потом приводим к фиксированной длине - const left = exp_part_with_brackets.substring(0, exp_part_with_brackets.indexOf(exp_part_with_brackets.match(/[<>=]/)[0])) - const right = exp_part_with_brackets.substring(exp_part_with_brackets.lastIndexOf(exp_part_with_brackets.match(/[<>=]/g)[exp_part_with_brackets.match(/[<>=]/g).length - 1]) + 1) + const left = exp_part_with_brackets.substring(0, exp_part_with_brackets.indexOf(exp_part_with_brackets.match(/[<>=!]/)[0])) + const right = exp_part_with_brackets.substring(exp_part_with_brackets.lastIndexOf(exp_part_with_brackets.match(/[<>=!]/g)[exp_part_with_brackets.match(/[<>=!]/g).length - 1]) + 1) - let left_value, right_value + let left_value = 0, right_value = 0 + const bool = exp_part_with_brackets.match(/[<>=!]+/)[0] try { eval(`left_value = ${left}`); eval(`right_value = ${right}`) - exp_part_with_brackets = exp_part_with_brackets.replace(left, left_value.toFixed(5)).replace(right, right_value.toFixed(5)) + exp_part_with_brackets = '' + left_value.toFixed(5) + bool + right_value.toFixed(5) } catch (err) { console.log(`value error: left: ${left} right: ${right}`) } @@ -1283,8 +1284,6 @@ function checkCondition(expression, programName) { expression = expression.replace(exp_part, add_1e(exp_part_with_brackets)) }); - console.log(expression) - var value = 0; // console.log(expression) var codeString = 'if (' + expression + ') {value = 1} else {value = 0}';