Fix > and < not working

This commit is contained in:
kwaroran
2024-04-25 03:12:16 +09:00
parent be38e42186
commit 63e3492466
2 changed files with 31 additions and 4 deletions

View File

@@ -1233,6 +1233,10 @@ export function risuChatParser(da:string, arg:{
break break
} }
case '<':{ case '<':{
if(stackType[nested.length] === 1){
nested[0] += da[pointer]
break
}
nested.unshift('') nested.unshift('')
stackType[nested.length] = 2 stackType[nested.length] = 2
break break
@@ -1319,6 +1323,10 @@ export function risuChatParser(da:string, arg:{
break break
} }
case '>':{ case '>':{
if(stackType[nested.length] === 1){
nested[0] += da[pointer]
break
}
if(nested.length === 1 || stackType[nested.length] !== 2){ if(nested.length === 1 || stackType[nested.length] !== 2){
break break
} }

View File

@@ -14,12 +14,12 @@ function toRPN(expression:string) {
}; };
expression = expression.replace(/\s+/g, ''); expression = expression.replace(/\s+/g, '');
let expression2 = expression.split(/([\+\-\*\/\^\%])/).filter(token => token); let expression2 = expression.split(/([\+\-\*\/\^\%\>\<])/).filter(token => token);
expression2.forEach(token => { expression2.forEach(token => {
if (parseFloat(token) || token === '0') { if (parseFloat(token) || token === '0') {
outputQueue += token + ' '; outputQueue += token + ' ';
} else if ('+-*/^%'.includes(token)) { } else if ('+-*/^%><'.includes(token)) {
while (operatorStack.length > 0 && while (operatorStack.length > 0 &&
((operators[token].associativity === 'Left' && ((operators[token].associativity === 'Left' &&
operators[token].precedence <= operators[operatorStack[operatorStack.length - 1]].precedence) || operators[token].precedence <= operators[operatorStack[operatorStack.length - 1]].precedence) ||
@@ -63,8 +63,27 @@ function calculateRPN(expression:string) {
return stack.pop(); return stack.pop();
} }
export function calcString(args:string) { function executeRPNCalculation(text:string) {
const expression = toRPN(args); const expression = toRPN(text);
const evaluated = calculateRPN(expression); const evaluated = calculateRPN(expression);
return evaluated return evaluated
} }
export function calcString(text:string) {
let depthText:string[] = ['']
for(let i = 0; i < text.length; i++) {
if(text[i] === '(') {
depthText.push('')
}
else if(text[i] === ')' && depthText.length > 1) {
let result = executeRPNCalculation(depthText.pop())
depthText[depthText.length - 1] += result
}
else {
depthText[depthText.length - 1] += text[i]
}
}
return executeRPNCalculation(depthText.join(''))
}