mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
chore: add segment names to parsed commands for easier translations
This commit is contained in:
+5
-3
@@ -12,9 +12,11 @@ int parseCommand(std::vector<Command> &commands, std::string line) {
|
|||||||
Command cmd;
|
Command cmd;
|
||||||
|
|
||||||
if (matched.ready()) {
|
if (matched.ready()) {
|
||||||
|
std::string segment = matched[2];
|
||||||
cmd.line = line;
|
cmd.line = line;
|
||||||
cmd.type = commandTypes.at(matched[1]);
|
cmd.commandType = commandTypes.at(matched[1]);
|
||||||
cmd.segment = segmentTypes.at(matched[2]);
|
cmd.segmentType = segmentTypes.at(segment);
|
||||||
|
cmd.segmentName = segmentNames.at(segment);
|
||||||
cmd.index = std::stoi(std::string(matched[3]));
|
cmd.index = std::stoi(std::string(matched[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ int parseCommand(std::vector<Command> &commands, std::string line) {
|
|||||||
Command cmd;
|
Command cmd;
|
||||||
|
|
||||||
cmd.line = line;
|
cmd.line = line;
|
||||||
cmd.type = commandTypes.at(matched[1]);
|
cmd.commandType = commandTypes.at(matched[1]);
|
||||||
|
|
||||||
commands.push_back(cmd);
|
commands.push_back(cmd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+9
-2
@@ -44,10 +44,17 @@ std::unordered_map<std::string, SegmentType> const segmentTypes = {
|
|||||||
{"temp", SegmentType::TEMP}, {"pointer", SegmentType::POINTER},
|
{"temp", SegmentType::TEMP}, {"pointer", SegmentType::POINTER},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::unordered_map<std::string, std::string> const segmentNames = {
|
||||||
|
{"local", "LCL"}, {"argument", "ARG"}, {"this", "THIS"},
|
||||||
|
{"that", "THAT"}, {"static", "NONE"}, {"constant", "NONE"},
|
||||||
|
{"temp", "NONE"}, {"pointer", "NONE"},
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
std::string line;
|
std::string line;
|
||||||
CommandType type;
|
CommandType commandType;
|
||||||
SegmentType segment;
|
SegmentType segmentType;
|
||||||
|
std::string segmentName;
|
||||||
int index;
|
int index;
|
||||||
} Command;
|
} Command;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user