Compare commits

..

2 Commits

Author SHA1 Message Date
3e3330b046 Load symbols from the json 2026-05-19 19:35:52 +02:00
7eee6a08c8 Add predefined symbols in a json 2026-05-19 19:25:49 +02:00
2 changed files with 37 additions and 0 deletions

View File

@@ -3,6 +3,9 @@
#include <string> #include <string>
#include <cctype> #include <cctype>
#include <map> #include <map>
#include <fstream>
#include <nlohmann/json.hpp>
// Comp map // Comp map
const std::map<std::string, std::string> compMap = { const std::map<std::string, std::string> compMap = {
@@ -92,7 +95,14 @@ static inline std::string strip(const std::string &s) {
return result; return result;
} }
using symbolsMap = std::map<std::string, int>;
int main() { int main() {
// Load predefined symbols
std::ifstream file("./symbols.json");
nlohmann::json symbols_json = nlohmann::json::parse(file);
symbolsMap symbols_map = symbols_json.get<symbolsMap>();
std::string line; std::string line;
while (std::getline(std::cin, line)) { while (std::getline(std::cin, line)) {
line = trim(line); line = trim(line);

27
symbols.json Normal file
View File

@@ -0,0 +1,27 @@
{
"SP": 0,
"LCL": 1,
"ARG": 2,
"THIS": 3,
"THAT": 4,
"R0": 0,
"R1": 1,
"R2": 2,
"R3": 3,
"R4": 4,
"R5": 5,
"R6": 6,
"R7": 7,
"R8": 8,
"R9": 9,
"R10": 10,
"R11": 11,
"R12": 12,
"R13": 13,
"R14": 14,
"R15": 15,
"SCREEN": 16384,
"KBD": 24576
}