202608290119
This commit is contained in:
1 parent
6130e5d54a
commit
ef77c07819
2 files changed
+24
-6
No files matched your search
+13
-3
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -54,7 +56,13 @@ private:
|
||||
const std::set<std::string> raw_rot8_ins = {"stp", "btp", "ror", "flb",
|
||||
"biz", "rnz", "out", "inp"};
|
||||
|
||||
token_stream(const std::string &filename);
|
||||
token_stream(const std::string &filename) {
|
||||
this->filename = filename;
|
||||
std::ifstream file(filename); // TODO: when open failed
|
||||
std::stringstream buf;
|
||||
buf << file.rdbuf();
|
||||
lines = lex(buf.str());
|
||||
}
|
||||
std::vector<token_line> lex(const std::string &char_stream);
|
||||
};
|
||||
|
||||
@@ -77,8 +85,10 @@ private:
|
||||
};
|
||||
|
||||
class ast {
|
||||
private:
|
||||
public:
|
||||
ast_node root = {r8asm::ast_node_t::CODEBLOCK, "", {}};
|
||||
|
||||
private:
|
||||
addr dataptr = 0;
|
||||
std::vector<std::map<std::string, general_data>> scopes = {{}};
|
||||
std::map<std::string, ast_node> macros;
|
||||
@@ -168,5 +178,5 @@ private:
|
||||
|
||||
public:
|
||||
std::string export_rot8();
|
||||
bool import_file(std::string filename);
|
||||
bool import_file(const std::string &filename);
|
||||
};
|
||||
+11
-3
@@ -1,5 +1,6 @@
|
||||
#include "r8asm/r8asm.hh"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
@@ -668,9 +669,9 @@ r8asm::token_stream::lex(const std::string &char_stream) {
|
||||
} else
|
||||
token_buffer.push_back({r8asm::token_t::RQUOTE, token_val});
|
||||
} else if (token_val[0] == '(')
|
||||
token_buffer.push_back({r8asm::token_t::LPAREN,token_val});
|
||||
token_buffer.push_back({r8asm::token_t::LPAREN, token_val});
|
||||
else if (token_val[0] == ')')
|
||||
token_buffer.push_back({r8asm::token_t::RPAREN,token_val});
|
||||
token_buffer.push_back({r8asm::token_t::RPAREN, token_val});
|
||||
else if (std::string(OPERATORS).find(token_val[0]) !=
|
||||
std::string::npos) // operator
|
||||
token_buffer.push_back(
|
||||
@@ -688,4 +689,11 @@ r8asm::token_stream::lex(const std::string &char_stream) {
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
#undef OPERATORS
|
||||
#undef OPERATORS
|
||||
|
||||
bool r8asm::import_file(const std::string &filename) {
|
||||
for (const auto &token_it : parse(token_stream(filename)).children) {
|
||||
main_tree.root.children.push_back(token_it);
|
||||
}
|
||||
return true; // TODO: ERROR CHECK
|
||||
}
|
||||
Reference in new issue
Block a user