diff --git a/DMS/Debug/DMS.log b/DMS/Debug/DMS.log index 662f7a5..03034fa 100644 --- a/DMS/Debug/DMS.log +++ b/DMS/Debug/DMS.log @@ -1,2 +1,2 @@ - DMS.cpp + LineParser.cpp DMS.vcxproj -> C:\Users\Ryan\source\repos\DMS\Debug\DMS.exe diff --git a/DMS/Debug/DMS.obj b/DMS/Debug/DMS.obj index cd711bc..5192ada 100644 Binary files a/DMS/Debug/DMS.obj and b/DMS/Debug/DMS.obj differ diff --git a/DMS/Debug/DMS.tlog/CL.command.1.tlog b/DMS/Debug/DMS.tlog/CL.command.1.tlog index 0d2a8d8..67d555e 100644 Binary files a/DMS/Debug/DMS.tlog/CL.command.1.tlog and b/DMS/Debug/DMS.tlog/CL.command.1.tlog differ diff --git a/DMS/Debug/DMS.tlog/CL.read.1.tlog b/DMS/Debug/DMS.tlog/CL.read.1.tlog index 4b6f8f9..d79b043 100644 Binary files a/DMS/Debug/DMS.tlog/CL.read.1.tlog and b/DMS/Debug/DMS.tlog/CL.read.1.tlog differ diff --git a/DMS/Debug/DMS.tlog/CL.write.1.tlog b/DMS/Debug/DMS.tlog/CL.write.1.tlog index adb64a8..7145153 100644 Binary files a/DMS/Debug/DMS.tlog/CL.write.1.tlog and b/DMS/Debug/DMS.tlog/CL.write.1.tlog differ diff --git a/DMS/Debug/LineParser.obj b/DMS/Debug/LineParser.obj index 3209327..93d0007 100644 Binary files a/DMS/Debug/LineParser.obj and b/DMS/Debug/LineParser.obj differ diff --git a/DMS/Debug/cmd.obj b/DMS/Debug/cmd.obj index 99b7d42..543fb48 100644 Binary files a/DMS/Debug/cmd.obj and b/DMS/Debug/cmd.obj differ diff --git a/DMS/Debug/codes.obj b/DMS/Debug/codes.obj index 1b6cbd0..a3870e2 100644 Binary files a/DMS/Debug/codes.obj and b/DMS/Debug/codes.obj differ diff --git a/DMS/Debug/number_utils.obj b/DMS/Debug/number_utils.obj index 448e958..6569053 100644 Binary files a/DMS/Debug/number_utils.obj and b/DMS/Debug/number_utils.obj differ diff --git a/DMS/Debug/utils.obj b/DMS/Debug/utils.obj index f79d0b8..f8079b2 100644 Binary files a/DMS/Debug/utils.obj and b/DMS/Debug/utils.obj differ diff --git a/DMS/Debug/value.obj b/DMS/Debug/value.obj index 0e75c35..98218f5 100644 Binary files a/DMS/Debug/value.obj and b/DMS/Debug/value.obj differ diff --git a/DMS/Debug/vc142.idb b/DMS/Debug/vc142.idb index 268ae46..c686495 100644 Binary files a/DMS/Debug/vc142.idb and b/DMS/Debug/vc142.idb differ diff --git a/DMS/Debug/vc142.pdb b/DMS/Debug/vc142.pdb index c380367..2fe32ab 100644 Binary files a/DMS/Debug/vc142.pdb and b/DMS/Debug/vc142.pdb differ diff --git a/DMS/LineParser.cpp b/DMS/LineParser.cpp index f8f6227..2a14f27 100644 --- a/DMS/LineParser.cpp +++ b/DMS/LineParser.cpp @@ -1,13 +1,40 @@ #include "LineParser.h" using namespace dms::tokens; +using namespace dms::utils; namespace dms { + void doCheck(passer* stream,std::vector* t_vec, size_t line, bool &isNum, bool &hasDec, std::vector* buffer) { + if (isNum) { + t_vec->push_back(token{ tokens::number,codes::NOOP,stream->processBuffer(*buffer),line }); + buffer->clear(); + isNum = false; + hasDec = false; + } + else if (buffer->size() > 0) { + std::string str = stream->processBuffer(*buffer); + if (utils::isNum(str) && str.size() > 0) { + t_vec->push_back(token{ tokens::number,codes::NOOP,stream->processBuffer(*buffer),line }); + buffer->clear(); + isNum = false; + hasDec = false; + } + else if (utils::isalphanum(str) && str.size() > 0) { + t_vec->push_back(token{ tokens::name,codes::NOOP,stream->processBuffer(*buffer),line }); + buffer->clear(); + hasDec = false; + } + else { + t_vec->push_back(token{ tokens::name,codes::ERRO,"Invalid variable name!",line }); + } + } + } cmd* tokenizer(std::vector* tok) { - + cmd* c = new cmd{}; + // turn toke data into + return c; } LineParser::LineParser(std::string f) { fn = f; - } LineParser::LineParser() {} dms_state* dms::LineParser::Parse() { @@ -23,27 +50,219 @@ namespace dms { } dms_state* dms::LineParser::Parse(dms_state* state, std::string file) { std::map chunks; - std::vector tokens; + std::vector t_vec; std::string li; std::ifstream myfile(file); std::stringstream rawdata; // Read whole file into a string if (myfile.is_open()) { - rawdata << myfile.rdbuf(); + std::string line; + while (std::getline(myfile, line)) { + rawdata << line << "\n"; + } myfile.close(); - std::cout << rawdata.str() << std::endl; + //std::cout << rawdata.str() << std::endl; } else { std::cout << "Unable to open file"; delete[] state; // Cleanup return nullptr; + } + passer stream = passer(); + stream.stream = rawdata.str(); + uint8_t data = stream.next(); + std::vector buffer; + bool isStr = false; + bool isNum = false; + bool hasDec = false; + bool labelStart = false; + size_t line = 0; + while (data != NULL) { + if (data == '/' && stream.peek()=='/') { + line++; + stream.next('\n'); // Seek until you find a newline + } + else if (data == '\n') { + if (isNum) { + t_vec.push_back(token{ tokens::number,codes::NOOP,stream.processBuffer(buffer),line }); + buffer.clear(); + isNum = false; + } + line++; + data = ' '; + } + else if (data == '"' && !isStr) { + isStr = true; + } + else if (data == ':' && stream.peek()==':' && !labelStart) { + labelStart = true; + stream.next(); + } + else if (data == ':' && stream.peek() == ':' && labelStart) { + t_vec.push_back(token{ tokens::label,codes::NOOP,stream.processBuffer(buffer),line }); + buffer.clear(); + stream.next(); + labelStart = false; + } + else if (data == '\\' && stream.peek() == '"' && isStr) { + buffer.push_back('"'); + stream.next(); + } + else if (data == '"' && isStr) { + isStr = false; + t_vec.push_back(token{ tokens::string,codes::NOOP,stream.processBuffer(buffer),line }); + buffer.clear(); + } + else if (isdigit(data) ) { + isNum = true; + buffer.push_back(data); + } + else if (isalnum(data) || isStr) { + buffer.push_back(data); + } + else if (data == '.' && isNum && !hasDec) { + hasDec = true; + buffer.push_back(data); + } + else if (data == '.' && isNum && hasDec) { + t_vec.push_back(token{ tokens::number,codes::ERRO,"Malformed number!",line }); + } + else if (data == '[') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::bracketo,codes::NOOP,"",line }); + } + else if (data == ']') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::bracketc,codes::NOOP,"",line }); + } + else if (data == '(') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::parao,codes::NOOP,"",line }); + } + else if (data == ')') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::parac,codes::NOOP,"",line }); + } + else if (data == ',') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::seperator,codes::NOOP,"",line }); + } + else if (data == '.') { + //doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::dot,codes::NOOP,"",line }); + } + else if (data == '{') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::cbracketo,codes::NOOP,"",line }); + } + else if (data == '}') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::cbracketc,codes::NOOP,"",line }); + } + else if (data == '+') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::plus,codes::NOOP,"",line }); + } + else if (data == '-') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::minus,codes::NOOP,"",line }); + } + else if (data == '*') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::multiply,codes::NOOP,"",line }); + } + else if (data == '/') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::divide,codes::NOOP,"",line }); + } + else if (data == '^') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::pow,codes::NOOP,"",line }); + } + else if (data == '%') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::mod,codes::NOOP,"",line }); + } + else if (data == '=') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::equal,codes::NOOP,"",line }); + } + else if (data == ':') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::bracket,codes::NOOP,"",line }); + } + else if (data == '!') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::Not,codes::NOOP,"",line }); + } + + if (data == ' ' && !isStr) { // tokens end with a space + token tok; + std::string str = stream.processBuffer(buffer); + buffer.clear(); + if (str == "enable") { + tok.build(tokens::flag, codes::ENAB); + } else if (str == "entry") { + tok.build(tokens::flag, codes::ENTR); + } + else if (str == "loadfile") { + tok.build(tokens::flag, codes::LOAD); + } + else if (str == "version") { + tok.build(tokens::flag,codes::VERN); + } + else if (str == "using") { + tok.build(tokens::flag, codes::USIN); + } + else if (str == "if") { + tok.build(tokens::control, codes::IFFF); + } + else if (str == "elseif") { + tok.build(tokens::control, codes::ELIF); + } + else if (str == "while") { + tok.build(tokens::control, codes::WHLE); + } + else if (str == "true") { + tok.build(tokens::True, codes::NOOP); + } + else if (str == "False") { + tok.build(tokens::False, codes::NOOP); + } + else if (str == "else") { + tok.build(tokens::control, codes::ELSE); + } + else if (str == "and") { + tok.build(tokens::And, codes::NOOP); + } + else if (str == "or") { + tok.build(tokens::Or, codes::NOOP); + } + else if (str == "for") { + tok.build(tokens::For, codes::NOOP); + } + else if (utils::isalphanum(str) && str.size()>0) { + tok.build(tokens::name, str); + } + else { + // Unknown command! + tok.build(tokens::noop, codes::UNWN); + tok.name = str; + } + if (tok.raw!=codes::UNWN && tok.type != tokens::noop) { + tok.line_num = line; + t_vec.push_back(tok); + } + } + data = stream.next(); } - + std::cout << "Done!" << std::endl; + for (size_t i = 0; i < t_vec.size(); i++) { + std::cout << t_vec[i] << std::endl; + } // Data is good now let's parse - - return state; } } \ No newline at end of file diff --git a/DMS/LineParser.h b/DMS/LineParser.h index aaa3228..a7cf301 100644 --- a/DMS/LineParser.h +++ b/DMS/LineParser.h @@ -4,13 +4,50 @@ #include #include #include +#include +#include #include "codes.h" #include "cmd.h" #include "dms_state.h" #include "chunk.h" #include "token.h" +#include "utils.h" namespace dms { + struct passer { + std::string stream; + uint8_t next() { + if (stream.size() == pos) { + return NULL; + } + else { + return stream[pos++]; + } + } + void next(uint8_t c) { + next(); + while (peek() != c) { + next(); + } + } + uint8_t prev() { + if (0 == pos) { + return NULL; + } + return stream[--pos]; + } + uint8_t peek() { + if (stream.size() == pos) { + return NULL; + } + return stream[pos]; + } + std::string processBuffer(std::vector buf) { + return std::string(buf.begin(),buf.end()); + } + private: + size_t pos = 0; + }; class LineParser { std::string fn; diff --git a/DMS/codes.cpp b/DMS/codes.cpp index ded5770..5e573f1 100644 --- a/DMS/codes.cpp +++ b/DMS/codes.cpp @@ -1,3 +1,3 @@ #pragma once #include "Codes.h" -const std::string dms::codes::list[] = { "NOOP","ENTR","ENAB","DISA","LOAD","VERN","USIN","STAT","DISP","ASGN","LABL","CHOI","OPTN","FORE","????","WHLE","FNWR","FNNR","IFFF","ELIF","ELSE","DEFN","SKIP","COMP","INDX","JMPZ","INST" }; \ No newline at end of file +const std::string dms::codes::list[] = { "NOOP","ENTR","ENAB","DISA","LOAD","VERN","USIN","STAT","DISP","ASGN","LABL","CHOI","OPTN","FORE","????","WHLE","FNWR","FNNR","IFFF","ELIF","ELSE","DEFN","SKIP","COMP","INDX","JMPZ","INST","ERRO" }; \ No newline at end of file diff --git a/DMS/codes.h b/DMS/codes.h index 3a84a70..ee2462d 100644 --- a/DMS/codes.h +++ b/DMS/codes.h @@ -29,7 +29,8 @@ namespace dms::codes { COMP, INDX, JMPZ, - INST + INST, + ERRO }; extern const std::string list[]; static bool isControl(const op code) { diff --git a/DMS/string_utils.cpp b/DMS/string_utils.cpp index f1dee3b..596718d 100644 --- a/DMS/string_utils.cpp +++ b/DMS/string_utils.cpp @@ -1,12 +1,12 @@ #include "string_utils.h" -char16_t* copyStr(dms::dms_string str, size_t start, size_t size) { - char16_t* newptr = new char16_t[size]; +uint8_t* copyStr(dms::dms_string str, size_t start, size_t size) { + uint8_t* newptr = new uint8_t[size]; std::copy(str.val + start, str.val + start + size, newptr); return newptr; } -char16_t* copyStr(dms::dms_string str, dms::dms_number start, dms::dms_number size) { - char16_t* newptr = new char16_t[size.getValue()]; +uint8_t* copyStr(dms::dms_string str, dms::dms_number start, dms::dms_number size) { + uint8_t* newptr = new uint8_t[size.getValue()]; std::copy(str.val + (size_t)start.getValue(), str.val + (size_t)start.getValue() + (size_t)size.getValue(), newptr); return newptr; } @@ -19,7 +19,7 @@ namespace dms::string_utils { } if (utils::typeassert(state, args, string)) { size_t size = args.args[0].s->length; - char16_t* newptr = copyStr(*args.args[0].s, 0, size); + uint8_t* newptr = copyStr(*args.args[0].s, 0, size); std::reverse(newptr, newptr + size); dms_string* newstr = new dms_string{ size, newptr }; return newstr; @@ -42,11 +42,12 @@ namespace dms::string_utils { } else { - char16_t* newptr = copyStr(str, start, size); + uint8_t* newptr = copyStr(str, start, size); dms_string* newstr = new dms_string{ size,newptr }; return newstr; } } + return buildString(""); } //string dms_string* upper(dms_state* state, dms_args args) { @@ -56,7 +57,7 @@ namespace dms::string_utils { } if (utils::typeassert(state, args, string)) { dms_string str = *args.args[0].s; - char16_t* newptr = copyStr(str, 0, str.length); + uint8_t* newptr = copyStr(str, 0, str.length); std::transform(newptr, newptr + str.length, newptr, toupper); dms_string* newstr = new dms_string{ str.length, newptr }; return newstr; @@ -71,7 +72,7 @@ namespace dms::string_utils { } if (utils::typeassert(state, args, string)) { dms_string str = *args.args[0].s; - char16_t* newptr = copyStr(str, 0, str.length); + uint8_t* newptr = copyStr(str, 0, str.length); std::transform(newptr, newptr + str.length, newptr, tolower); dms_string* newstr = new dms_string{ str.length, newptr }; return newstr; @@ -166,6 +167,7 @@ namespace dms::string_utils { if (utils::typeassert(state, args, string, string)) { return buildBool(indexOf(state, args)->val != -1); } + return buildBool(false); } //string number dms_string* repeat(dms_state* state, dms_args args) { @@ -182,5 +184,6 @@ namespace dms::string_utils { temp << newstr; return buildString(temp.str()); } + return buildString(""); } } \ No newline at end of file diff --git a/DMS/test.dms b/DMS/test.dms index 3eb020c..02618af 100644 --- a/DMS/test.dms +++ b/DMS/test.dms @@ -1,17 +1,15 @@ entry main enable warnings //enable debugging -define -loadfile loadtest.dms -define +loadfile "loadtest.dms" version 1.2 -using extendedDefine as +using extendedDefine [main] "This works!" "What's up" - Ryan "Hello how are you doing?" // this is a comment + Ryan "Hello \"how\" are you doing?" // this is a comment Bob "I'm good you?" tester = "Hello" @@ -22,12 +20,7 @@ using extendedDefine as list,test = {{1,2+food,hi[3]},true,tester,123,"This is a string!",false, {3,2,1}},5 a = list[1] - /* - heheheh - sdfsdf - ghgfh - kjuty - */ + hungry = (-2+4-((5*5)/sqrt(144+5)))^2*2+2 list[1] = "Hello" var1,var2 = func(1,"string", 2+5) @@ -36,33 +29,36 @@ using extendedDefine as ::label:: //Hello im testing stuff - choice "Pick one:" + choice "Pick one:"{ "first" func() "second" func() "third" func() "forth" func() + } for x = 1,10 for y = 1,10 - for z = 1,10 + for z = 1,10 { "test" "$x$ $y$ $z$" - + } test = true test2 = false while cond ... - if (func(123)!=name[1] or true == "Bob") and foodCount >= 10.34 + if (func(123)!=name[1] or true == "Bob") and foodCount >= 10.34 { "test=true or test2=false!" "help me" - if cool == true + if cool == true { "We are here" "Nested if" + } elseif food >= 21 "This is getting weird" "Hi" - elseif (func2(321)!=name2[1] or true == "Bob2") and foodCount2 >= 100.78 + } + elseif (func2(321)!=name2[1] or true == "Bob2") and foodCount2 >= 1.78 "This Block" else "That Block" diff --git a/DMS/token.h b/DMS/token.h index b66a3a2..40f87e9 100644 --- a/DMS/token.h +++ b/DMS/token.h @@ -1,17 +1,85 @@ #pragma once #include +#include "codes.h" namespace dms::tokens { enum tokentype { + noop, flag, name, number, - boolean, string, parao, parac, - }; + bracketo, + bracketc, + seperator, + dot, + cbracketo, + cbracketc, + plus, + minus, + multiply, + divide, + pow, + mod, + equal, + bracket, + control, + True, + False, + Or, + And, + Not, + For, + label + };//stream, t_vec, line, isNum, buffer struct token { - tokentype type; - std::string raw; + tokentype type = noop; + codes::op raw = codes::NOOP; + std::string name=""; + size_t line_num=0; + void build(tokentype tt, codes::op o) { + type = tt; + raw = o; + } + void build(tokentype tt, std::string s) { + type = tt; + name = s; + } + friend std::ostream& operator << (std::ostream& out, const token& c) { + const std::string temp1[] = { + "noop", + "flag", + "name", + "number", + "string", + "parao", + "parac", + "bracketo", + "bracketc", + "seperator", + "dot", + "cbracketo", + "cbracketc", + "plus", + "minus", + "multiply", + "divide", + "pow", + "mod", + "equal", + "bracket", + "control", + "true", + "false", + "or", + "and", + "not", + "for", + "label" + }; + out << "Line <" << c.line_num << ">" << codes::list[c.raw] << " " << temp1[c.type] << " \t\t " << c.name; + return out; + } }; } \ No newline at end of file diff --git a/DMS/utils.cpp b/DMS/utils.cpp index 13689a4..da46f9e 100644 --- a/DMS/utils.cpp +++ b/DMS/utils.cpp @@ -1,5 +1,26 @@ #include "utils.h" namespace dms::utils { + bool isalphanum(std::string str) { + for (size_t i = 0; i < str.size(); i++) { + if (!isalnum(str[i]) && str[i]!='_') + return false; + } + return true; + } + bool isalpha(std::string str) { + for (size_t i = 0; i < str.size(); i++) { + if (!std::isalpha(str[i]) && str[i] != '_') + return false; + } + return true; + } + bool isNum(std::string str) { + for (size_t i = 0; i < str.size(); i++) { + if (!std::isdigit(str[i]) && str[i] != '.') + return false; + } + return true; + } std::string random_string(size_t length) { auto randchar = []() -> char diff --git a/DMS/utils.h b/DMS/utils.h index 14651b5..8e04d6f 100644 --- a/DMS/utils.h +++ b/DMS/utils.h @@ -21,4 +21,7 @@ namespace dms::utils { bool typeassert(dms_args args, datatypes t1=nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); //Type asserting is mostly an internal thing for build in methods. It's not needed for dms code! bool typeassert(dms_state* state, dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); std::string resolveTypes(datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); + bool isalphanum(std::string str); + bool isalpha(std::string str); + bool isNum(std::string str); } \ No newline at end of file diff --git a/DMS/value.cpp b/DMS/value.cpp index a7b68a9..a99fc19 100644 --- a/DMS/value.cpp +++ b/DMS/value.cpp @@ -7,7 +7,7 @@ namespace dms { dms_string* buildString(std::string str) { size_t len = str.length(); - char16_t* arr = new char16_t[len]; + uint8_t* arr = new uint8_t[len]; for (size_t i = 0; i < len; i++) { arr[i] = str.at(i); } @@ -50,77 +50,66 @@ namespace dms { bool value::typeMatch(const value o) const { return type == o.type; } - bool value::set(dms_string* str) { - try { - s = str; - delete[] b; - delete[] n; - delete[] e; - delete[] c; - b = nullptr; - n = nullptr; - e = nullptr; - c = nullptr; - type = dms::string; - return true; - } - catch (...) { - return false; - } + void value::set(dms_string* str) { + s = str; + delete[] b; + delete[] n; + delete[] e; + delete[] c; + b = nullptr; + n = nullptr; + e = nullptr; + c = nullptr; + type = string; } - bool value::set(dms_boolean* bo) { - try { - b = bo; - delete[] s; - delete[] n; - delete[] e; - delete[] c; - s = nullptr; - n = nullptr; - e = nullptr; - c = nullptr; - type = dms::boolean; - return true; - } - catch (...) { - return false; - } + void value::set(dms_boolean* bo) { + b = bo; + delete[] s; + delete[] n; + delete[] e; + delete[] c; + s = nullptr; + n = nullptr; + e = nullptr; + c = nullptr; + type = boolean; } - bool value::set(dms_number* num) { - try { - n = num; - delete[] b; - delete[] s; - delete[] e; - delete[] c; - b = nullptr; - s = nullptr; - e = nullptr; - c = nullptr; - type = dms::number; - return true; - } - catch (...) { - return false; - } + void value::set(dms_number* num) { + n = num; + delete[] b; + delete[] s; + delete[] e; + delete[] c; + b = nullptr; + s = nullptr; + e = nullptr; + c = nullptr; + type = number; } - bool dms::value::set(dms_env* en) { - try { - e = en; - delete[] b; - delete[] s; - delete[] n; - delete[] c; - b = nullptr; - n = nullptr; - s = nullptr; - c = nullptr; - type = dms::env; - return true; - } - catch (...) { - return false; - } + void dms::value::set(dms_env* en) { + e = en; + delete[] b; + delete[] s; + delete[] n; + delete[] c; + b = nullptr; + n = nullptr; + s = nullptr; + c = nullptr; + type = env; + } + void value::set() { + delete[] b; + delete[] s; + delete[] n; + delete[] e; + delete[] c; + s = nullptr; + n = nullptr; + e = nullptr; + c = nullptr; + b = nullptr; + type = nil; } std::string dms_string::getValue() { std::stringstream temp; @@ -137,10 +126,23 @@ namespace dms { void dms_env::pushValue(value ind, value val) { if (ind.type == number) { size_t size = ipart.size(); - ipart.insert_or_assign(ind.n->val,val); - } - else { - hpart.insert_or_assign(ind.toString(), val); + if (val.type == nil) { + ipart.erase(ind.n->val); + count--; + } + else { + ipart.insert_or_assign(ind.n->val, val); + count++; + } + } else { + if (val.type == nil) { + hpart.erase(ind.toString()); + count--; + } + else { + hpart.insert_or_assign(ind.toString(), val); + count++; + } } } value dms_env::getValue(value ind) { diff --git a/DMS/value.h b/DMS/value.h index e47cd50..ccfc024 100644 --- a/DMS/value.h +++ b/DMS/value.h @@ -25,7 +25,7 @@ namespace dms { }; struct dms_string { size_t length = 0; - char16_t* val = nullptr; + uint8_t* val = nullptr; std::string getValue(); friend std::ostream& operator << (std::ostream& out, const dms_string& c) { for (size_t i = 0; i < c.length; i++) { @@ -47,10 +47,11 @@ namespace dms { dms_string* s = nullptr; dms_env* e = nullptr; dms_custom* c = nullptr; - bool set(dms_string* str); - bool set(dms_boolean* bo); - bool set(dms_number* num); - bool set(dms_env* en); + void set(dms_string* str); + void set(dms_boolean* bo); + void set(dms_number* num); + void set(dms_env* en); + void set(); bool typeMatch(const value o) const; std::string toString(); friend bool operator<(const value& l, const value& r) @@ -99,7 +100,9 @@ namespace dms { std::map hpart; std::map ipart; void pushValue(value val); - void pushValue(value str, value val); + void pushValue(value ind, value val); value getValue(value val); + private: + size_t count = 0; }; } diff --git a/Debug/DMS.exe b/Debug/DMS.exe index 246f3d2..f9e7254 100644 Binary files a/Debug/DMS.exe and b/Debug/DMS.exe differ diff --git a/Debug/DMS.ilk b/Debug/DMS.ilk index 045c4c1..072f456 100644 Binary files a/Debug/DMS.ilk and b/Debug/DMS.ilk differ diff --git a/Debug/DMS.pdb b/Debug/DMS.pdb index 6727f4b..f1d5f62 100644 Binary files a/Debug/DMS.pdb and b/Debug/DMS.pdb differ