Debugging single commands translation wip

This commit is contained in:
Hazem Krimi
2024-04-17 18:37:25 +01:00
parent 9760124dc7
commit b26afe682b
5 changed files with 33 additions and 48 deletions
+8 -17
View File
@@ -2,8 +2,8 @@
#include <fstream>
#include <string>
#include "types.h"
#include "operations.h"
#include "memory.h"
#include "arithmetic.h"
using namespace std;
@@ -39,7 +39,7 @@ public:
{
file << translatePush(filename, determineSegment(vec[1]), stoi(vec[2]));
}
else
if (vec[0] == "pop")
{
file << translatePop(filename, determineSegment(vec[1]), stoi(vec[2]));
}
@@ -47,23 +47,14 @@ public:
if (vec.size() == 1)
{
int op = determineArithmeticOperator(vec[0]);
if (vec[0] == "add")
cout << translateAdd();
cout << op << " " << vec[0] << endl;
if (vec[0] == "sub")
cout << translateSub();
switch (determineArithmeticOperator(vec[0]))
{
case ArithmeticOperator::ADD:
file << translateAdd();
break;
case ArithmeticOperator::SUB:
file << translateSub();
break;
case ArithmeticOperator::NEG:
default:
file << translateNeg();
break;
}
if (vec[0] == "neg")
cout << translateNeg();
}
file << endl;
View File
@@ -4,17 +4,17 @@
using namespace std;
ArithmeticOperator determineArithmeticOperator(string arithmeticOperator)
{
if (arithmeticOperator == "add")
return ArithmeticOperator::ADD;
if (arithmeticOperator == "sub")
return ArithmeticOperator::SUB;
if (arithmeticOperator == "neg")
return ArithmeticOperator::NEG;
// Operation determineOperation(string operation)
// {
// if (operation == "add")
// return Operation::ADD;
// if (operation == "sub")
// return Operation::SUB;
// if (operation == "neg")
// return Operation::NEG;
return ArithmeticOperator::NEG;
}
// return Operation::NEG;
// }
string translateAdd()
{
+3 -3
View File
@@ -61,7 +61,7 @@ public:
stringstream vmCodeStream(vmCode);
string text;
smatch matched;
vector<vector<string>> tokens;
vector<vector<string>> commands;
while (getline(vmCodeStream, text, '\n'))
{
@@ -77,10 +77,10 @@ public:
{
matchedVector.push_back(text);
}
tokens.push_back(matchedVector);
commands.push_back(matchedVector);
}
return tokens;
return commands;
}
void closeFile() {
+11 -17
View File
@@ -9,20 +9,14 @@ enum Segment
TEMP,
};
enum ArithmeticOperator {
ADD,
SUB,
NEG
};
enum ComparisonOperator {
EQ,
GT,
LT,
};
enum LogicalOperator {
AND,
OR,
NOT
};
// enum Operation {
// ADD,
// SUB,
// NEG,
// EQ,
// GT,
// LT,
// AND,
// OR,
// NOT
// };