From 77fdcb4cf8d05bd8984329614035c227b96c1d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Fri, 4 Feb 2022 12:28:44 +0000 Subject: oddaljeno delo --- .gitignore | 1 + Makefile | 4 ++-- main.cpp | 75 ++++++++++++++++++++++++++++++++++++-------------------------- main.hpp | 4 ++-- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 396601d..6f5641f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ a.out valgrind-out.txt* *core* ž +*.swp diff --git a/Makefile b/Makefile index 437de56..3127871 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/main.cpp b/main.cpp index 74b9fad..35b3f08 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,8 @@ +#include #include "main.hpp" using namespace std; using namespace ov; +using namespace mup; namespace ov { template value_type Ram::peek (index_type addr) { @@ -192,59 +194,70 @@ namespace ov { } vector assembler (string v) { map defs; - vector; - int hiaddr = 0; - int i = 0; - while (i < v.length) { + vector 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) { diff --git a/main.hpp b/main.hpp index 1794b7a..e099986 100644 --- a/main.hpp +++ b/main.hpp @@ -74,8 +74,8 @@ namespace ov { }; // privzeto inicializiran na NOOP inštrukcijo struct def { vector args; - string body(""); - } + string body; + }; class Ov; template class Ram { private: -- cgit v1.2.3