diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | main.cpp | 75 | ||||
-rw-r--r-- | main.hpp | 4 |
4 files changed, 49 insertions, 35 deletions
@@ -4,3 +4,4 @@ a.out valgrind-out.txt* *core* ž +*.swp @@ -2,8 +2,8 @@ DESTDIR=/ SRCFILE=main.cpp BINFILE=ov O=0 -CFLAGS += -Wextra -Wall -g -O$O -I. -o$(BINFILE) -finput-charset=UTF-8 -fextended-identifiers -LIBS += +CFLAGS += -Wextra -Wall -g -O$O -I. -o$(BINFILE) -finput-charset=UTF-8 -fextended-identifiers $(shell pkg-config muparserx --cflags) +LIBS += $(shell pkg-config muparserx --libs) CC=c++ VGARGS += --leak-check=full --track-origins=yes --verbose --log-file=valgrind-out.txt --suppressions=/usr/lib/i386-linux-gnu/valgrind/default.supp --show-leak-kinds=all --leak-resolution=high @@ -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) { @@ -74,8 +74,8 @@ namespace ov { }; // privzeto inicializiran na NOOP inštrukcijo struct def { vector<string> args; - string body(""); - } + string body; + }; class Ov; template<typename value_type, typename index_type> class Ram { private: |