diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-02-04 13:28:44 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-02-04 13:28:44 +0100 |
commit | 77fdcb4cf8d05bd8984329614035c227b96c1d8f (patch) | |
tree | bdd223b1fb71b6a61ed46d489a579e2be6bf790b /main.cpp | |
parent | za zunanje delo 2 (diff) | |
download | ov-master.tar ov-master.tar.gz ov-master.tar.bz2 ov-master.tar.lz ov-master.tar.xz ov-master.tar.zst ov-master.zip |
Diffstat (limited to '')
-rw-r--r-- | main.cpp | 75 |
1 files changed, 44 insertions, 31 deletions
@@ -1,6 +1,8 @@ +#include <mpParser.h> #include "main.hpp" using namespace std; using namespace ov; +using namespace mup; namespace ov { template<typename value_type, typename index_type> value_type Ram<value_type, index_type>::peek (index_type addr) { @@ -192,59 +194,70 @@ namespace ov { } vector<struct instr> assembler (string v) { map<string, struct def> defs; - vector<struct instr>; - int hiaddr = 0; - int i = 0; - while (i < v.length) { + vector<struct instr> r; + // unsigned int hiaddr = 0; // max address that was written to in r + // unsigned int o = 0; // output origin + unsigned int i = 0; // input string offset + ParserX p(pckCOMMON | pckUNIT | pckCOMPLEX | pckNON_COMPLEX | pckSTRING | pckMATRIX); + p.EnableAutoCreateVar(true); + while (i < v.length()) { if (i && v[i-1] == '\n' && !v.find("%define ", i)) { i += strlen("%define "); - int ž = s.find('(', i); + unsigned int ž = v.find('(', i); string dn(""); if (ž == string::npos) { - if ((ž = s.find(' ', i)) == string::npos) - if ((ž = s.find('\n', i)) == string::npos) + if ((ž = v.find(' ', i)) == string::npos) + if ((ž = v.find('\n', i)) == string::npos) throw EndlessArgument; - dn = s.substr(i, ž); + dn = v.substr(i, ž); } else { - dn = s.substr(i, s.find('(', ž)); - int k = s.find(')', ž); + dn = v.substr(i, v.find('(', ž)); + unsigned int k = v.find(')', ž); if (k == string::npos) throw EndlessArgument; - string args = s.substr(ž+1, k); - while ((k = s.find(',', ž)) != string::npos) { - defs[dn].args.push_back(s.substr(ž, k)); + string args = v.substr(ž+1, k); + while ((k = v.find(',', ž)) != string::npos) { + defs[dn].args.push_back(v.substr(ž, k)); ž = k+1; } - i = s.find(')', ž); - defs[dn].args.push_back(s.substr(ž, i)); + i = v.find(')', ž); + defs[dn].args.push_back(v.substr(ž, i)); } i++; - while (s[s.find('\n', i)-1] == '\\') { - defs[dn].body.append(s.substr(i, s.find('\n', i))); - i = s.find('\n', i)+1; + while (v[v.find('\n', i)-1] == '\\') { + defs[dn].body.append(v.substr(i, v.find('\n', i))); + i = v.find('\n', i)+1; } - defs[dn].body.append(s.substr(i, s.find('\n', i))); - i = s.find('\n', i)+1; + defs[dn].body.append(v.substr(i, v.find('\n', i))); + i = v.find('\n', i)+1; } if (i && v[i-1] == '\n' && !v.find("%macro ", i)) { i += strlen("%macro "); - if ((ž = s.find(' ', i)) == string::npos) + unsigned int ž = v.find(' ', i); + if (ž == string::npos) throw EndlessArgument; - string dn = s.substr(i, ž++); - n = atoi(s.substring(++i)); - for (int j = 0; j < n; j++) - defs[dn].args.push_back("%" << n+1); - if ((i = s.find('\n', i)) == string::npos) + string dn = v.substr(i, ž++); + unsigned int n = atoi(v.substr(++i).c_str()); + for (unsigned int j = 0; j < n; j++) { + char buffer[69]; + sprintf(buffer, "%%%u", j+1); + defs[dn].args.push_back(buffer); + } + if ((i = v.find('\n', i)) == string::npos) throw EndlessBlock; i++; - while (s.find("%endmacro", i)) { - n = s.find('\n', i)+1; - if (n == str::npos) - throw EndmacroMissing; - defs[dn].body.append(s.substr(i, n)); + while (v.find("%endmacro", i)) { + n = v.find('\n', i)+1; + if (n == string::npos) + throw EndlessBlock; + defs[dn].body.append(v.substr(i, n)); } } + if (i && v[i-1] == '\n' && !v.find(".org ", i)) { + + } } + return r; } } int main (int argc, char ** argv) { |