Skip to content

Commit 0a80df7

Browse files
committed
some cleanup
1 parent ea1cb2b commit 0a80df7

File tree

5 files changed

+7
-15
lines changed

5 files changed

+7
-15
lines changed

calculator.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ float calc(std::vector<RPNToken>& tokenlist, VarTable * vartabel){
1414

1515
//remember that operands will be eaten in reverse order
1616
switch (last.opcode) {
17-
case OC::NUM: res = last.value; break;
18-
case OC::VAR: res = vartabel->getValue((int)last.value); break;
17+
case OC::NUM: res = last.value; break;
18+
case OC::VAR: res = vartabel->getValue((int)last.value); break;
1919
case OC::MUL: res = calc(tokenlist, vartabel) * calc(tokenlist, vartabel); break;
2020
case OC::DIV: v1 = calc(tokenlist, vartabel); res = calc(tokenlist, vartabel)/v1; break;
2121
case OC::ADD: res = calc(tokenlist, vartabel) + calc(tokenlist, vartabel); break;
2222
case OC::SUB: v1 = calc(tokenlist, vartabel); res = calc(tokenlist, vartabel) - v1; break;
23-
case OC::PAS: res = calc(tokenlist, vartabel); break;
24-
case OC::CHS: res = -calc(tokenlist, vartabel); break;
23+
case OC::PAS: res = calc(tokenlist, vartabel); break;
24+
case OC::CHS: res = -calc(tokenlist, vartabel); break;
2525
case OC::LT: res = calc(tokenlist, vartabel) > calc(tokenlist, vartabel); break;
2626
case OC::LE: res = calc(tokenlist, vartabel) >= calc(tokenlist, vartabel); break;
2727
case OC::GT: res = calc(tokenlist, vartabel) < calc(tokenlist, vartabel); break;
2828
case OC::GE: res = calc(tokenlist, vartabel) <= calc(tokenlist, vartabel); break;
2929
case OC::EQ: res = calc(tokenlist, vartabel) == calc(tokenlist, vartabel); break;
3030
case OC::NE: res = calc(tokenlist, vartabel) != calc(tokenlist, vartabel); break;
3131
case OC::ASS: res = calc(tokenlist, vartabel);
32-
vartabel->setVar(tokenlist[cursor-1].value, res); cursor--; break;
32+
vartabel->setVar(tokenlist[cursor-1].value, res); cursor--; break;
3333
case OC::COL: v1 = calc(tokenlist, vartabel); v2=calc(tokenlist, vartabel);
34-
res = calc(tokenlist, vartabel)?v2:v1; break;
35-
default: break;
34+
res = calc(tokenlist, vartabel)?v2:v1; break;
35+
default: break;
3636
}
3737
return res;
3838
}

calculator.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
void calcandprint(std::vector<RPNToken> &tokenlist, VarTable * vartabel, bool prt);
88
float calc(std::vector<RPNToken> &tokenlist, VarTable * vartabel);
99

10-
// VarTable * vartab;
11-
1210
static float fun_elv(float x, float y, float z){
1311
if (x>0.5) return y; else return z;}
1412
static int cursor;

rpngenerator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
using namespace std;
99

10-
1110
void expr(Token &tk, TkList tkList, vector<RPNToken> &tokensout);
1211
void expr1_par(Token &tk, TkList &tkList, vector<RPNToken> &tokensout);
1312
void expr0_val(Token &tk, TkList &tkList, vector<RPNToken> &tokensout);
@@ -75,7 +74,6 @@ vector<RPNToken> makeRPN(vector<Token> tkListIn)
7574
// we will move the input token list into a structure TkList, equipped with member funtions
7675
TkList tkList;
7776
tkList.tokens = tkListIn;
78-
7977
vector<RPNToken> tokensout;
8078

8179
tokensout.clear();

tokengenerator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
using namespace std;
99

10-
vector<float> varValues;
11-
1210
void printtokengenerator(const vector<Token>& RPNTokens,
1311
VarTable *vartabel){
1412
const string ppOC[20] ={"NUM", "VAR", "MUL", "DIV", "ADD", "SUB", "PAS", "CHS", "LT", "LE", "GT", "GE", "EQ",

vartable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ using namespace std;
77

88
struct VarTable
99
{
10-
public:
11-
1210
int getIndex(string name);
1311
// look for name in the table and return the storage index
1412
// if not found create a new entry and return the new index

0 commit comments

Comments
 (0)