From 32b48aeb75db4ad40fe0173614e585f9bee72257 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 1 Dec 2016 11:16:25 -0700 Subject: Found a big problem with order of operations. I believe this is because I'm using right tail recursion, but I'm not really sure how I could change it for this program. order of operations is being observed perfectly, but then operations are being performed from right to left, not left to right. I think I may be reducing too frequently, honestly. --- src/scriptengine.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/scriptengine.cpp') diff --git a/src/scriptengine.cpp b/src/scriptengine.cpp index 7b5df03..b828409 100644 --- a/src/scriptengine.cpp +++ b/src/scriptengine.cpp @@ -56,19 +56,35 @@ Number ScriptEngine::exec( Expression *pExpr ) break; case Token::tPlus: - sNums.push( sNums.peekPop() + sNums.peekPop() ); + { + Number a = sNums.peekPop(); + Number b = sNums.peekPop(); + sNums.push( a + b ); + } break; case Token::tMinus: - sNums.push( sNums.peekPop() - sNums.peekPop() ); + { + Number a = sNums.peekPop(); + Number b = sNums.peekPop(); + sNums.push( a - b ); + } break; case Token::tDivide: - sNums.push( sNums.peekPop() / sNums.peekPop() ); + { + Number a = sNums.peekPop(); + Number b = sNums.peekPop(); + sNums.push( a / b ); + } break; case Token::tMultiply: - sNums.push( sNums.peekPop() * sNums.peekPop() ); + { + Number a = sNums.peekPop(); + Number b = sNums.peekPop(); + sNums.push( a * b ); + } break; case Token::tNegate: -- cgit v1.2.3