diff --git a/DMS syntax npp.xml b/DMS syntax npp.xml index 67e0893..0682c15 100644 --- a/DMS syntax npp.xml +++ b/DMS syntax npp.xml @@ -25,8 +25,8 @@ 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 jump exit - leaking debugging warnings statesave hostmsg + if then return and or true false for while choice end else elseif goto jump exit debug nil + leaking debugging warnings statesave omniscient 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 @@ -36,19 +36,19 @@ - + - - - - + + + + - - + + diff --git a/DMS/Debug/DMS.log b/DMS/Debug/DMS.log index 1c01c78..ae767a8 100644 --- a/DMS/Debug/DMS.log +++ b/DMS/Debug/DMS.log @@ -1,5 +1,2 @@ - LineParserBuilds.cpp - LineParserParse.cpp - chunk.cpp - Generating Code... + LineParserParse.cpp DMS.vcxproj -> F:\VSCWorkspace\DMS\Debug\DMS.exe diff --git a/DMS/Debug/DMS.obj b/DMS/Debug/DMS.obj index a11430e..74719e2 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 4c1ae59..1315fd4 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 7d7da95..dcef754 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 cf39db3..ce40db9 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/cmd.obj b/DMS/Debug/cmd.obj index 07e9027..3302c22 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 b867956..95e9400 100644 Binary files a/DMS/Debug/codes.obj and b/DMS/Debug/codes.obj differ diff --git a/DMS/Debug/dms_exceptions.obj b/DMS/Debug/dms_exceptions.obj index 1b963f0..dabdfc1 100644 Binary files a/DMS/Debug/dms_exceptions.obj and b/DMS/Debug/dms_exceptions.obj differ diff --git a/DMS/Debug/number_utils.obj b/DMS/Debug/number_utils.obj index a26bef9..5ec87c4 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 d3a086a..e86b352 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 002a4ef..cf1a83e 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 76d1dbc..f87c0ba 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 e68168e..a93d702 100644 Binary files a/DMS/Debug/vc142.pdb and b/DMS/Debug/vc142.pdb differ diff --git a/DMS/LineParser.h b/DMS/LineParser.h index c13cd38..808701c 100644 --- a/DMS/LineParser.h +++ b/DMS/LineParser.h @@ -56,6 +56,7 @@ namespace dms { std::vector temp; std::vector tdump; size_t tabs = 0; + tokenstream* _stream; dms_state* state; void doCheck(passer* stream, std::vector* t_vec, size_t line, bool& isNum, bool& hasDec, std::vector* buffer); void _Parse(tokenstream stream); @@ -73,8 +74,14 @@ namespace dms { void buildGoto(std::string g, bool v = false); void buildNoop(); void buildLabel(std::string l); + void buildSpeed(double s); + void buildWait(double w); // Utils + void badSymbol(errors::errortype err, tokenstream* stream); + void badSymbol(tokenstream* stream); + void badSymbol(); + void tokenDump(std::vector* v); bool createBlock(std::string bk_name, blocktype bk_type); diff --git a/DMS/LineParserMatchProcess.cpp b/DMS/LineParserMatchProcess.cpp index 489bfd5..8c26ea3 100644 --- a/DMS/LineParserMatchProcess.cpp +++ b/DMS/LineParserMatchProcess.cpp @@ -15,11 +15,12 @@ namespace dms { print("DISP := ", msg); cmd* c = new cmd; c->opcode = codes::DISP; + c->args.push(buildValue()); 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)) { + else if ((isBlock(bt_block) || isBlock(bt_method)) && 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 @@ -29,12 +30,66 @@ namespace dms { print("DISP := ", name, " says '", msg, "'"); cmd* c = new cmd; c->opcode = codes::DISP; - c->args.push(buildValue(msg)); c->args.push(buildValue(name)); + c->args.push(buildValue(msg)); 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; } + else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::name,tokens::colon,tokens::cbracketo)) { + std::string name = stream->next().name; + cmd* c = new cmd; + c->opcode = codes::SSPK; + c->args.push(buildVariable(name)); + current_chunk->addCmd(c); + // Command to set the speaker + stream->next(); + stream->next(); + print("Doing disp!!!"); + while (stream->peek().type != tokens::cbracketc) { + print(stream->peek()); + if (stream->match(tokens::name)) { + std::string mode = stream->next().name; + if (mode == "speed") { + if (stream->match(tokens::number)) { + buildSpeed(std::stod(stream->next().name)); + } + else { + badSymbol(stream); + } + } + else if (mode == "wait") { + if (stream->match(tokens::number)) { + buildWait(std::stod(stream->next().name)); + } + else { + badSymbol(errors::disp_unknown, stream); + } + } + else { + // Assume we have a dact + if (stream->match(tokens::string)) { + cmd* c = new cmd; + c->opcode = codes::DACT; + c->args.push(buildVariable(mode)); + current_chunk->addCmd(c); + } + else { + badSymbol(stream); + } + } + } + else if (stream->match(tokens::string)) { + + } + else if (stream->match(tokens::newline)) { + stream->next(); + } + else { + badSymbol(stream); + } + } + } // 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)) { @@ -122,7 +177,7 @@ namespace dms { stream->next(); } else if (stream->match(tokens::cbracketo) && start) { - state->push_error(errors::error{ errors::choice_unknown,concat("Unexpected symbol ",stream->next()),true,stream->peek().line_num,current_chunk }); + badSymbol(stream); } else if (stream->match(tokens::string)) { std::string name = stream->next().name; @@ -148,7 +203,7 @@ namespace dms { stream->next(); // Consume } else { - state->push_error(errors::error{ errors::choice_unknown,concat("Unexpected symbol ",stream->next()),true,stream->peek().line_num,current_chunk }); + badSymbol(stream); } } buildLabel(str); @@ -282,7 +337,7 @@ namespace dms { } else { cleanup(tempval); // Cleanup - state->push_error(errors::error{ errors::badtoken,concat("Invalid symbol: ",tempstream.peek()),true, tempstream.peek().line_num,current_chunk }); + badSymbol(stream); } } } diff --git a/DMS/LineParserParse.cpp b/DMS/LineParserParse.cpp index 4c95ca2..9b166c4 100644 --- a/DMS/LineParserParse.cpp +++ b/DMS/LineParserParse.cpp @@ -23,11 +23,11 @@ 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. + rawdata << ";;"; // 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"; + rawdata << line << ";\n"; } myfile.close(); //std::cout << rawdata.str() << std::endl; @@ -53,9 +53,9 @@ namespace dms { } else if (data == '\n') { doCheck(&stream, &t_vec, line-2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::newline,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::newline,codes::NOOP,"",line }); if (isNum) { - t_vec.push_back(token{ tokens::number,codes::NOOP,stream.processBuffer(buffer),line - 2 }); + t_vec.push_back(token{ tokens::number,codes::NOOP,stream.processBuffer(buffer),line }); buffer.clear(); isNum = false; } @@ -70,7 +70,7 @@ namespace dms { stream.next(); } else if (data == ':' && stream.peek() == ':' && labelStart) { - t_vec.push_back(token{ tokens::label,codes::NOOP,stream.processBuffer(buffer),line - 2 }); + t_vec.push_back(token{ tokens::label,codes::NOOP,stream.processBuffer(buffer),line }); buffer.clear(); stream.next(); labelStart = false; @@ -81,7 +81,7 @@ namespace dms { } else if (data == '"' && isStr) { isStr = false; - t_vec.push_back(token{ tokens::string,codes::NOOP,stream.processBuffer(buffer),line - 2 }); + t_vec.push_back(token{ tokens::string,codes::NOOP,stream.processBuffer(buffer),line }); buffer.clear(); } else if (isStr) { @@ -99,190 +99,184 @@ namespace dms { buffer.push_back(data); } else if (data == '.' && isNum && hasDec) { - t_vec.push_back(token{ tokens::number,codes::ERRO,"Malformed number!",line - 2 }); + t_vec.push_back(token{ tokens::number,codes::ERRO,"Malformed number!",line }); } else if (data == '[') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::bracketo,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::bracketc,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::parao,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::parac,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::seperator,codes::NOOP,"",line - 2 }); + 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 - 2 }); + t_vec.push_back(token{ tokens::dot,codes::NOOP,"",line }); } else if (data == '{') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::cbracketo,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::cbracketc,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::plus,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::minus,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::multiply,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::divide,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::caret,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::caret,codes::NOOP,"",line }); } else if (data == '%') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::percent,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::percent,codes::NOOP,"",line }); } else if (data == '=') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::equal,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::colon,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::newline,codes::NOOP,"",line - 2 }); + 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 - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::exclamation,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::exclamation,codes::NOOP,"",line }); } else if (data == '~') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::tilde,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::tilde,codes::NOOP,"",line }); } else if (data == '`') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::backtick,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::backtick,codes::NOOP,"",line }); } else if (data == '@') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::at,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::at,codes::NOOP,"",line }); } else if (data == '#') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::pound,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::pound,codes::NOOP,"",line }); } else if (data == '$') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::dollar,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::dollar,codes::NOOP,"",line }); } else if (data == '&') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::ampersand,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::ampersand,codes::NOOP,"",line }); } else if (data == '\t') { - doCheck(&stream, &t_vec, line - 2, isNum, hasDec, &buffer); - t_vec.push_back(token{ tokens::tab,codes::NOOP,"",line - 2 }); + doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); + t_vec.push_back(token{ tokens::tab,codes::NOOP,"",line }); } if (data == ' ' && !isStr) { // tokens end with a space std::string str = stream.processBuffer(buffer); tolower(str); if (str == "enable") { - t_vec.push_back(token{ tokens::flag,codes::ENAB,"",line - 2 }); + t_vec.push_back(token{ tokens::flag,codes::ENAB,"",line }); } else if (str == "entry") { - t_vec.push_back(token{ tokens::flag,codes::ENTR,"",line - 2 }); + t_vec.push_back(token{ tokens::flag,codes::ENTR,"",line }); } else if (str == "loadfile") { - t_vec.push_back(token{ tokens::flag,codes::LOAD,"",line - 2 }); + t_vec.push_back(token{ tokens::flag,codes::LOAD,"",line }); } else if (str == "version") { - t_vec.push_back(token{ tokens::flag,codes::VERN,"",line - 2 }); + t_vec.push_back(token{ tokens::flag,codes::VERN,"",line }); } else if (str == "using") { - t_vec.push_back(token{ tokens::flag,codes::USIN,"",line - 2 }); + t_vec.push_back(token{ tokens::flag,codes::USIN,"",line }); } else if (str == "disable") { - t_vec.push_back(token{ tokens::flag,codes::DISA,"",line - 2 }); + t_vec.push_back(token{ tokens::flag,codes::DISA,"",line }); } else if (str == "if") { - t_vec.push_back(token{ tokens::control,codes::IFFF,"",line - 2 }); + t_vec.push_back(token{ tokens::control,codes::IFFF,"",line }); } else if (str == "elseif") { - t_vec.push_back(token{ tokens::control,codes::ELIF,"",line - 2 }); + t_vec.push_back(token{ tokens::control,codes::ELIF,"",line }); } else if (str == "while") { - t_vec.push_back(token{ tokens::control,codes::WHLE,"",line - 2 }); + t_vec.push_back(token{ tokens::control,codes::WHLE,"",line }); } else if (str == "true") { - t_vec.push_back(token{ tokens::True,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::True,codes::NOOP,"",line }); } else if (str == "false") { - t_vec.push_back(token{ tokens::False,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::False,codes::NOOP,"",line }); } else if (str == "else") { - t_vec.push_back(token{ tokens::control,codes::ELSE,"",line - 2 }); + t_vec.push_back(token{ tokens::control,codes::ELSE,"",line }); } else if (str == "and") { - t_vec.push_back(token{ tokens::And,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::And,codes::NOOP,"",line }); } else if (str == "or") { - t_vec.push_back(token{ tokens::Or,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::Or,codes::NOOP,"",line }); } else if (str == "for") { - t_vec.push_back(token{ tokens::For,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::For,codes::NOOP,"",line }); } else if (str == "choice") { - t_vec.push_back(token{ tokens::control,codes::CHOI,"",line - 2 }); + t_vec.push_back(token{ tokens::control,codes::CHOI,"",line }); } else if (str == "return") { - t_vec.push_back(token{ tokens::ret,codes::RETN,"",line - 2 }); + t_vec.push_back(token{ tokens::ret,codes::RETN,"",line }); } else if (str == "nil") { - t_vec.push_back(token{ tokens::nil,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::nil,codes::NOOP,"",line }); } else if (str == "goto") { - t_vec.push_back(token{ tokens::gotoo,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::gotoo,codes::NOOP,"",line }); } else if (str == "jump") { - t_vec.push_back(token{ tokens::jump,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::jump,codes::NOOP,"",line }); } else if (str == "exit") { - t_vec.push_back(token{ tokens::exit,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::exit,codes::NOOP,"",line }); } else if (str == "debug") { - t_vec.push_back(token{ tokens::debug,codes::NOOP,"",line - 2 }); + t_vec.push_back(token{ tokens::debug,codes::NOOP,"",line }); } else if (utils::isNum(str) && str.size()!=0) { - t_vec.push_back(token{ tokens::number,codes::NOOP,stream.processBuffer(buffer),line - 2 }); + t_vec.push_back(token{ tokens::number,codes::NOOP,stream.processBuffer(buffer),line }); isNum = false; } else if (utils::isalphanum(str) && str.size() > 0) { - t_vec.push_back(token{ tokens::name,codes::NOOP,stream.processBuffer(buffer),line - 2 }); - } - else { - // Unknown command! - /*tok.build(tokens::noop, codes::UNWN); - tok.name = str; - tok.line_num = line;*/ + t_vec.push_back(token{ tokens::name,codes::NOOP,stream.processBuffer(buffer),line }); } buffer.clear(); } @@ -306,7 +300,7 @@ namespace dms { void LineParser::_Parse(tokenstream stream) { token current = stream.next(); while (stream.peek().type != tokens::eof) { - //print(current); + print(current); if (current.type == tokens::flag) { temp = stream.next(tokens::newline); stream.prev(); // Unconsume the newline piece @@ -343,7 +337,8 @@ namespace dms { } } // Default block - if (stream.match(tokens::newline, tokens::bracketo, tokens::name, tokens::bracketc)) { + if (stream.match(tokens::newline,tokens::bracketo, tokens::name, tokens::bracketc)) { + stream.next(); stream.next(); std::string name = stream.next().name; createBlock(name, bt_block); @@ -432,6 +427,6 @@ namespace dms { // tabs = 0; current = stream.next(); } - state->push_chunk(current_chunk->name, current_chunk); + createBlock("$END$", bt_block); } } \ No newline at end of file diff --git a/DMS/LineParserUtils.cpp b/DMS/LineParserUtils.cpp index 46c5cc2..f137164 100644 --- a/DMS/LineParserUtils.cpp +++ b/DMS/LineParserUtils.cpp @@ -82,6 +82,7 @@ namespace dms { return isBlock(bt_block); // Default block type } bool LineParser::isBlock(blocktype bk_type) { + //print(); if (current_chunk == nullptr) { return false; // If a chunk wasn't defined then code was probably defined outside of a block } @@ -155,6 +156,27 @@ namespace dms { } } } + void LineParser::badSymbol(errors::errortype err,tokenstream* stream) { + state->push_error(errors::error{ err,concat("Unexpected symbol '",stream->next().toString(),"'"),true,stream->peek().line_num,current_chunk }); + } + void LineParser::badSymbol(tokenstream* stream) { + state->push_error(errors::error{ errors::unknown,concat("Unexpected symbol '",stream->next().toString(),"'"),true,stream->peek().line_num,current_chunk }); + } + void LineParser::badSymbol() { + state->push_error(errors::error{ errors::unknown,concat("Unexpected symbol '",_stream->next().toString(),"'"),true,_stream->peek().line_num,current_chunk }); + } + void LineParser::buildSpeed(double s) { + cmd* c = new cmd; + c->opcode = codes::DSPD; + c->args.push(buildValue(s)); + current_chunk->addCmd(c); + } + void LineParser::buildWait(double w) { + cmd* c = new cmd; + c->opcode = codes::WAIT; + c->args.push(buildValue(w)); + current_chunk->addCmd(c); + } bool LineParser::createBlock(std::string bk_name, blocktype bk_type) { if (current_chunk != nullptr) { if (!state->chunks.count(current_chunk->name)) @@ -176,6 +198,7 @@ namespace dms { void LineParser::tokenizer(dms_state* state,std::vector &toks) { tokenstream stream; stream.init(&toks); + _stream = &stream; this->state = state; // Grab the pointer to the state and store it within the parser object _Parse(stream); } diff --git a/DMS/chunk.cpp b/DMS/chunk.cpp index aa066e4..1fd8eaa 100644 --- a/DMS/chunk.cpp +++ b/DMS/chunk.cpp @@ -1,5 +1,17 @@ #include "chunk.h" namespace dms { + std::string getBlockType(const blocktype b) { + if (b == bt_block) + return "block"; + if (b == bt_method) + return "method"; + if (b == bt_env) + return "env"; + if (b == bt_character) + return "character"; + if (b == bt_menu) + return "menu"; + } void chunk::addCmd(cmd* c) { cmds.push_back(c); } diff --git a/DMS/chunk.h b/DMS/chunk.h index 15897b7..6b067be 100644 --- a/DMS/chunk.h +++ b/DMS/chunk.h @@ -1,5 +1,6 @@ #pragma once #include "cmd.h" +#include #include #include namespace dms { @@ -10,6 +11,7 @@ namespace dms { bt_character, bt_menu }; + std::string getBlockType(const blocktype b); struct chunk { blocktype type = bt_block; diff --git a/DMS/codes.cpp b/DMS/codes.cpp index 116be6b..6c0bc3a 100644 --- a/DMS/codes.cpp +++ b/DMS/codes.cpp @@ -1,3 +1,40 @@ #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","FUNC","IFFF","ELIF","ELSE","DEFN","SKIP","COMP","INDX","JMPZ","INST","ERRO" ,"GOTO","JUMP","RETN", "EXIT", "DEBG" }; \ 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", + "FUNC", + "IFFF", + "ELIF", + "ELSE", + "DEFN", + "SKIP", + "COMP", + "INDX", + "JMPZ", + "INST", + "ERRO", + "GOTO", + "JUMP", + "RETN", + "EXIT", + "DEBG", + "DSPD", + "DACT", + "WAIT", + "APND", + "SSPK" +}; \ No newline at end of file diff --git a/DMS/codes.h b/DMS/codes.h index 36b4cd4..fff020f 100644 --- a/DMS/codes.h +++ b/DMS/codes.h @@ -17,7 +17,6 @@ namespace dms::codes { CHOI, OPTN, FORE, - UNWN, WHLE, FUNC, IFFF, @@ -34,7 +33,12 @@ namespace dms::codes { JUMP, RETN, EXIT, - DEBG + DEBG, + DSPD, + DACT, + WAIT, + APND, + SSPK }; extern const std::string list[]; static bool isControl(const op code) { diff --git a/DMS/diaplsy cmd.txt b/DMS/diaplsy cmd.txt new file mode 100644 index 0000000..b766a6a --- /dev/null +++ b/DMS/diaplsy cmd.txt @@ -0,0 +1,24 @@ +Chat Stuff +-------------------------------------------------------------------------- +DISP spk "msg" display message from a speaker +DSPD # set display speed +DACT path +WAIT # delay until next cmd is processed +APND "msg" appends text to last message, keeping all applied stats +SSPK spk sets the speaker + +Ryan: { + speed 100 + calm "Hello Bob, " + wait 0.455 + excited "how are you doing? " + "It's a nice day we are having!" +} + +DISP "" +DSPD Ryan 100 +DACT Ryan [path defined by: Ryan.calm] +APND Ryan "Hello Bob, " +WAIT 0.455 +DACT Ryan [path defined by: Ryan.excited] +APND "how are you doing?" diff --git a/DMS/dms_state.cpp b/DMS/dms_state.cpp index 9f11d52..53ef01a 100644 --- a/DMS/dms_state.cpp +++ b/DMS/dms_state.cpp @@ -2,11 +2,11 @@ namespace dms { dms_state::dms_state() { // We should define the defaults for the enables - //chunks.insert_or_assign("leaking",false); - //chunks.insert_or_assign("debugging",false); - //chunks.insert_or_assign("warnings",false); // - //chunks.insert_or_assign("statesave",true); // Allows you to save state - //chunks.insert_or_assign("omniscient",true); // Allows you to know who's who when you first meet them + enables.insert_or_assign("leaking",false); + enables.insert_or_assign("debugging",false); + enables.insert_or_assign("warnings",false); // + enables.insert_or_assign("statesave",true); // Allows you to save state + enables.insert_or_assign("omniscient",true); // Allows you to know who's who when you first meet them } bool dms_state::isEnabled(std::string flag) { if (enables.count(flag)) { @@ -18,7 +18,7 @@ namespace dms { std::cout << std::endl << "STATE DUMP" << std::endl << "Number of chunks: " << chunks.size(); std::ofstream outputFile("dump.bin"); for (const auto& [key, val] : chunks) { - std::cout << "Key: " << key << " Value: " << *val << '\n'; + std::cout << "Key: " << key << "<" << getBlockType(val->type) << ">" << std::endl << *val << std::endl; } //If the error has a chunk then we get the data from it if (err.current_chunk != nullptr) { @@ -27,10 +27,10 @@ namespace dms { outputFile.close(); } void dms_state::dump() { - std::cout << "Number of chunks: " << chunks.size(); + std::cout << "Number of chunks: " << chunks.size() << std::endl; std::ofstream outputFile("dump.bin"); for (const auto& [key, val] : chunks) { - std::cout << "Key: " << key << " Value: " << *val << '\n'; + std::cout << "Key: " << key << "<" << getBlockType(val->type) << ">" << std::endl << *val << std::endl; } outputFile.close(); } @@ -39,10 +39,8 @@ namespace dms { } void dms_state::push_error(errors::error err) { std::cout << err.err_msg << " On Line <" << err.linenum << ">" << std::endl; - if (err.crash) { - dump(err); + if (err.crash) std::exit(err.code); - } } void dms_state::push_warning(errors::error err) { err.crash = false; // Force code to not crash then push the error diff --git a/DMS/dump.txt b/DMS/dump.txt index 2a8d50a..16b76bd 100644 --- a/DMS/dump.txt +++ b/DMS/dump.txt @@ -1,21 +1,25 @@ Token Dump: -Line <4294967295>NOOP newline -Line <0>NOOP newline +Line <1>NOOP newline +Line <1>NOOP newline Line <1>NOOP bracketo Line <1>NOOP name default Line <1>NOOP colon Line <1>NOOP name char Line <1>NOOP bracketc Line <1>NOOP newline +Line <1>NOOP newline Line <2>NOOP newline Line <3>NOOP name money Line <3>NOOP equal Line <3>NOOP number 0 Line <3>NOOP newline +Line <3>NOOP newline Line <4>NOOP name test Line <4>NOOP equal Line <4>NOOP nil nil Line <4>NOOP newline +Line <4>NOOP newline +Line <5>NOOP newline Line <5>NOOP newline Line <6>NOOP bracketo Line <6>NOOP name Ryan @@ -23,23 +27,29 @@ Line <6>NOOP colon Line <6>NOOP name char Line <6>NOOP bracketc Line <6>NOOP newline +Line <6>NOOP newline Line <7>NOOP name age Line <7>NOOP equal Line <7>NOOP number 21 Line <7>NOOP newline +Line <7>NOOP newline Line <8>NOOP name money Line <8>NOOP equal Line <8>NOOP number 1000 Line <8>NOOP newline +Line <8>NOOP newline Line <9>NOOP newline Line <10>NOOP name calm Line <10>NOOP colon Line <10>NOOP string ./path/to/file Line <10>NOOP newline +Line <10>NOOP newline Line <11>NOOP name excited Line <11>NOOP colon Line <11>NOOP string ./path/to/file Line <11>NOOP newline +Line <11>NOOP newline +Line <12>NOOP newline Line <12>NOOP newline Line <13>NOOP bracketo Line <13>NOOP name step @@ -54,6 +64,7 @@ Line <13>NOOP name c Line <13>NOOP parac Line <13>NOOP bracketc Line <13>NOOP newline +Line <13>NOOP newline Line <14>NOOP string Testing... Line <14>NOOP newline Line <15>NOOP name d @@ -66,21 +77,27 @@ Line <15>NOOP parac Line <15>NOOP divide Line <15>NOOP name c Line <15>NOOP newline +Line <15>NOOP newline Line <16>NOOP name e Line <16>NOOP equal Line <16>NOOP string somestring Line <16>NOOP newline +Line <16>NOOP newline Line <17>NOOP name e Line <17>NOOP equal Line <17>NOOP nil nil Line <17>NOOP newline +Line <17>NOOP newline Line <18>NOOP name g Line <18>NOOP equal Line <18>NOOP false false Line <18>NOOP newline +Line <18>NOOP newline Line <19>RETN ret Line <19>NOOP name d Line <19>NOOP newline +Line <19>NOOP newline +Line <20>NOOP newline Line <20>NOOP newline Line <21>NOOP bracketo Line <21>NOOP name inventory @@ -88,44 +105,53 @@ Line <21>NOOP colon Line <21>NOOP name env Line <21>NOOP bracketc Line <21>NOOP newline +Line <21>NOOP newline Line <22>NOOP name slot1 Line <22>NOOP number Line <22>NOOP equal Line <22>NOOP string Line <22>NOOP newline +Line <22>NOOP newline Line <23>NOOP name slot2 Line <23>NOOP number Line <23>NOOP equal Line <23>NOOP string Line <23>NOOP newline +Line <23>NOOP newline Line <24>NOOP name slot3 Line <24>NOOP number Line <24>NOOP equal Line <24>NOOP string Line <24>NOOP newline +Line <24>NOOP newline Line <25>NOOP name slot4 Line <25>NOOP number Line <25>NOOP equal Line <25>NOOP string Line <25>NOOP newline +Line <25>NOOP newline Line <26>NOOP name slot5 Line <26>NOOP number Line <26>NOOP equal Line <26>NOOP string Line <26>NOOP newline +Line <26>NOOP newline Line <27>NOOP name slot6 Line <27>NOOP number Line <27>NOOP equal Line <27>NOOP string Line <27>NOOP newline +Line <27>NOOP newline Line <28>NOOP name slot7 Line <28>NOOP number Line <28>NOOP equal Line <28>NOOP string Line <28>NOOP newline +Line <28>NOOP newline Line <29>NOOP name slot8 Line <29>NOOP number Line <29>NOOP equal Line <29>NOOP string Line <29>NOOP newline -Line <31>NOOP eof +Line <29>NOOP newline +Line <29>NOOP eof diff --git a/DMS/errors.h b/DMS/errors.h index e27eeda..6f0a05a 100644 --- a/DMS/errors.h +++ b/DMS/errors.h @@ -11,7 +11,8 @@ namespace dms::errors { badtoken, block_already_defined, choice_unknown, - nested_function + nested_function, + disp_unknown }; struct error { errortype code=unknown; diff --git a/DMS/loadtest.dms b/DMS/loadtest.dms index aeed2ee..14296e9 100644 --- a/DMS/loadtest.dms +++ b/DMS/loadtest.dms @@ -11,7 +11,7 @@ excited: "./path/to/file" [step:function(a,b,c)] - "Testing..." + "Testing..." // testing d = (100 + b) / c e = "somestring" e = nil diff --git a/DMS/test.dms b/DMS/test.dms index 4489ab3..d640ab1 100644 --- a/DMS/test.dms +++ b/DMS/test.dms @@ -1,17 +1,20 @@ entry main enable warnings disable omniscient -//enable debugging +enable debugging loadfile "loadtest.dms" version 1.2 using extendedDefine +[testblockpro] + "hehe" -[main] { +[main] Ryan: "This works!" DEBUG "What's up" // Debug lines are removed when debug mode is disabled Ryan: { - speed 100%;calm "Hello Bob, " + true + speed 100;calm "Hello Bob, " wait 0.455 excited "how are you doing?" // Becomes: Hello Bob, how are you doing? @@ -62,7 +65,6 @@ using extendedDefine "nine" exit "ten" exit 0 } -} @@ -73,3 +75,4 @@ using extendedDefine [newblock:function()] "Test #2" "Does it parse this part properly?" + "huh" diff --git a/DMS/token.h b/DMS/token.h index 7ad44cc..26b950b 100644 --- a/DMS/token.h +++ b/DMS/token.h @@ -68,8 +68,13 @@ namespace dms::tokens { raw = o; name = s; } + std::string toString() { + std::stringstream str; + str << name; + return str.str(); + } friend std::ostream& operator << (std::ostream& out, const token& c) { - const std::string temp1[] = { + const std::string tokenlist[] = { "none", "noop", "flag", @@ -116,7 +121,7 @@ namespace dms::tokens { "ampersand", "nil" }; - out << "Line <" << c.line_num << ">" << codes::list[c.raw] << " " << temp1[c.type] << " \t\t " << c.name; + out << "Line <" << c.line_num << ">" << codes::list[c.raw] << " " << tokenlist[c.type] << " \t\t " << c.name; return out; } }; diff --git a/Debug/DMS.exe b/Debug/DMS.exe index c45a2ce..80aad85 100644 Binary files a/Debug/DMS.exe and b/Debug/DMS.exe differ diff --git a/Debug/DMS.ilk b/Debug/DMS.ilk index b5476f2..7d5047c 100644 Binary files a/Debug/DMS.ilk and b/Debug/DMS.ilk differ diff --git a/Debug/DMS.pdb b/Debug/DMS.pdb index 91a3565..5f0d37f 100644 Binary files a/Debug/DMS.pdb and b/Debug/DMS.pdb differ