mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
chore: use vector instead of custom linked list
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
#include "linked-list.hpp"
|
||||
|
||||
template <typename T> int insertNode(LinkedList<T> *list, T data) {
|
||||
LinkedList<T> *node = new LinkedList<T>;
|
||||
|
||||
node->data = data;
|
||||
|
||||
if (list == nullptr) {
|
||||
node->next = list;
|
||||
list = node;
|
||||
} else {
|
||||
list->next = node;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
template <typename T>
|
||||
struct LinkedList {
|
||||
T data;
|
||||
struct LinkedList* next;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
int insertNode(LinkedList<T> *, T);
|
||||
+8
-2
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "parser.hpp"
|
||||
#include "utils.hpp"
|
||||
@@ -10,7 +11,7 @@ int process(std::string source) {
|
||||
std::ifstream ifs(source);
|
||||
std::string line;
|
||||
|
||||
LinkedList<Command> *commands = nullptr;
|
||||
std::vector<Command> commands;
|
||||
|
||||
while (getline(ifs, line)) {
|
||||
if (isComment(line) || isEmptyLine(line))
|
||||
@@ -18,9 +19,14 @@ int process(std::string source) {
|
||||
|
||||
int parseResult;
|
||||
|
||||
if ((parseResult = parseCommand(commands, line)) != 0)
|
||||
if ((parseResult = parseCommand(commands, line)) != 0) {
|
||||
return parseResult;
|
||||
}
|
||||
}
|
||||
|
||||
for (const Command &cmd : commands) {
|
||||
std::cout << int(cmd.type) << " " << int(cmd.segment) << " " << cmd.index << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "linked-list.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
int parseCommand(LinkedList<Command> *, std::string);
|
||||
int parseCommand(std::vector<Command>&, std::string);
|
||||
|
||||
Reference in New Issue
Block a user