From a0688f64ddbf0b16d6aafc0de8e39d8adfd172a0 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Thu, 27 Aug 2020 23:01:59 -0400 Subject: [PATCH] Starting to add cmds --- DMS syntax npp.xml | 52 ++-- DMS/DMS.cpp | 1 - DMS/DMS.vcxproj | 1 + DMS/DMS.vcxproj.filters | 3 + DMS/LineParser.cpp | 143 ++++++---- DMS/LineParser.h | 11 +- DMS/LineParserExtended.cpp | 63 +++++ DMS/chunk.cpp | 2 +- DMS/chunk.h | 5 +- DMS/dms_state.h | 5 +- DMS/dump.txt | 562 ++++++------------------------------- DMS/errors.h | 3 +- DMS/loadtest.dms | 28 ++ DMS/streams.cpp | 0 DMS/streams.h | 1 - DMS/test.dms | 33 +-- DMS/utils.cpp | 7 + DMS/utils.h | 1 + 18 files changed, 324 insertions(+), 597 deletions(-) create mode 100644 DMS/LineParserExtended.cpp create mode 100644 DMS/loadtest.dms delete mode 100644 DMS/streams.cpp delete mode 100644 DMS/streams.h diff --git a/DMS syntax npp.xml b/DMS syntax npp.xml index 098ae4d..67e0893 100644 --- a/DMS syntax npp.xml +++ b/DMS syntax npp.xml @@ -25,9 +25,9 @@ ENABLE DISABLE LOADFILE ENTRY USING VERSION as AS enable disable loadfile entry using version - if then return and or true false for while choice end else elseif goto + if then return and or true false for while choice end else elseif goto jump exit leaking debugging warnings statesave hostmsg - ceil tan CSIM log10 sinh GOTOE lshift deg MUL QUIT cosh exp rad GOTO SUB log ADD JUMP error POW randomseed floor tanh max atan SKIP acos DIV abs rshif COMPARE print atan2 asin cos sin mod sqrt function getInput sleep getVar setVar newThread setGlobalVar getGlobalVar SAVE LOAD WATCH env char + ceil tan CSIM log10 sinh GOTOE lshift deg MUL QUIT cosh exp rad GOTO SUB log ADD error POW randomseed floor tanh max atan SKIP acos DIV abs rshif COMPARE print atan2 asin cos sin mod sqrt function getInput sleep getVar setVar newThread setGlobalVar getGlobalVar SAVE LOAD WATCH env char _VERSION filesystem extendedDefine @@ -35,30 +35,30 @@ 00:: 01 02:: 03$ 04 05$ 06" 07\ 08" 09 10 11 12' 13 14' 15 16 17 18 19 20 21 22 23 - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DMS/DMS.cpp b/DMS/DMS.cpp index 8b5d578..4542ee8 100644 --- a/DMS/DMS.cpp +++ b/DMS/DMS.cpp @@ -22,5 +22,4 @@ int main() { LineParser parser = LineParser("test.dms"); parser.Parse(); - print("Goodbye!"); } \ No newline at end of file diff --git a/DMS/DMS.vcxproj b/DMS/DMS.vcxproj index b86a06e..b188331 100644 --- a/DMS/DMS.vcxproj +++ b/DMS/DMS.vcxproj @@ -147,6 +147,7 @@ + diff --git a/DMS/DMS.vcxproj.filters b/DMS/DMS.vcxproj.filters index b075295..af03e5d 100644 --- a/DMS/DMS.vcxproj.filters +++ b/DMS/DMS.vcxproj.filters @@ -54,6 +54,9 @@ Source Files\DMS + + Source Files\DMS + diff --git a/DMS/LineParser.cpp b/DMS/LineParser.cpp index cd58498..2f5dc62 100644 --- a/DMS/LineParser.cpp +++ b/DMS/LineParser.cpp @@ -1,5 +1,5 @@ #include "LineParser.h" - +#include "errors.h" using namespace dms::tokens; using namespace dms::utils; namespace dms { @@ -77,6 +77,9 @@ namespace dms { return isBlock(bt_block); // Default block type } bool LineParser::isBlock(blocktype bk_type) { + if (current_chunk == nullptr) { + return false; // If a chunk wasn't defined then code was probably defined outside of a block + } return current_chunk->type == bk_type; } void doCheck(passer* stream,std::vector* t_vec, size_t line, bool &isNum, bool &hasDec, std::vector* buffer) { @@ -177,8 +180,8 @@ namespace dms { } bool LineParser::createBlock(std::string bk_name, blocktype bk_type) { if (current_chunk != nullptr) { - if (!chunks.count(current_chunk->name)) - chunks.insert_or_assign(current_chunk->name, current_chunk); + if (!state->chunks.count(current_chunk->name)) + state->chunks.insert_or_assign(current_chunk->name, current_chunk); else { std::stringstream str; @@ -192,13 +195,12 @@ namespace dms { chunk_type = bk_type; current_chunk->type = bk_type; print("Created Block: ",bk_name," <",bk_type,">"); + return true; } void LineParser::_Parse(tokenstream stream) { token current = stream.next(); while (stream.peek().type != tokens::eof) { print(current); - if (current.type == tokens::tab) - tabs++; if (current.type == tokens::flag) { temp = stream.next(tokens::newline); stream.prev(); // Unconsume the newline piece @@ -225,7 +227,9 @@ namespace dms { // TODO add usings, kinda useless atm since everything will be packed in. Perhaps extensions? } else if (code == codes::LOAD && tok == tokens::string) { - Parse(state, temp[0].name); // Load another file + print("Loading File: ",temp[0].name); + LineParser parser = LineParser(); + parser.Parse(state, temp[0].name);// Load another file } else { std::stringstream str; @@ -239,7 +243,6 @@ namespace dms { std::string name = stream.next().name; createBlock(name,bt_block); line = stream.next().line_num; // Consume - stream.next(); // Consume } // This handles a few block types since they all follow a similar format else if (stream.match(tokens::newline, tokens::bracketo, tokens::name, tokens::colon, tokens::name, tokens::bracketc)) { @@ -260,7 +263,6 @@ namespace dms { else if (temp == "menu") { createBlock(name, bt_menu); } - stream.next(); } // Function block type else if (stream.match(tokens::newline, tokens::bracketo, tokens::name, tokens::colon, tokens::name, tokens::parao)) { @@ -303,40 +305,89 @@ namespace dms { } } // Control Handle all controls here - if (stream.match(tokens::tab, tokens::control)) { - stream.next(); // Standard consumption + if (stream.match(tokens::control)) { token control = stream.next(); if (control.raw == codes::CHOI && stream.peek().type == tokens::string) { // Let's parse choice blocks. std::string prompt = stream.next().name; print("Prompt: ", prompt); bool good = true; - size_t c = 0; - while (good) { - // We need to template the matches - if (stream.match(tokens::tab, tokens::string, tokens::name, tokens::parao)) { - stream.next(); - std::string prompt = stream.next().name; + std::string option; + cmd* c = new cmd; + // Create a unique label name by using the line number + std::string choicelabel = concat("$CHOI_END_", stream.peek().line_num); + wait(); + c->opcode = codes::CHOI; + c->args.push(buildValue(prompt)); + current_chunk->addCmd(c); // We will keep a reference to this and add to it as we go through the list - // To handle the function stuff we need to consume and process that data - // We have a method to process function data since this will be used a lot in many different places - // We just grabbed the prompt, we don't yet know how many choices we have. So we have to figure out how we can - // Process and write the bytecode for this. - std::string func = stream.next().name; - print("Choice: <", c, "> ", prompt, " Funcname: ", func); - std::vector funcstuff = stream.next(tokens::newline); + /* + What's going on here might be tough to understand just by looking at the code + The bytecode generated by this code might look something like this: - //We need to process the function data and finish creating + off op opcodes + 0 CHOI "Pick one!" "Choice 1" "Choice 2" "Choice 3" "Choice 4" + 1 FUNC print "You picked 1!" + 2 GOTO $CHOI_END_1 + 3 FUNC print "You picked 2!" + 4 GOTO $CHOI_END_1 + 5 JUMP park + 6 NOOP + 7 GOTO mylabel + 8 LABL $CHOI_END_1 - c++; + The CHOI code tells the vm that we need to process user input. The input we get in a number 0-3 + I know we have 4 choices + If the user provides us with a 0 then we need to move to off 1 + If the user provides us with a 1 then we need to move to off 3 + If the user provides us with a 2 then we need to move to off 5 + If the user provides us with a 3 then we need to move to off 7 + I'm sure you see the pattern here. 1 (+2) 3 (+2) 5... We only need to jump once then let the vm continue like normal. + The math for this is: [current_pos] + (n*2+1) + n*2+1 (n = 0) = 1 + n*2+1 (n = 1) = 3 + n*2+1 (n = 2) = 5 + n*2+1 (n = 3) = 7 + Which is why you see NOOP for the JUMP code. If GOTO wasn't the last choice possible to make there would be a NOOP after that as well. + The NOOP ensures the pattern stays. + If we are provided with a number greater than 3 then we can push an execption. + */ + while (!stream.match(tokens::cbracketc)) { + // We need to match the possible options for a choice block + /* + "option" function() + "option" goto "" + "option" goto var + "option" jump "" + "option" jump var + "option" exit [0] + + Exit takes an optional int + */ + if (stream.match(tokens::string)) { + std::string name = stream.next().name; + c->args.push(buildValue(name)); // We append the choice to the first part of the CHOI cmd + + // We consumed the option now lets do some matching, note that all of these are one liners in the bytecode! + if (match_process_function(&stream)) { + + } + else if (match_process_goto(&stream)) { + + } + else if (match_process_jump(&stream)) { + + } + else if (match_process_exit(&stream)) { + + } } - else if (stream.match(tokens::tab) || stream.match(tokens::newline)) { - stream.next(); // Allow tabs and newlines to pass like normal + // Last Match + else if (stream.match(tokens::newline)) { + stream.next(); // Consume } - else { - good = false; - print("Choice handled!"); - wait(); + else if (!stream.match(tokens::cbracketc)) { + state->push_error(errors::error{errors::choice_unknown,"Unexpected symbol!"}); } } } @@ -345,26 +396,8 @@ namespace dms { } } // Displays both with a target and without - if (stream.match(tokens::tab, tokens::string, tokens::newline)) { - // ToDo Implement the command for this - stream.next(); // Standard consumption - print("DISP := ", stream.next().name); - } - else if (stream.match(tokens::tab, tokens::name, tokens::colon, tokens::string, tokens::newline)) { - // We might have to handle scope here - // Here we mathc Name "This guy said this!" - stream.next(); // Standard consumption - std::string name = stream.next().name; - stream.next(); // That colon - std::string msg = stream.next().name; - print("DISP := ", name, " says '", msg, "'"); - // We might have to consume a newline... Depends on what's next - if (stream.hasScope(tabs)) { - // If true we might have a group of displaying stuff. - // A proper scope will have the next line contain one more tab than the last + match_process_disp(&stream); - } - } // function stuff /*if (match(stream, tokens::name, tokens::parao)) { std::string n = stream.next().name; @@ -379,9 +412,10 @@ namespace dms { tabs = 0; current = stream.next(); } - chunks.insert_or_assign(current_chunk->name, current_chunk); + state->chunks.insert_or_assign(current_chunk->name, current_chunk); } void LineParser::tokenizer(dms_state* state,std::vector &toks) { + tokenstream stream; stream.init(&toks); this->state = state; // Grab the pointer to the state and store it within the parser object _Parse(stream); @@ -414,7 +448,10 @@ namespace dms { if (myfile.is_open()) { std::string line; + rawdata << "\n\n"; // For things to work I added 2 newlines. The issue is with how I decided to parse things. + // This way you are allowed to start a block at the top of the screen! while (std::getline(myfile, line)) { + trim(line); rawdata << line << "\n"; } myfile.close(); @@ -550,6 +587,10 @@ namespace dms { doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); t_vec.push_back(token{ tokens::colon,codes::NOOP,"",line }); } + else if (data == ';') { + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::newline,codes::NOOP,"",line }); + } else if (data == '!') { doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); t_vec.push_back(token{ tokens::Not,codes::NOOP,"",line }); diff --git a/DMS/LineParser.h b/DMS/LineParser.h index 046c846..0ed5c01 100644 --- a/DMS/LineParser.h +++ b/DMS/LineParser.h @@ -43,19 +43,26 @@ namespace dms { class LineParser { std::string fn; - std::map chunks; chunk* current_chunk = nullptr; std::string chunk_name; blocktype chunk_type = bt_block; std::stack scopes; size_t line = 1; - tokenstream stream; std::vector temp; size_t tabs = 0; dms_state* state; void _Parse(tokenstream stream); + // Match Process Code + bool match_process_debug(tokenstream* stream); + bool match_process_disp(tokenstream* stream); + bool match_process_choice(tokenstream* stream); + bool match_process_function(tokenstream* stream); + bool match_process_goto(tokenstream* stream); + bool match_process_jump(tokenstream* stream); + bool match_process_exit(tokenstream* stream); public: + //Refer to streams.cpp for the match_process_CMD code. dms_state* Parse(); dms_state* Parse(std::string l); dms_state* Parse(dms_state* state, std::string l); diff --git a/DMS/LineParserExtended.cpp b/DMS/LineParserExtended.cpp new file mode 100644 index 0000000..1fd11d8 --- /dev/null +++ b/DMS/LineParserExtended.cpp @@ -0,0 +1,63 @@ +#include "LineParser.h" +using namespace dms::tokens; +using namespace dms::utils; +namespace dms { + bool LineParser::match_process_disp(tokenstream* stream) { + /* + DISP, "msg" + DISP, "msg" speaker + + Compound DISP + */ + if (isBlock(bt_block) && stream->match(tokens::newline, tokens::string, tokens::newline)) { + stream->next(); // Standard consumption + std::string msg = stream->next().name; + print("DISP := ", msg); + cmd* c = new cmd; + c->opcode = codes::DISP; + c->args.push(buildValue(msg)); + current_chunk->addCmd(c); // Add the cmd to the current chunk + return true; + } + else if (isBlock(bt_block) && stream->match(tokens::newline, tokens::name, tokens::colon, tokens::string, tokens::newline)) { + // We might have to handle scope here + // Here we match 'Ryan: "This guy said this!"' Note the colon is needed! + stream->next(); // Standard consumption + std::string name = stream->next().name; + stream->next(); // That colon + std::string msg = stream->next().name; + print("DISP := ", name, " says '", msg, "'"); + cmd* c = new cmd; + c->opcode = codes::DISP; + c->args.push(buildValue(msg)); + c->args.push(buildValue(name)); + current_chunk->addCmd(c); // Add the cmd to the current chunk + // We might have to consume a newline... Depends on what's next + return true; + } + // emotion: "path" + // looks like a simple disp command + else if (isBlock(bt_character) && stream->match(tokens::tab, tokens::name, tokens::colon, tokens::string, tokens::newline)) { + return true; + } + return false; + } + bool LineParser::match_process_debug(tokenstream* stream) { + return false; + } + bool LineParser::match_process_choice(tokenstream* stream) { + return false; + } + bool LineParser::match_process_function(tokenstream* stream) { + return false; + } + bool LineParser::match_process_goto(tokenstream* stream) { + return false; + } + bool LineParser::match_process_jump(tokenstream* stream) { + return false; + } + bool LineParser::match_process_exit(tokenstream* stream) { + return false; + } +} \ No newline at end of file diff --git a/DMS/chunk.cpp b/DMS/chunk.cpp index a5666e4..9a9dab3 100644 --- a/DMS/chunk.cpp +++ b/DMS/chunk.cpp @@ -1,6 +1,6 @@ #include "chunk.h" namespace dms { - void chunk::addCmd(cmd c) { + 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 d154a67..cfc2c94 100644 --- a/DMS/chunk.h +++ b/DMS/chunk.h @@ -14,10 +14,11 @@ namespace dms { blocktype type = bt_block; dms_args params; std::string name = ""; - std::vector cmds = std::vector(); + std::vector cmds; size_t pos = 0; size_t line = 0; - void addCmd(cmd c); + void addCmd(cmd* c); + chunk(){} }; } diff --git a/DMS/dms_state.h b/DMS/dms_state.h index 627f246..515c6af 100644 --- a/DMS/dms_state.h +++ b/DMS/dms_state.h @@ -1,7 +1,7 @@ #pragma once -#include #include "errors.h" -#include +#include "chunk.h" +#include #include namespace dms { class dms_state @@ -10,6 +10,7 @@ namespace dms { void push_error(errors::error err); void push_warning(errors::error err); double version=1.0; + std::map chunks; std::string entry = "start"; std::map enables; }; diff --git a/DMS/dump.txt b/DMS/dump.txt index cacbe11..4b7e7bf 100644 --- a/DMS/dump.txt +++ b/DMS/dump.txt @@ -1,526 +1,128 @@ Token Dump: -Line <1>ENTR flag -Line <1>NOOP name main Line <1>NOOP newline -Line <2>ENAB flag -Line <2>NOOP name warnings Line <2>NOOP newline -Line <3>DISA flag -Line <3>NOOP name omniscient +Line <3>NOOP bracketo +Line <3>NOOP name default +Line <3>NOOP colon +Line <3>NOOP name char +Line <3>NOOP bracketc Line <3>NOOP newline Line <4>NOOP newline +Line <5>NOOP name money +Line <5>NOOP equal +Line <5>NOOP number 0 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>NOOP bracketo +Line <7>NOOP name Ryan +Line <7>NOOP colon +Line <7>NOOP name char +Line <7>NOOP bracketc Line <7>NOOP newline -Line <8>NOOP bracketo -Line <8>NOOP name default -Line <8>NOOP colon -Line <8>NOOP name char -Line <8>NOOP bracketc +Line <8>NOOP name age +Line <8>NOOP equal +Line <8>NOOP number 21 Line <8>NOOP newline -Line <9>NOOP tab +Line <9>NOOP name money +Line <9>NOOP equal +Line <9>NOOP number 1000 Line <9>NOOP newline -Line <10>NOOP tab -Line <10>NOOP name money -Line <10>NOOP equal -Line <10>NOOP number 0 Line <10>NOOP newline -Line <11>NOOP bracketo -Line <11>NOOP name Ryan +Line <11>NOOP name calm Line <11>NOOP colon -Line <11>NOOP name char -Line <11>NOOP bracketc +Line <11>NOOP string ./path/to/file 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 name excited +Line <12>NOOP colon +Line <12>NOOP string ./path/to/file Line <12>NOOP newline -Line <13>NOOP tab -Line <13>NOOP name money -Line <13>NOOP equal -Line <13>NOOP number 1000 Line <13>NOOP newline -Line <14>NOOP tab +Line <14>NOOP bracketo +Line <14>NOOP name step +Line <14>NOOP colon +Line <14>NOOP name function +Line <14>NOOP parao +Line <14>NOOP name a +Line <14>NOOP seperator +Line <14>NOOP name b +Line <14>NOOP seperator +Line <14>NOOP name c +Line <14>NOOP parac +Line <14>NOOP bracketc Line <14>NOOP newline -Line <15>NOOP tab -Line <15>NOOP name calm -Line <15>NOOP colon -Line <15>NOOP string ./path/to/file +Line <15>NOOP string Testing... Line <15>NOOP newline -Line <16>NOOP tab -Line <16>NOOP name excited -Line <16>NOOP colon -Line <16>NOOP string ./path/to/file +Line <16>NOOP name d +Line <16>NOOP equal +Line <16>NOOP parao +Line <16>NOOP name 100 +Line <16>NOOP number +Line <16>NOOP plus +Line <16>NOOP name b +Line <16>NOOP parac +Line <16>NOOP divide +Line <16>NOOP name c Line <16>NOOP newline +Line <17>NOOP name e +Line <17>NOOP equal +Line <17>NOOP string somestring Line <17>NOOP newline -Line <18>NOOP bracketo -Line <18>NOOP name step -Line <18>NOOP colon -Line <18>NOOP name function -Line <18>NOOP parao -Line <18>NOOP name a -Line <18>NOOP seperator -Line <18>NOOP name b -Line <18>NOOP seperator -Line <18>NOOP name c -Line <18>NOOP parac -Line <18>NOOP bracketc +Line <18>NOOP name e +Line <18>NOOP equal +Line <18>NOOP nil nil Line <18>NOOP newline -Line <19>NOOP tab -Line <19>NOOP string Testing... +Line <19>NOOP name g +Line <19>NOOP equal +Line <19>NOOP false false Line <19>NOOP newline -Line <20>NOOP tab +Line <20>RETN ret Line <20>NOOP name d -Line <20>NOOP equal -Line <20>NOOP parao -Line <20>NOOP name 100 -Line <20>NOOP number -Line <20>NOOP plus -Line <20>NOOP name b -Line <20>NOOP parac -Line <20>NOOP divide -Line <20>NOOP name c Line <20>NOOP newline -Line <21>NOOP tab -Line <21>NOOP name e -Line <21>NOOP equal -Line <21>NOOP string somestring Line <21>NOOP newline -Line <22>NOOP tab -Line <22>NOOP name e -Line <22>NOOP equal -Line <22>NOOP nil nil +Line <22>NOOP bracketo +Line <22>NOOP name inventory +Line <22>NOOP colon +Line <22>NOOP name env +Line <22>NOOP bracketc Line <22>NOOP newline -Line <23>NOOP tab -Line <23>NOOP name g +Line <23>NOOP name slot1 +Line <23>NOOP number Line <23>NOOP equal -Line <23>NOOP false false +Line <23>NOOP string Line <23>NOOP newline -Line <24>NOOP tab -Line <24>RETN ret -Line <24>NOOP name d +Line <24>NOOP name slot2 +Line <24>NOOP number +Line <24>NOOP equal +Line <24>NOOP string Line <24>NOOP newline +Line <25>NOOP name slot3 +Line <25>NOOP number +Line <25>NOOP equal +Line <25>NOOP string Line <25>NOOP newline -Line <26>NOOP bracketo -Line <26>NOOP name inventory -Line <26>NOOP colon -Line <26>NOOP name env -Line <26>NOOP bracketc +Line <26>NOOP name slot4 +Line <26>NOOP number +Line <26>NOOP equal +Line <26>NOOP string Line <26>NOOP newline -Line <27>NOOP tab -Line <27>NOOP name slot1 +Line <27>NOOP name slot5 Line <27>NOOP number Line <27>NOOP equal Line <27>NOOP string Line <27>NOOP newline -Line <28>NOOP tab -Line <28>NOOP name slot2 +Line <28>NOOP name slot6 Line <28>NOOP number Line <28>NOOP equal Line <28>NOOP string Line <28>NOOP newline -Line <29>NOOP tab -Line <29>NOOP name slot3 +Line <29>NOOP name slot7 Line <29>NOOP number Line <29>NOOP equal Line <29>NOOP string Line <29>NOOP newline -Line <30>NOOP tab -Line <30>NOOP name slot4 +Line <30>NOOP name slot8 Line <30>NOOP number Line <30>NOOP equal Line <30>NOOP string Line <30>NOOP newline -Line <31>NOOP tab -Line <31>NOOP name slot5 -Line <31>NOOP number -Line <31>NOOP equal -Line <31>NOOP string -Line <31>NOOP newline -Line <32>NOOP tab -Line <32>NOOP name slot6 -Line <32>NOOP number -Line <32>NOOP equal -Line <32>NOOP string -Line <32>NOOP newline -Line <33>NOOP tab -Line <33>NOOP name slot7 -Line <33>NOOP number -Line <33>NOOP equal -Line <33>NOOP string -Line <33>NOOP newline -Line <34>NOOP tab -Line <34>NOOP name slot8 -Line <34>NOOP number -Line <34>NOOP equal -Line <34>NOOP string -Line <34>NOOP newline -Line <35>NOOP tab -Line <35>NOOP newline -Line <36>NOOP bracketo -Line <36>NOOP name main -Line <36>NOOP bracketc -Line <36>NOOP cbracketo -Line <36>NOOP newline -Line <37>NOOP tab -Line <37>NOOP name Ryan -Line <37>NOOP colon -Line <37>NOOP string This works! -Line <37>NOOP newline -Line <38>NOOP tab -Line <38>NOOP name DEBUG -Line <38>NOOP string What's up -Line <38>NOOP newline -Line <39>NOOP tab -Line <39>NOOP name Ryan -Line <39>NOOP colon -Line <39>NOOP cbracketo -Line <39>NOOP newline -Line <40>NOOP tab -Line <40>NOOP tab -Line <40>NOOP name speed -Line <40>NOOP number 100 -Line <40>NOOP mod -Line <40>NOOP newline -Line <41>NOOP tab -Line <41>NOOP tab -Line <41>NOOP name calm -Line <41>NOOP string Hello Bob, -Line <41>NOOP newline -Line <42>NOOP tab -Line <42>NOOP tab -Line <42>NOOP name wait -Line <42>NOOP number 0.455 -Line <42>NOOP newline -Line <43>NOOP tab -Line <43>NOOP tab -Line <43>NOOP name excited -Line <43>NOOP string how are you doing? -Line <43>NOOP newline -Line <44>NOOP tab -Line <44>NOOP tab -Line <44>NOOP newline -Line <45>NOOP tab -Line <45>NOOP cbracketc -Line <45>NOOP newline -Line <46>NOOP tab -Line <46>NOOP newline -Line <47>NOOP tab -Line <47>NOOP name tester -Line <47>NOOP equal -Line <47>NOOP string Hello -Line <47>NOOP newline -Line <48>NOOP tab -Line <48>NOOP name food -Line <48>NOOP equal -Line <48>NOOP number 3 -Line <48>NOOP newline -Line <49>NOOP tab -Line <49>NOOP name a -Line <49>NOOP equal -Line <49>NOOP name list -Line <49>NOOP bracketo -Line <49>NOOP number 1 -Line <49>NOOP bracketc -Line <49>NOOP newline -Line <50>NOOP tab -Line <50>NOOP newline -Line <51>NOOP tab -Line <51>IFFF control -Line <51>NOOP name statment -Line <51>NOOP cbracketo -Line <51>NOOP newline -Line <52>NOOP tab -Line <52>NOOP tab -Line <52>NOOP string test -Line <52>NOOP newline -Line <53>NOOP tab -Line <53>NOOP cbracketc -Line <53>ELIF control -Line <53>NOOP name statement -Line <53>NOOP cbracketo -Line <53>NOOP newline -Line <54>NOOP tab -Line <54>NOOP tab -Line <54>NOOP string test -Line <54>NOOP newline -Line <55>NOOP tab -Line <55>NOOP tab -Line <55>NOOP cbracketc -Line <55>IFFF control -Line <55>NOOP name statement -Line <55>NOOP cbracketo -Line <55>NOOP newline -Line <56>NOOP tab -Line <56>NOOP tab -Line <56>NOOP tab -Line <56>NOOP string test -Line <56>NOOP newline -Line <57>NOOP tab -Line <57>NOOP tab -Line <57>NOOP tab -Line <57>NOOP string test -Line <57>NOOP newline -Line <58>NOOP tab -Line <58>NOOP tab -Line <58>NOOP tab -Line <58>IFFF control -Line <58>NOOP name statement -Line <58>NOOP cbracketo -Line <58>NOOP newline -Line <59>NOOP tab -Line <59>NOOP tab -Line <59>NOOP tab -Line <59>NOOP tab -Line <59>NOOP string test -Line <59>NOOP newline -Line <60>NOOP tab -Line <60>NOOP tab -Line <60>NOOP tab -Line <60>NOOP cbracketc -Line <60>ELSE control -Line <60>NOOP cbracketo -Line <60>NOOP newline -Line <61>NOOP tab -Line <61>NOOP tab -Line <61>NOOP tab -Line <61>NOOP tab -Line <61>NOOP string test -Line <61>NOOP newline -Line <62>NOOP tab -Line <62>NOOP tab -Line <62>NOOP tab -Line <62>NOOP cbracketc -Line <62>NOOP newline -Line <63>NOOP tab -Line <63>NOOP tab -Line <63>NOOP cbracketc -Line <63>ELIF control -Line <63>NOOP name statement -Line <63>NOOP cbracketo -Line <63>NOOP newline -Line <64>NOOP tab -Line <64>NOOP tab -Line <64>NOOP tab -Line <64>NOOP string test -Line <64>NOOP newline -Line <65>NOOP tab -Line <65>NOOP tab -Line <65>NOOP cbracketc -Line <65>ELSE control -Line <65>NOOP cbracketo -Line <65>NOOP newline -Line <66>NOOP tab -Line <66>NOOP tab -Line <66>NOOP tab -Line <66>NOOP string test -Line <66>NOOP newline -Line <67>NOOP tab -Line <67>NOOP tab -Line <67>NOOP cbracketc -Line <67>NOOP newline -Line <68>NOOP tab -Line <68>NOOP newline -Line <69>NOOP tab -Line <69>NOOP gotoo -Line <69>NOOP string somewhere -Line <69>NOOP newline -Line <70>NOOP tab -Line <70>NOOP jump -Line <70>NOOP string overhere -Line <70>NOOP newline -Line <71>NOOP newline -Line <72>NOOP tab -Line <72>NOOP name hungry -Line <72>NOOP equal -Line <72>NOOP parao -Line <72>NOOP minus -Line <72>NOOP number 2 -Line <72>NOOP plus -Line <72>NOOP number 4 -Line <72>NOOP minus -Line <72>NOOP parao -Line <72>NOOP parao -Line <72>NOOP number 5 -Line <72>NOOP multiply -Line <72>NOOP number 5 -Line <72>NOOP parac -Line <72>NOOP divide -Line <72>NOOP name sqrt -Line <72>NOOP parao -Line <72>NOOP number 144 -Line <72>NOOP plus -Line <72>NOOP number 5 -Line <72>NOOP parac -Line <72>NOOP parac -Line <72>NOOP parac -Line <72>NOOP pow -Line <72>NOOP number 2 -Line <72>NOOP multiply -Line <72>NOOP number 2 -Line <72>NOOP plus -Line <72>NOOP number 2 -Line <72>NOOP newline -Line <73>NOOP tab -Line <73>NOOP name list -Line <73>NOOP bracketo -Line <73>NOOP number 1 -Line <73>NOOP bracketc -Line <73>NOOP equal -Line <73>NOOP string Hello -Line <73>NOOP newline -Line <74>NOOP tab -Line <74>NOOP name var1 -Line <74>NOOP number -Line <74>NOOP equal -Line <74>NOOP name func -Line <74>NOOP parao -Line <74>NOOP number 1 -Line <74>NOOP seperator -Line <74>NOOP string string -Line <74>NOOP seperator -Line <74>NOOP number 2 -Line <74>NOOP plus -Line <74>NOOP number 5 -Line <74>NOOP parac -Line <74>NOOP newline -Line <75>NOOP tab -Line <75>NOOP name a -Line <75>NOOP equal -Line <75>NOOP name 100 -Line <75>NOOP number -Line <75>NOOP plus -Line <75>NOOP name func -Line <75>NOOP parao -Line <75>NOOP number 1 -Line <75>NOOP seperator -Line <75>NOOP string string -Line <75>NOOP seperator -Line <75>NOOP number 2 -Line <75>NOOP plus -Line <75>NOOP number 5 -Line <75>NOOP parac -Line <75>NOOP plus -Line <75>NOOP number 100 -Line <75>NOOP newline -Line <76>NOOP tab -Line <76>NOOP name func -Line <76>NOOP parao -Line <76>NOOP number 1 -Line <76>NOOP seperator -Line <76>NOOP string string -Line <76>NOOP seperator -Line <76>NOOP number 2 -Line <76>NOOP plus -Line <76>NOOP number 5 -Line <76>NOOP parac -Line <76>NOOP newline -Line <77>NOOP tab -Line <77>NOOP label label -Line <77>NOOP newline -Line <78>NOOP tab -Line <78>NOOP newline -Line <79>NOOP tab -Line <79>NOOP newline -Line <80>NOOP tab -Line <80>CHOI control -Line <80>NOOP string Pick one: -Line <80>NOOP cbracketo -Line <80>NOOP newline -Line <81>NOOP tab -Line <81>NOOP tab -Line <81>NOOP string first -Line <81>NOOP name func -Line <81>NOOP parao -Line <81>NOOP parac -Line <81>NOOP newline -Line <82>NOOP tab -Line <82>NOOP tab -Line <82>NOOP string second -Line <82>NOOP name func -Line <82>NOOP parao -Line <82>NOOP parac -Line <82>NOOP newline -Line <83>NOOP tab -Line <83>NOOP tab -Line <83>NOOP string third -Line <83>NOOP name func -Line <83>NOOP parao -Line <83>NOOP parac -Line <83>NOOP newline -Line <84>NOOP tab -Line <84>NOOP tab -Line <84>NOOP string forth -Line <84>NOOP name func -Line <84>NOOP parao -Line <84>NOOP parac -Line <84>NOOP newline -Line <85>NOOP tab -Line <85>NOOP tab -Line <85>NOOP string fifth -Line <85>NOOP gotoo -Line <85>NOOP string here -Line <85>NOOP newline -Line <86>NOOP tab -Line <86>NOOP tab -Line <86>NOOP string sixth -Line <86>NOOP gotoo -Line <86>NOOP name name -Line <86>NOOP newline -Line <87>NOOP tab -Line <87>NOOP tab -Line <87>NOOP string sevinth -Line <87>NOOP jump -Line <87>NOOP string there -Line <87>NOOP newline -Line <88>NOOP tab -Line <88>NOOP tab -Line <88>NOOP string eight -Line <88>NOOP jump -Line <88>NOOP name name -Line <88>NOOP newline -Line <89>NOOP tab -Line <89>NOOP cbracketc -Line <89>NOOP newline -Line <90>NOOP cbracketc -Line <90>NOOP newline -Line <91>NOOP newline -Line <92>NOOP newline -Line <93>NOOP bracketo -Line <93>NOOP name Bob -Line <93>NOOP colon -Line <93>NOOP name char -Line <93>NOOP bracketc -Line <93>NOOP newline -Line <94>NOOP tab -Line <94>NOOP name age -Line <94>NOOP equal -Line <94>NOOP number 24 -Line <94>NOOP newline -Line <95>NOOP tab -Line <95>NOOP name money -Line <95>NOOP equal -Line <95>NOOP number 100 -Line <95>NOOP newline -Line <96>NOOP newline -Line <97>NOOP bracketo -Line <97>NOOP name newblock -Line <97>NOOP colon -Line <97>NOOP name function -Line <97>NOOP parao -Line <97>NOOP parac -Line <97>NOOP bracketc -Line <97>NOOP newline -Line <98>NOOP tab -Line <98>NOOP string Test #2 -Line <98>NOOP number -Line <98>NOOP newline -Line <99>NOOP tab -Line <99>NOOP string Does it parse this part properly? -Line <99>NOOP newline -Line <101>NOOP eof +Line <32>NOOP eof diff --git a/DMS/errors.h b/DMS/errors.h index 10b42b5..ee64292 100644 --- a/DMS/errors.h +++ b/DMS/errors.h @@ -8,7 +8,8 @@ namespace dms::errors { invalie_type, array_out_of_bounds, badtoken, - block_already_defined + block_already_defined, + choice_unknown }; struct error { errortype code=unknown; diff --git a/DMS/loadtest.dms b/DMS/loadtest.dms new file mode 100644 index 0000000..f9feb6f --- /dev/null +++ b/DMS/loadtest.dms @@ -0,0 +1,28 @@ +[default:char] + // The default stats for all characters. + money = 0 + +[Ryan:char] + age = 21 + money = 1000 + // Inside a character block this syntax defines animation/image file for an emotion + calm: "./path/to/file" + excited: "./path/to/file" + +[step:function(a,b,c)] + "Testing..." + d = (100 + b) / c + e = "somestring" + e = nil + g = false + return d + +[inventory:env] + slot1 = "" + slot2 = "" + slot3 = "" + slot4 = "" + slot5 = "" + slot6 = "" + slot7 = "" + slot8 = "" \ No newline at end of file diff --git a/DMS/streams.cpp b/DMS/streams.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/DMS/streams.h b/DMS/streams.h deleted file mode 100644 index 6f70f09..0000000 --- a/DMS/streams.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/DMS/test.dms b/DMS/test.dms index e8affa9..c541bc4 100644 --- a/DMS/test.dms +++ b/DMS/test.dms @@ -2,43 +2,15 @@ entry main enable warnings disable omniscient //enable debugging -//loadfile "loadtest.dms" +loadfile "loadtest.dms" version 1.2 using extendedDefine -[default:char] - // The default stats for all characters. - money = 0 -[Ryan:char] - age = 21 - money = 1000 - // Inside a character block this syntax defines animation/image file for an emotion - calm: "./path/to/file" - excited: "./path/to/file" - -[step:function(a,b,c)] - "Testing..." - d = (100 + b) / c - e = "somestring" - e = nil - g = false - return d - -[inventory:env] - slot1 = "" - slot2 = "" - slot3 = "" - slot4 = "" - slot5 = "" - slot6 = "" - slot7 = "" - slot8 = "" [main] { Ryan: "This works!" DEBUG "What's up" // Debug lines are removed when debug mode is disabled Ryan: { - speed 100% - calm "Hello Bob, " + speed 100%;calm "Hello Bob, " wait 0.455 excited "how are you doing?" // Becomes: Hello Bob, how are you doing? @@ -86,6 +58,7 @@ using extendedDefine "sixth" goto name "sevinth" jump "there" "eight" jump name + "nine" exit } } diff --git a/DMS/utils.cpp b/DMS/utils.cpp index efe01b6..60c8140 100644 --- a/DMS/utils.cpp +++ b/DMS/utils.cpp @@ -98,4 +98,11 @@ namespace dms::utils { std::string temp = str.str(); return temp.substr(1, temp.size() - 3); } + void trim(std::string& s) { + size_t p = s.find_first_not_of(" \t"); + s.erase(0, p); + p = s.find_last_not_of(" \t"); + if (std::string::npos != p) + s.erase(p + 1); + } } \ No newline at end of file diff --git a/DMS/utils.h b/DMS/utils.h index 8e04d6f..ade6fb9 100644 --- a/DMS/utils.h +++ b/DMS/utils.h @@ -24,4 +24,5 @@ namespace dms::utils { bool isalphanum(std::string str); bool isalpha(std::string str); bool isNum(std::string str); + void trim(std::string& s); } \ No newline at end of file