diff --git a/DMS/DMS.cpp b/DMS/DMS.cpp index da07f39..8b5d578 100644 --- a/DMS/DMS.cpp +++ b/DMS/DMS.cpp @@ -2,21 +2,24 @@ // #include -#include -#include +//#include +//#include +#include "value.h" +#include "codes.h" +#include "cmd.h" +#include "dms_exceptions.h" +#include "errors.h" +#include "utils.h" +#include "number_utils.h" +#include "string_utils.h" +#include "LineParser.h" #include "dms.h" +#include "chunk.h" +#include "token.h" using namespace dms; using namespace dms::utils; - int main() { - /* - TODO - - Work on LineParser, chunk and state - We need to parse the dms file. - Might need to rework the syntax a bit - */ LineParser parser = LineParser("test.dms"); parser.Parse(); print("Goodbye!"); diff --git a/DMS/DMS.vcxproj b/DMS/DMS.vcxproj index d88dedd..bc716a6 100644 --- a/DMS/DMS.vcxproj +++ b/DMS/DMS.vcxproj @@ -103,6 +103,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console diff --git a/DMS/Debug/DMS.obj b/DMS/Debug/DMS.obj index 2449605..d34117d 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 67d555e..b7b9314 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 d79b043..68da36c 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 e4b1204..b63787c 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 0d0f275..e2ca299 100644 Binary files a/DMS/Debug/LineParser.obj and b/DMS/Debug/LineParser.obj differ diff --git a/DMS/Debug/byte.obj b/DMS/Debug/byte.obj deleted file mode 100644 index 4dbbd08..0000000 Binary files a/DMS/Debug/byte.obj and /dev/null differ diff --git a/DMS/Debug/cmd.obj b/DMS/Debug/cmd.obj index 543fb48..f530845 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 a3870e2..dcf882d 100644 Binary files a/DMS/Debug/codes.obj and b/DMS/Debug/codes.obj differ diff --git a/DMS/Debug/dms.new.obj.enc b/DMS/Debug/dms.new.obj.enc deleted file mode 100644 index 4fef3f0..0000000 Binary files a/DMS/Debug/dms.new.obj.enc and /dev/null differ diff --git a/DMS/Debug/dms_exceptions.obj b/DMS/Debug/dms_exceptions.obj index e517d25..66ed778 100644 Binary files a/DMS/Debug/dms_exceptions.obj and b/DMS/Debug/dms_exceptions.obj differ diff --git a/DMS/Debug/dmsstring.obj b/DMS/Debug/dmsstring.obj deleted file mode 100644 index f2a3b58..0000000 Binary files a/DMS/Debug/dmsstring.obj and /dev/null differ diff --git a/DMS/Debug/env.obj b/DMS/Debug/env.obj deleted file mode 100644 index 441d55e..0000000 Binary files a/DMS/Debug/env.obj and /dev/null differ diff --git a/DMS/Debug/line.obj b/DMS/Debug/line.obj deleted file mode 100644 index dc0e8ce..0000000 Binary files a/DMS/Debug/line.obj and /dev/null differ diff --git a/DMS/Debug/number_utils.obj b/DMS/Debug/number_utils.obj index 6569053..260a4ce 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 f8079b2..6d3d20b 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 98218f5..9ea0786 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 64bd562..709d09f 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 94eba8d..bc3e133 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 1ef190d..9b5e473 100644 --- a/DMS/LineParser.cpp +++ b/DMS/LineParser.cpp @@ -3,6 +3,25 @@ using namespace dms::tokens; using namespace dms::utils; namespace dms { + void tokenstream::init(std::vector* ptr) { + this->tokens = *ptr; + } + token tokenstream::next() { + if (pos > this->tokens.size()) + return token{ tokentype::noop,codes::NOOP,"EOF",0 }; + return this->tokens[pos++]; + } + token tokenstream::peek() { + return this->tokens[pos]; + } + std::vector tokenstream::next(tokens::tokentype tk, size_t n) { + std::vector temp; + while (peek().type!=tk) { + temp.push_back(next()); + } + temp.push_back(next()); + return temp; + } uint8_t passer::next() { if (stream.size() == pos) { return NULL; @@ -57,14 +76,102 @@ namespace dms { } } } - cmd* LineParser::getPattern(std::vector &tok) { - cmd* c = new cmd(); - - return c; + void wait() { + std::cin.ignore(); } - std::vector LineParser::tokenizer(std::vector &tok) { - std::vector chunks; - // turn token data into + bool LineParser::match(tokenstream stream, tokens::tokentype t1, tokens::tokentype t2, tokens::tokentype t3, tokens::tokentype t4, tokens::tokentype t5, tokens::tokentype t6, tokens::tokentype t7, tokens::tokentype t8, tokens::tokentype t9, tokens::tokentype t10, tokens::tokentype t11, tokens::tokentype t12) { + tokens::tokentype types[12] = { t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12 }; + for (size_t i = 0; i < 12; i++) { + if (types[i] == tokens::none) + return true; + if (stream.tokens[stream.pos+i].type != types[i]) + return false; + print(stream.tokens[stream.pos + i].type, " | ", types[i]); + } + return true; + } + std::map LineParser::tokenizer(dms_state* state,std::vector &toks) { + std::map chunks; + chunk* current_chunk = nullptr; + std::string chunk_name; + blocktype chunk_type; + + tokenstream stream; + stream.init(&toks); + token current = stream.next(); + std::vector temp; + while (stream.peek().type != tokens::eof) { + print(current); + if (current.type == tokens::flag) { + temp = stream.next(tokens::newline); + if (temp.size() != 2) { + std::cout << ""; + } + codes::op code = current.raw; + tokens::tokentype tok = temp[0].type; + if (code == codes::ENAB && tok == tokens::name) { + state->enables.insert_or_assign(temp[0].name,true); + } + else if (code == codes::ENTR && tok == tokens::name) { + state->entry = temp[0].name; + } + else if (code == codes::DISA && tok == tokens::name) { + state->enables.insert_or_assign(temp[0].name, false); + } + else if (code == codes::VERN && tok == tokens::number) { + state->version = std::stod(temp[0].name); + } + else if (code == codes::USIN && tok == tokens::name) { + // TODO add usings, kinda useless since everything will be packed in. Perhaps extensions might work + } + else if (code == codes::LOAD && tok == tokens::string) { + Parse(state, temp[0].name); // Load another file + } + else { + std::stringstream str; + str << "Expected " << " got: " << current << " "; + state->push_error(errors::error{errors::badtoken,str.str(),true,current.line_num}); + } + std::cout << temp.size() << std::endl; + std::cout << temp[0] << std::endl; + } + // To implement function we need to match stuff + + //Todo Finish the chunk data stuff + if (match(stream,tokens::newline,tokens::bracketo,tokens::name,tokens::bracketc)) { + stream.next(); + if (current_chunk != nullptr) + chunks.insert_or_assign(current_chunk->name, *current_chunk); + + current_chunk = new chunk; + stream.next(); // Consume + current_chunk->name = stream.next().name; + stream.next(); // Consume + } + else if (match(stream, tokens::newline, tokens::bracketo, tokens::name,tokens::colon,tokens::name, tokens::bracketc)) { + stream.next(); + stream.next(); + if (current_chunk != nullptr) + chunks.insert_or_assign(current_chunk->name, *current_chunk); + + current_chunk = new chunk; + current_chunk->name = stream.next().name; + stream.next(); + std::string temp = stream.next().name; + if (temp == "char") { + current_chunk->type = bt_character; + } + else if (temp == "env") { + current_chunk->type = bt_env; + } + else if (temp == "menu") { + current_chunk->type = bt_menu; + } + stream.next(); + } + wait(); + current = stream.next(); + } return chunks; } void LineParser::tolower(std::string &s1) { @@ -229,7 +336,7 @@ namespace dms { } else if (data == ':') { doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::bracket,codes::NOOP,"",line }); + t_vec.push_back(token{ tokens::colon,codes::NOOP,"",line }); } else if (data == '!') { doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); @@ -241,79 +348,78 @@ namespace dms { } if (data == ' ' && !isStr) { // tokens end with a space - token tok; std::string str = stream.processBuffer(buffer); tolower(str); buffer.clear(); if (str == "enable") { - tok.build(tokens::flag, codes::ENAB); + t_vec.push_back(token{ tokens::flag,codes::ENAB,"",line }); } else if (str == "entry") { - tok.build(tokens::flag, codes::ENTR); + t_vec.push_back(token{ tokens::flag,codes::ENTR,"",line }); } else if (str == "loadfile") { - tok.build(tokens::flag, codes::LOAD); + t_vec.push_back(token{ tokens::flag,codes::LOAD,"",line }); } else if (str == "version") { - tok.build(tokens::flag,codes::VERN); + t_vec.push_back(token{ tokens::flag,codes::VERN,"",line }); } else if (str == "using") { - tok.build(tokens::flag, codes::USIN); + t_vec.push_back(token{ tokens::flag,codes::USIN,"",line }); + } + else if (str == "disable") { + t_vec.push_back(token{ tokens::flag,codes::DISA,"",line }); } else if (str == "if") { - tok.build(tokens::control, codes::IFFF); + t_vec.push_back(token{ tokens::control,codes::IFFF,"",line }); } else if (str == "elseif") { - tok.build(tokens::control, codes::ELIF); + t_vec.push_back(token{ tokens::control,codes::ELIF,"",line }); } else if (str == "while") { - tok.build(tokens::control, codes::WHLE); + t_vec.push_back(token{ tokens::control,codes::WHLE,"",line }); } else if (str == "true") { - tok.build(tokens::True, codes::NOOP); + t_vec.push_back(token{ tokens::True,codes::NOOP,"",line }); } else if (str == "False") { - tok.build(tokens::False, codes::NOOP); + t_vec.push_back(token{ tokens::False,codes::NOOP,"",line }); } else if (str == "else") { - tok.build(tokens::control, codes::ELSE); + t_vec.push_back(token{ tokens::control,codes::ELSE,"",line }); } else if (str == "and") { - tok.build(tokens::And, codes::NOOP); + t_vec.push_back(token{ tokens::And,codes::NOOP,"",line }); } else if (str == "or") { - tok.build(tokens::Or, codes::NOOP); + t_vec.push_back(token{ tokens::Or,codes::NOOP,"",line }); } else if (str == "for") { - tok.build(tokens::For, codes::NOOP); + t_vec.push_back(token{ tokens::For,codes::NOOP,"",line }); } else if (str == "choice") { - tok.build(tokens::control, codes::CHOI); + t_vec.push_back(token{ tokens::control,codes::CHOI,"",line }); } else if (utils::isalphanum(str) && str.size()>0) { - tok.build(tokens::name, str); + t_vec.push_back(token{ tokens::name,codes::NOOP,str,line }); } else { // Unknown command! - tok.build(tokens::noop, codes::UNWN); + /*tok.build(tokens::noop, codes::UNWN); tok.name = str; - tok.line_num = line; - std::cout << tok; - } - if (tok.raw!=codes::UNWN && tok.type != tokens::noop) { - tok.line_num = line; - t_vec.push_back(tok); + tok.line_num = line;*/ } } data = stream.next(); } + t_vec.push_back(token{ tokens::eof,codes::NOOP,"",line+1 }); std::ofstream outputFile("dump.txt"); outputFile << "Token Dump:" << std::endl; for (size_t i = 0; i < t_vec.size(); i++) { outputFile << t_vec[i] << std::endl; } outputFile.close(); + print("Running tokenizer"); // Tokens build let's parse - tokenizer(t_vec); + tokenizer(state, t_vec); return state; } } \ No newline at end of file diff --git a/DMS/LineParser.h b/DMS/LineParser.h index cf7d96f..60a40b8 100644 --- a/DMS/LineParser.h +++ b/DMS/LineParser.h @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include "codes.h" #include "cmd.h" #include "dms_state.h" @@ -13,7 +13,16 @@ #include "token.h" #include "utils.h" + namespace dms { + struct tokenstream { + std::vector tokens; + size_t pos = 0; + void init(std::vector* ptr); + tokens::token next(); + tokens::token peek(); + std::vector next(tokens::tokentype tk, size_t n=0); + }; struct passer { std::string stream; uint8_t next(); @@ -33,8 +42,9 @@ namespace dms { dms_state* Parse(dms_state* state, std::string l); LineParser(std::string fn); LineParser(); + //Matches tokens from the stream, if the tokens match it will return true and YOU should call next on the stream. This method does not change the current position + bool match(tokenstream stream, tokens::tokentype t1=tokens::none, tokens::tokentype t2 = tokens::none, tokens::tokentype t3 = tokens::none, tokens::tokentype t4 = tokens::none, tokens::tokentype t5 = tokens::none, tokens::tokentype t6 = tokens::none, tokens::tokentype t7 = tokens::none, tokens::tokentype t8 = tokens::none, tokens::tokentype t9 = tokens::none, tokens::tokentype t10 = tokens::none, tokens::tokentype t11 = tokens::none, tokens::tokentype t12 = tokens::none); void tolower(std::string &str); - std::vector tokenizer(std::vector &tok); - cmd* getPattern(std::vector& tok); + std::map tokenizer(dms_state* state, std::vector &tok); }; } \ No newline at end of file diff --git a/DMS/chunk.cpp b/DMS/chunk.cpp index 3a07abc..a5666e4 100644 --- a/DMS/chunk.cpp +++ b/DMS/chunk.cpp @@ -1 +1,6 @@ #include "chunk.h" +namespace dms { + void chunk::addCmd(cmd c) { + cmds.push_back(c); + } +} \ No newline at end of file diff --git a/DMS/chunk.h b/DMS/chunk.h index 2af4b3b..56e75aa 100644 --- a/DMS/chunk.h +++ b/DMS/chunk.h @@ -12,8 +12,10 @@ namespace dms { struct chunk { blocktype type = bt_block; + std::string name = ""; std::vector cmds = std::vector(); size_t pos = 0; + void addCmd(cmd c); }; } diff --git a/DMS/dms_state.h b/DMS/dms_state.h index 9034683..389ca5a 100644 --- a/DMS/dms_state.h +++ b/DMS/dms_state.h @@ -1,10 +1,14 @@ #pragma once #include #include "errors.h" +#include namespace dms { class dms_state { public: void push_error(errors::error err) {}; + double version=1.0; + std::string entry = "start"; + std::map enables; }; } diff --git a/DMS/dump.txt b/DMS/dump.txt index 79c40fa..412fecd 100644 --- a/DMS/dump.txt +++ b/DMS/dump.txt @@ -6,467 +6,486 @@ Line <2>ENAB flag Line <2>NOOP name warnings Line <2>NOOP newline Line <4>NOOP newline -Line <5>LOAD flag -Line <5>NOOP string loadtest.dms -Line <5>NOOP newline -Line <6>VERN flag -Line <6>NOOP number 1.2 Line <6>NOOP newline -Line <7>USIN flag -Line <7>NOOP name extendedDefine +Line <7>VERN flag +Line <7>NOOP number 1.2 Line <7>NOOP newline +Line <8>USIN flag +Line <8>NOOP name extendedDefine Line <8>NOOP newline -Line <9>NOOP bracketo -Line <9>NOOP name main -Line <9>NOOP bracketc Line <9>NOOP newline -Line <10>NOOP tab -Line <10>NOOP string This works! +Line <10>NOOP bracketo +Line <10>NOOP name Ryan +Line <10>NOOP colon +Line <10>NOOP name char +Line <10>NOOP bracketc +Line <10>NOOP cbracketo Line <10>NOOP newline Line <11>NOOP tab -Line <11>NOOP string What's up +Line <11>NOOP name name +Line <11>NOOP equal +Line <11>NOOP string Ryan Line <11>NOOP newline +Line <12>NOOP tab +Line <12>NOOP name age +Line <12>NOOP equal +Line <12>NOOP number 21 Line <12>NOOP newline -Line <13>NOOP tab -Line <13>NOOP name ryan -Line <13>NOOP string Hello "how" are you doing? +Line <13>NOOP cbracketc +Line <13>NOOP newline Line <14>NOOP newline -Line <15>NOOP tab -Line <15>NOOP name bob -Line <15>NOOP string I'm good you? +Line <15>NOOP bracketo +Line <15>NOOP name main +Line <15>NOOP bracketc Line <15>NOOP newline Line <16>NOOP tab +Line <16>NOOP string This works! Line <16>NOOP newline Line <17>NOOP tab -Line <17>NOOP name tester -Line <17>NOOP equal -Line <17>NOOP string Hello +Line <17>NOOP string What's up Line <17>NOOP newline -Line <18>NOOP tab Line <18>NOOP newline Line <19>NOOP tab -Line <19>NOOP name food -Line <19>NOOP equal -Line <19>NOOP number 3 -Line <19>NOOP newline -Line <20>NOOP tab +Line <19>NOOP name ryan +Line <19>NOOP string Hello "how" are you doing? Line <20>NOOP newline Line <21>NOOP tab -Line <21>NOOP name hi -Line <21>NOOP equal -Line <21>NOOP cbracketo -Line <21>NOOP number 1 -Line <21>NOOP seperator -Line <21>NOOP number 2 -Line <21>NOOP seperator -Line <21>NOOP number 3 -Line <21>NOOP cbracketc +Line <21>NOOP name bob +Line <21>NOOP string I'm good you? Line <21>NOOP newline +Line <22>NOOP tab Line <22>NOOP newline Line <23>NOOP tab -Line <23>NOOP name list -Line <23>NOOP seperator -Line <23>NOOP name test -Line <23>NOOP equal -Line <23>NOOP cbracketo -Line <23>NOOP cbracketo -Line <23>NOOP number 1 -Line <23>NOOP seperator -Line <23>NOOP number 2 -Line <23>NOOP plus -Line <23>NOOP name food -Line <23>NOOP seperator -Line <23>NOOP name hi -Line <23>NOOP bracketo -Line <23>NOOP number 3 -Line <23>NOOP bracketc -Line <23>NOOP cbracketc -Line <23>NOOP seperator -Line <23>NOOP name true -Line <23>NOOP seperator Line <23>NOOP name tester -Line <23>NOOP seperator -Line <23>NOOP number 123 -Line <23>NOOP seperator -Line <23>NOOP string This is a string! -Line <23>NOOP seperator -Line <23>NOOP name false -Line <23>NOOP seperator -Line <23>NOOP cbracketo -Line <23>NOOP number 3 -Line <23>NOOP seperator -Line <23>NOOP number 2 -Line <23>NOOP seperator -Line <23>NOOP number 1 -Line <23>NOOP cbracketc -Line <23>NOOP cbracketc -Line <23>NOOP seperator -Line <23>NOOP number 5 +Line <23>NOOP equal +Line <23>NOOP string Hello Line <23>NOOP newline Line <24>NOOP tab -Line <24>NOOP name a -Line <24>NOOP equal -Line <24>NOOP name list -Line <24>NOOP bracketo -Line <24>NOOP number 1 -Line <24>NOOP bracketc Line <24>NOOP newline +Line <25>NOOP tab +Line <25>NOOP name food +Line <25>NOOP equal +Line <25>NOOP number 3 Line <25>NOOP newline Line <26>NOOP tab -Line <26>NOOP name hungry -Line <26>NOOP equal -Line <26>NOOP parao -Line <26>NOOP minus -Line <26>NOOP number 2 -Line <26>NOOP plus -Line <26>NOOP number 4 -Line <26>NOOP minus -Line <26>NOOP parao -Line <26>NOOP parao -Line <26>NOOP number 5 -Line <26>NOOP multiply -Line <26>NOOP number 5 -Line <26>NOOP parac -Line <26>NOOP divide -Line <26>NOOP name sqrt -Line <26>NOOP parao -Line <26>NOOP number 144 -Line <26>NOOP plus -Line <26>NOOP number 5 -Line <26>NOOP parac -Line <26>NOOP parac -Line <26>NOOP parac -Line <26>NOOP pow -Line <26>NOOP number 2 -Line <26>NOOP multiply -Line <26>NOOP number 2 -Line <26>NOOP plus -Line <26>NOOP number 2 Line <26>NOOP newline Line <27>NOOP tab -Line <27>NOOP name list -Line <27>NOOP bracketo -Line <27>NOOP number 1 -Line <27>NOOP bracketc +Line <27>NOOP name hi Line <27>NOOP equal -Line <27>NOOP string Hello +Line <27>NOOP cbracketo +Line <27>NOOP number 1 +Line <27>NOOP seperator +Line <27>NOOP number 2 +Line <27>NOOP seperator +Line <27>NOOP number 3 +Line <27>NOOP cbracketc Line <27>NOOP newline -Line <28>NOOP tab -Line <28>NOOP number var1 -Line <28>NOOP seperator -Line <28>NOOP name var2 -Line <28>NOOP number -Line <28>NOOP equal -Line <28>NOOP name func -Line <28>NOOP parao -Line <28>NOOP number 1 -Line <28>NOOP seperator -Line <28>NOOP string string -Line <28>NOOP seperator -Line <28>NOOP number 2 -Line <28>NOOP plus -Line <28>NOOP number 5 -Line <28>NOOP parac Line <28>NOOP newline Line <29>NOOP tab -Line <29>NOOP name a -Line <29>NOOP equal -Line <29>NOOP name 100 -Line <29>NOOP number -Line <29>NOOP plus -Line <29>NOOP name func -Line <29>NOOP parao -Line <29>NOOP number 1 +Line <29>NOOP name list Line <29>NOOP seperator -Line <29>NOOP string string +Line <29>NOOP name test +Line <29>NOOP equal +Line <29>NOOP cbracketo +Line <29>NOOP cbracketo +Line <29>NOOP number 1 Line <29>NOOP seperator Line <29>NOOP number 2 Line <29>NOOP plus +Line <29>NOOP name food +Line <29>NOOP seperator +Line <29>NOOP name hi +Line <29>NOOP bracketo +Line <29>NOOP number 3 +Line <29>NOOP bracketc +Line <29>NOOP cbracketc +Line <29>NOOP seperator +Line <29>NOOP name true +Line <29>NOOP seperator +Line <29>NOOP name tester +Line <29>NOOP seperator +Line <29>NOOP number 123 +Line <29>NOOP seperator +Line <29>NOOP string This is a string! +Line <29>NOOP seperator +Line <29>NOOP name false +Line <29>NOOP seperator +Line <29>NOOP cbracketo +Line <29>NOOP number 3 +Line <29>NOOP seperator +Line <29>NOOP number 2 +Line <29>NOOP seperator +Line <29>NOOP number 1 +Line <29>NOOP cbracketc +Line <29>NOOP cbracketc +Line <29>NOOP seperator Line <29>NOOP number 5 -Line <29>NOOP parac -Line <29>NOOP plus -Line <29>NOOP number 100 Line <29>NOOP newline Line <30>NOOP tab -Line <30>NOOP name func -Line <30>NOOP parao +Line <30>NOOP name a +Line <30>NOOP equal +Line <30>NOOP name list +Line <30>NOOP bracketo Line <30>NOOP number 1 -Line <30>NOOP seperator -Line <30>NOOP string string -Line <30>NOOP seperator -Line <30>NOOP number 2 -Line <30>NOOP plus -Line <30>NOOP number 5 -Line <30>NOOP parac +Line <30>NOOP bracketc Line <30>NOOP newline -Line <31>NOOP tab -Line <31>NOOP label label Line <31>NOOP newline Line <32>NOOP tab +Line <32>NOOP name hungry +Line <32>NOOP equal +Line <32>NOOP parao +Line <32>NOOP minus +Line <32>NOOP number 2 +Line <32>NOOP plus +Line <32>NOOP number 4 +Line <32>NOOP minus +Line <32>NOOP parao +Line <32>NOOP parao +Line <32>NOOP number 5 +Line <32>NOOP multiply +Line <32>NOOP number 5 +Line <32>NOOP parac +Line <32>NOOP divide +Line <32>NOOP name sqrt +Line <32>NOOP parao +Line <32>NOOP number 144 +Line <32>NOOP plus +Line <32>NOOP number 5 +Line <32>NOOP parac +Line <32>NOOP parac +Line <32>NOOP parac +Line <32>NOOP pow +Line <32>NOOP number 2 +Line <32>NOOP multiply +Line <32>NOOP number 2 +Line <32>NOOP plus +Line <32>NOOP number 2 +Line <32>NOOP newline +Line <33>NOOP tab +Line <33>NOOP name list +Line <33>NOOP bracketo +Line <33>NOOP number 1 +Line <33>NOOP bracketc +Line <33>NOOP equal +Line <33>NOOP string Hello Line <33>NOOP newline Line <34>NOOP tab +Line <34>NOOP number var1 +Line <34>NOOP seperator +Line <34>NOOP name var2 +Line <34>NOOP number +Line <34>NOOP equal +Line <34>NOOP name func +Line <34>NOOP parao +Line <34>NOOP number 1 +Line <34>NOOP seperator +Line <34>NOOP string string +Line <34>NOOP seperator +Line <34>NOOP number 2 +Line <34>NOOP plus +Line <34>NOOP number 5 +Line <34>NOOP parac Line <34>NOOP newline Line <35>NOOP tab -Line <35>CHOI control -Line <35>NOOP string Pick one: +Line <35>NOOP name a +Line <35>NOOP equal +Line <35>NOOP name 100 +Line <35>NOOP number +Line <35>NOOP plus +Line <35>NOOP name func +Line <35>NOOP parao +Line <35>NOOP number 1 +Line <35>NOOP seperator +Line <35>NOOP string string +Line <35>NOOP seperator +Line <35>NOOP number 2 +Line <35>NOOP plus +Line <35>NOOP number 5 +Line <35>NOOP parac +Line <35>NOOP plus +Line <35>NOOP number 100 Line <35>NOOP newline Line <36>NOOP tab -Line <36>NOOP tab -Line <36>NOOP string first Line <36>NOOP name func Line <36>NOOP parao +Line <36>NOOP number 1 +Line <36>NOOP seperator +Line <36>NOOP string string +Line <36>NOOP seperator +Line <36>NOOP number 2 +Line <36>NOOP plus +Line <36>NOOP number 5 Line <36>NOOP parac Line <36>NOOP newline Line <37>NOOP tab -Line <37>NOOP tab -Line <37>NOOP string second -Line <37>NOOP name func -Line <37>NOOP parao -Line <37>NOOP parac +Line <37>NOOP label label Line <37>NOOP newline Line <38>NOOP tab -Line <38>NOOP tab -Line <38>NOOP string third -Line <38>NOOP name func -Line <38>NOOP parao -Line <38>NOOP parac -Line <38>NOOP newline -Line <39>NOOP tab -Line <39>NOOP tab -Line <39>NOOP string forth -Line <39>NOOP name func -Line <39>NOOP parao -Line <39>NOOP parac Line <39>NOOP newline +Line <40>NOOP tab Line <40>NOOP newline Line <41>NOOP tab -Line <41>NOOP for -Line <41>NOOP name x -Line <41>NOOP equal -Line <41>NOOP number 1 -Line <41>NOOP seperator -Line <41>NOOP number 10 +Line <41>CHOI control +Line <41>NOOP string Pick one: Line <41>NOOP newline Line <42>NOOP tab Line <42>NOOP tab -Line <42>NOOP for -Line <42>NOOP name y -Line <42>NOOP equal -Line <42>NOOP number 1 -Line <42>NOOP seperator -Line <42>NOOP number 10 -Line <42>NOOP seperator -Line <42>NOOP number 1 +Line <42>NOOP string first +Line <42>NOOP name func +Line <42>NOOP parao +Line <42>NOOP parac Line <42>NOOP newline Line <43>NOOP tab Line <43>NOOP tab -Line <43>NOOP tab -Line <43>NOOP for -Line <43>NOOP name z -Line <43>NOOP equal -Line <43>NOOP number 1 -Line <43>NOOP seperator -Line <43>NOOP number 10 +Line <43>NOOP string second +Line <43>NOOP name func +Line <43>NOOP parao +Line <43>NOOP parac Line <43>NOOP newline Line <44>NOOP tab Line <44>NOOP tab -Line <44>NOOP tab -Line <44>NOOP tab -Line <44>NOOP string test +Line <44>NOOP string third +Line <44>NOOP name func +Line <44>NOOP parao +Line <44>NOOP parac Line <44>NOOP newline Line <45>NOOP tab Line <45>NOOP tab -Line <45>NOOP tab -Line <45>NOOP tab -Line <45>NOOP string $x$ $y$ $z$ +Line <45>NOOP string forth +Line <45>NOOP name func +Line <45>NOOP parao +Line <45>NOOP parac Line <45>NOOP newline -Line <46>NOOP tab -Line <46>NOOP name test -Line <46>NOOP equal -Line <46>NOOP name true Line <46>NOOP newline Line <47>NOOP tab -Line <47>NOOP name test2 -Line <47>NOOP number +Line <47>NOOP for +Line <47>NOOP name x Line <47>NOOP equal -Line <47>NOOP name false +Line <47>NOOP number 1 +Line <47>NOOP seperator +Line <47>NOOP number 10 Line <47>NOOP newline Line <48>NOOP tab +Line <48>NOOP tab +Line <48>NOOP for +Line <48>NOOP name y +Line <48>NOOP equal +Line <48>NOOP number 1 +Line <48>NOOP seperator +Line <48>NOOP number 10 +Line <48>NOOP seperator +Line <48>NOOP number 1 Line <48>NOOP newline Line <49>NOOP tab -Line <49>NOOP name count +Line <49>NOOP tab +Line <49>NOOP tab +Line <49>NOOP for +Line <49>NOOP name z Line <49>NOOP equal -Line <49>NOOP number 0 +Line <49>NOOP number 1 +Line <49>NOOP seperator +Line <49>NOOP number 10 Line <49>NOOP newline Line <50>NOOP tab +Line <50>NOOP tab +Line <50>NOOP tab +Line <50>NOOP tab +Line <50>NOOP string test Line <50>NOOP newline Line <51>NOOP tab -Line <51>WHLE control -Line <51>NOOP name count -Line <51>NOOP not -Line <51>NOOP equal -Line <51>NOOP number 100 +Line <51>NOOP tab +Line <51>NOOP tab +Line <51>NOOP tab +Line <51>NOOP string $x$ $y$ $z$ Line <51>NOOP newline Line <52>NOOP tab -Line <52>NOOP tab -Line <52>NOOP name count -Line <52>NOOP plus -Line <52>NOOP plus +Line <52>NOOP name test +Line <52>NOOP equal +Line <52>NOOP name true Line <52>NOOP newline Line <53>NOOP tab -Line <53>NOOP tab -Line <53>NOOP string Count = $count$ +Line <53>NOOP name test2 +Line <53>NOOP number +Line <53>NOOP equal +Line <53>NOOP name false Line <53>NOOP newline Line <54>NOOP tab Line <54>NOOP newline Line <55>NOOP tab -Line <55>IFFF control -Line <55>NOOP parao -Line <55>NOOP name func -Line <55>NOOP parao -Line <55>NOOP number 123 -Line <55>NOOP parac -Line <55>NOOP not +Line <55>NOOP name count Line <55>NOOP equal -Line <55>NOOP name name -Line <55>NOOP bracketo -Line <55>NOOP number 1 -Line <55>NOOP bracketc -Line <55>NOOP or -Line <55>NOOP true -Line <55>NOOP equal -Line <55>NOOP equal -Line <55>NOOP string Bob -Line <55>NOOP parac -Line <55>NOOP and -Line <55>NOOP name foodcount -Line <55>NOOP equal -Line <55>NOOP number 10.34 +Line <55>NOOP number 0 Line <55>NOOP newline Line <56>NOOP tab -Line <56>NOOP tab -Line <56>NOOP string test=true or test2=false! -Line <56>NOOP number Line <56>NOOP newline Line <57>NOOP tab -Line <57>NOOP tab -Line <57>NOOP string help me +Line <57>WHLE control +Line <57>NOOP name count +Line <57>NOOP not +Line <57>NOOP equal +Line <57>NOOP number 100 Line <57>NOOP newline Line <58>NOOP tab Line <58>NOOP tab -Line <58>IFFF control -Line <58>NOOP name cool -Line <58>NOOP equal -Line <58>NOOP equal -Line <58>NOOP name true +Line <58>NOOP name count +Line <58>NOOP plus +Line <58>NOOP plus Line <58>NOOP newline Line <59>NOOP tab Line <59>NOOP tab -Line <59>NOOP tab -Line <59>NOOP string We are here +Line <59>NOOP string Count = $count$ Line <59>NOOP newline Line <60>NOOP tab -Line <60>NOOP tab -Line <60>NOOP tab -Line <60>NOOP string Nested if Line <60>NOOP newline Line <61>NOOP tab -Line <61>NOOP tab -Line <61>ELIF control -Line <61>NOOP name food +Line <61>IFFF control +Line <61>NOOP parao +Line <61>NOOP name func +Line <61>NOOP parao +Line <61>NOOP number 123 +Line <61>NOOP parac +Line <61>NOOP not Line <61>NOOP equal -Line <61>NOOP number 21 +Line <61>NOOP name name +Line <61>NOOP bracketo +Line <61>NOOP number 1 +Line <61>NOOP bracketc +Line <61>NOOP or +Line <61>NOOP true +Line <61>NOOP equal +Line <61>NOOP equal +Line <61>NOOP string Bob +Line <61>NOOP parac +Line <61>NOOP and +Line <61>NOOP name foodcount +Line <61>NOOP equal +Line <61>NOOP number 10.34 Line <61>NOOP newline Line <62>NOOP tab Line <62>NOOP tab -Line <62>NOOP tab -Line <62>NOOP string This is getting weird +Line <62>NOOP string test=true or test2=false! +Line <62>NOOP number Line <62>NOOP newline Line <63>NOOP tab Line <63>NOOP tab -Line <63>NOOP string Hi +Line <63>NOOP string help me Line <63>NOOP newline Line <64>NOOP tab -Line <64>ELIF control -Line <64>NOOP parao -Line <64>NOOP number func2 -Line <64>NOOP parao -Line <64>NOOP number 321 -Line <64>NOOP parac -Line <64>NOOP not -Line <64>NOOP equal -Line <64>NOOP number name2 -Line <64>NOOP bracketo -Line <64>NOOP number 1 -Line <64>NOOP bracketc -Line <64>NOOP or -Line <64>NOOP true +Line <64>NOOP tab +Line <64>IFFF control +Line <64>NOOP name cool Line <64>NOOP equal Line <64>NOOP equal -Line <64>NOOP string Bob2 -Line <64>NOOP number -Line <64>NOOP parac -Line <64>NOOP and -Line <64>NOOP name foodcount2 -Line <64>NOOP number -Line <64>NOOP equal -Line <64>NOOP number 1.78 +Line <64>NOOP name true Line <64>NOOP newline Line <65>NOOP tab Line <65>NOOP tab -Line <65>NOOP string This Block +Line <65>NOOP tab +Line <65>NOOP string We are here Line <65>NOOP newline Line <66>NOOP tab -Line <66>NOOP name else +Line <66>NOOP tab +Line <66>NOOP tab +Line <66>NOOP string Nested if Line <66>NOOP newline Line <67>NOOP tab Line <67>NOOP tab -Line <67>NOOP string That Block +Line <67>ELIF control +Line <67>NOOP name food +Line <67>NOOP equal +Line <67>NOOP number 21 Line <67>NOOP newline Line <68>NOOP tab -Line <68>NOOP string ah this is why no pop +Line <68>NOOP tab +Line <68>NOOP tab +Line <68>NOOP string This is getting weird Line <68>NOOP newline +Line <69>NOOP tab +Line <69>NOOP tab +Line <69>NOOP string Hi Line <69>NOOP newline +Line <70>NOOP tab +Line <70>ELIF control +Line <70>NOOP parao +Line <70>NOOP number func2 +Line <70>NOOP parao +Line <70>NOOP number 321 +Line <70>NOOP parac +Line <70>NOOP not +Line <70>NOOP equal +Line <70>NOOP number name2 Line <70>NOOP bracketo -Line <70>NOOP name Ryan -Line <70>NOOP bracket -Line <70>NOOP name char +Line <70>NOOP number 1 Line <70>NOOP bracketc +Line <70>NOOP or +Line <70>NOOP true +Line <70>NOOP equal +Line <70>NOOP equal +Line <70>NOOP string Bob2 +Line <70>NOOP number +Line <70>NOOP parac +Line <70>NOOP and +Line <70>NOOP name foodcount2 +Line <70>NOOP number +Line <70>NOOP equal +Line <70>NOOP number 1.78 Line <70>NOOP newline Line <71>NOOP tab -Line <71>NOOP name age -Line <71>NOOP equal -Line <71>NOOP number 24 +Line <71>NOOP tab +Line <71>NOOP string This Block Line <71>NOOP newline Line <72>NOOP tab -Line <72>NOOP name money -Line <72>NOOP equal -Line <72>NOOP number 100 +Line <72>NOOP name else Line <72>NOOP newline Line <73>NOOP tab +Line <73>NOOP tab +Line <73>NOOP string That Block Line <73>NOOP newline -Line <74>NOOP bracketo -Line <74>NOOP name test -Line <74>NOOP bracket -Line <74>NOOP name env -Line <74>NOOP bracketc +Line <74>NOOP tab +Line <74>NOOP string ah this is why no pop Line <74>NOOP newline -Line <75>NOOP tab -Line <75>NOOP string test Line <75>NOOP newline +Line <76>NOOP bracketo +Line <76>NOOP name Ryan +Line <76>NOOP colon +Line <76>NOOP name char +Line <76>NOOP bracketc Line <76>NOOP newline -Line <77>NOOP bracketo -Line <77>NOOP name newblock -Line <77>NOOP bracket -Line <77>NOOP name function -Line <77>NOOP parao -Line <77>NOOP parac -Line <77>NOOP bracketc +Line <77>NOOP tab +Line <77>NOOP name age +Line <77>NOOP equal +Line <77>NOOP number 24 Line <77>NOOP newline Line <78>NOOP tab -Line <78>NOOP string Test #2 -Line <78>NOOP number +Line <78>NOOP name money +Line <78>NOOP equal +Line <78>NOOP number 100 Line <78>NOOP newline Line <79>NOOP tab -Line <79>NOOP string Does it parse this part properly? Line <79>NOOP newline +Line <80>NOOP bracketo +Line <80>NOOP name test +Line <80>NOOP colon +Line <80>NOOP name env +Line <80>NOOP bracketc +Line <80>NOOP newline +Line <81>NOOP tab +Line <81>NOOP string test +Line <81>NOOP newline +Line <82>NOOP newline +Line <83>NOOP bracketo +Line <83>NOOP name newblock +Line <83>NOOP colon +Line <83>NOOP name function +Line <83>NOOP parao +Line <83>NOOP parac +Line <83>NOOP bracketc +Line <83>NOOP newline +Line <84>NOOP tab +Line <84>NOOP string Test #2 +Line <84>NOOP number +Line <84>NOOP newline +Line <85>NOOP tab +Line <85>NOOP string Does it parse this part properly? +Line <85>NOOP newline +Line <87>NOOP eof diff --git a/DMS/errors.h b/DMS/errors.h index 39749c1..b4e9d74 100644 --- a/DMS/errors.h +++ b/DMS/errors.h @@ -7,10 +7,12 @@ namespace dms::errors { invalid_arguments, invalie_type, array_out_of_bounds, + badtoken }; struct error { errortype code=unknown; std::string err_msg; bool crash = true; // Set if you would like the state to exit + size_t linenum = 0; }; } \ No newline at end of file diff --git a/DMS/test.dms b/DMS/test.dms index 7e98c52..ce2394b 100644 --- a/DMS/test.dms +++ b/DMS/test.dms @@ -1,10 +1,15 @@ entry main enable warnings //enable debugging -loadfile "loadtest.dms" +//loadfile "loadtest.dms" version 1.2 using extendedDefine +[Ryan:char]{ + name = "Ryan" + age = 21 +} + [main] "This works!" "What's up" diff --git a/DMS/token.h b/DMS/token.h index beb339a..feaf268 100644 --- a/DMS/token.h +++ b/DMS/token.h @@ -3,6 +3,7 @@ #include "codes.h" namespace dms::tokens { enum tokentype { + none, noop, flag, name, @@ -23,7 +24,7 @@ namespace dms::tokens { pow, mod, equal, - bracket, + colon, control, True, False, @@ -33,7 +34,8 @@ namespace dms::tokens { For, label, newline, - tab + tab, + eof };//stream, t_vec, line, isNum, buffer struct token { tokentype type = noop; @@ -55,6 +57,7 @@ namespace dms::tokens { } friend std::ostream& operator << (std::ostream& out, const token& c) { const std::string temp1[] = { + "none", "noop", "flag", "name", @@ -75,7 +78,7 @@ namespace dms::tokens { "pow", "mod", "equal", - "bracket", + "colon", "control", "true", "false", @@ -85,7 +88,8 @@ namespace dms::tokens { "for", "label", "newline", - "tab" + "tab", + "eof" }; out << "Line <" << c.line_num << ">" << codes::list[c.raw] << " " << temp1[c.type] << " \t\t " << c.name; return out; diff --git a/Debug/DMS.exe b/Debug/DMS.exe index 02992e6..f2f8829 100644 Binary files a/Debug/DMS.exe and b/Debug/DMS.exe differ diff --git a/Debug/DMS.ilk b/Debug/DMS.ilk index d438ec0..4ed976c 100644 Binary files a/Debug/DMS.ilk and b/Debug/DMS.ilk differ diff --git a/Debug/DMS.pdb b/Debug/DMS.pdb index 195fe3f..71dcf18 100644 Binary files a/Debug/DMS.pdb and b/Debug/DMS.pdb differ diff --git a/test.dms b/test.dms index 7e98c52..81c12a7 100644 --- a/test.dms +++ b/test.dms @@ -1,7 +1,7 @@ entry main enable warnings //enable debugging -loadfile "loadtest.dms" +//loadfile "loadtest.dms" version 1.2 using extendedDefine