Skip to content

Commit

Permalink
v0.0.39 fix funny bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
staniska committed Mar 23, 2022
1 parent 4ef3071 commit 84ecac4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/interpretator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) -
Expand All @@ -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] === ')')
Expand All @@ -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}`)
}
Expand All @@ -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}';
Expand Down

0 comments on commit 84ecac4

Please sign in to comment.