diff --git a/src/parser.cpp b/src/parser.cpp index 5beb8b4..6c910e6 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -12,9 +12,11 @@ int parseCommand(std::vector &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 &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; diff --git a/src/types.hpp b/src/types.hpp index e1d97a5..faa8f63 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -44,10 +44,17 @@ std::unordered_map const segmentTypes = { {"temp", SegmentType::TEMP}, {"pointer", SegmentType::POINTER}, }; +std::unordered_map 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;