diff options
author | Mike Buland <eichlan@xagasoft.com> | 2016-12-01 11:16:25 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2016-12-01 11:16:25 -0700 |
commit | 32b48aeb75db4ad40fe0173614e585f9bee72257 (patch) | |
tree | 36ec0bbb72ece290ba82906edf3ae6c50f2a0984 /src/scriptengine.cpp | |
parent | b96daa4e9849ac9caf5c0dfcea8daac28267ea19 (diff) | |
download | clic-32b48aeb75db4ad40fe0173614e585f9bee72257.tar.gz clic-32b48aeb75db4ad40fe0173614e585f9bee72257.tar.bz2 clic-32b48aeb75db4ad40fe0173614e585f9bee72257.tar.xz clic-32b48aeb75db4ad40fe0173614e585f9bee72257.zip |
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.
Diffstat (limited to 'src/scriptengine.cpp')
-rw-r--r-- | src/scriptengine.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
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 ) | |||
56 | break; | 56 | break; |
57 | 57 | ||
58 | case Token::tPlus: | 58 | case Token::tPlus: |
59 | sNums.push( sNums.peekPop() + sNums.peekPop() ); | 59 | { |
60 | Number a = sNums.peekPop(); | ||
61 | Number b = sNums.peekPop(); | ||
62 | sNums.push( a + b ); | ||
63 | } | ||
60 | break; | 64 | break; |
61 | 65 | ||
62 | case Token::tMinus: | 66 | case Token::tMinus: |
63 | sNums.push( sNums.peekPop() - sNums.peekPop() ); | 67 | { |
68 | Number a = sNums.peekPop(); | ||
69 | Number b = sNums.peekPop(); | ||
70 | sNums.push( a - b ); | ||
71 | } | ||
64 | break; | 72 | break; |
65 | 73 | ||
66 | case Token::tDivide: | 74 | case Token::tDivide: |
67 | sNums.push( sNums.peekPop() / sNums.peekPop() ); | 75 | { |
76 | Number a = sNums.peekPop(); | ||
77 | Number b = sNums.peekPop(); | ||
78 | sNums.push( a / b ); | ||
79 | } | ||
68 | break; | 80 | break; |
69 | 81 | ||
70 | case Token::tMultiply: | 82 | case Token::tMultiply: |
71 | sNums.push( sNums.peekPop() * sNums.peekPop() ); | 83 | { |
84 | Number a = sNums.peekPop(); | ||
85 | Number b = sNums.peekPop(); | ||
86 | sNums.push( a * b ); | ||
87 | } | ||
72 | break; | 88 | break; |
73 | 89 | ||
74 | case Token::tNegate: | 90 | case Token::tNegate: |