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;
|
||||
|
||||
if (matched.ready()) {
|
||||
std::string segment = matched[2];
|
||||
cmd.line = line;
|
||||
cmd.type = commandTypes.at(matched[1]);
|
||||
cmd.segment = segmentTypes.at(matched[2]);
|
||||
cmd.commandType = commandTypes.at(matched[1]);
|
||||
cmd.segmentType = segmentTypes.at(segment);
|
||||
cmd.segmentName = segmentNames.at(segment);
|
||||
cmd.index = std::stoi(std::string(matched[3]));
|
||||
}
|
||||
|
||||
@@ -26,7 +28,7 @@ int parseCommand(std::vector<Command> &commands, std::string line) {
|
||||
Command cmd;
|
||||
|
||||
cmd.line = line;
|
||||
cmd.type = commandTypes.at(matched[1]);
|
||||
cmd.commandType = commandTypes.at(matched[1]);
|
||||
|
||||
commands.push_back(cmd);
|
||||
return 0;
|
||||
|
||||
+9
-2
@@ -44,10 +44,17 @@ std::unordered_map<std::string, SegmentType> const segmentTypes = {
|
||||
{"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 {
|
||||
std::string line;
|
||||
CommandType type;
|
||||
SegmentType segment;
|
||||
CommandType commandType;
|
||||
SegmentType segmentType;
|
||||
std::string segmentName;
|
||||
int index;
|
||||
} Command;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user