feat: parser initial scaffolding

This commit is contained in:
2026-03-26 13:18:00 +01:00
parent 595914175b
commit 5986a509e2
2 changed files with 45 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#include <iostream>
#include <regex>
#include <string>
#include "parser.hpp"
int parseCommand(LinkedList<Command> *commands, std::string line) {
std::smatch matched;
if (regex_search(line, matched, std::regex("^(.*) (.*) (.*)"))) {
Command cmd;
int err;
cmd.line = line;
cmd.type = commandTypes.at(matched[0]);
cmd.segment = segmentTypes.at(matched[1]);
cmd.index = std::stoi(matched[2]);
if ((err = insertNode(commands, cmd)) != 0) {
std::cerr << "Unexpected error parsing vm command:" << line << std::endl;
return 1;
}
}
if (regex_search(line, matched, std::regex("^(.*)"))) {
Command cmd;
int err;
cmd.line = line;
cmd.type = matched[0];
if ((err = insertNode(commands, cmd)) != 0) {
std::cerr << "Unexpected error parsing vm command:" << line << std::endl;
return 1;
}
}
return 0;
}
+6
View File
@@ -0,0 +1,6 @@
#include <string>
#include "linked-list.hpp"
#include "types.hpp"
int parseCommand(LinkedList<Command> *, std::string);