Starting to add cmds

This commit is contained in:
Ryan Ward 2020-08-27 23:01:59 -04:00
parent e1e77dfce9
commit a0688f64dd
18 changed files with 324 additions and 597 deletions

View File

@ -25,9 +25,9 @@
<Keywords name="Folders in comment, middle"></Keywords> <Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords> <Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">ENABLE DISABLE LOADFILE ENTRY USING VERSION as AS enable disable loadfile entry using version</Keywords> <Keywords name="Keywords1">ENABLE DISABLE LOADFILE ENTRY USING VERSION as AS enable disable loadfile entry using version</Keywords>
<Keywords name="Keywords2">if then return and or true false for while choice end else elseif goto</Keywords> <Keywords name="Keywords2">if then return and or true false for while choice end else elseif goto jump exit</Keywords>
<Keywords name="Keywords3">leaking debugging warnings statesave hostmsg</Keywords> <Keywords name="Keywords3">leaking debugging warnings statesave hostmsg</Keywords>
<Keywords name="Keywords4">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</Keywords> <Keywords name="Keywords4">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</Keywords>
<Keywords name="Keywords5">_VERSION</Keywords> <Keywords name="Keywords5">_VERSION</Keywords>
<Keywords name="Keywords6">filesystem extendedDefine</Keywords> <Keywords name="Keywords6">filesystem extendedDefine</Keywords>
<Keywords name="Keywords7"></Keywords> <Keywords name="Keywords7"></Keywords>
@ -35,30 +35,30 @@
<Keywords name="Delimiters">00:: 01 02:: 03$ 04 05$ 06&quot; 07\ 08&quot; 09 10 11 12&apos; 13 14&apos; 15 16 17 18 19 20 21 22 23</Keywords> <Keywords name="Delimiters">00:: 01 02:: 03$ 04 05$ 06&quot; 07\ 08&quot; 09 10 11 12&apos; 13 14&apos; 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists> </KeywordLists>
<Styles> <Styles>
<WordsStyle name="DEFAULT" fgColor="C3C3C3" bgColor="293135" fontName="math.exp()" fontStyle="0" fontSize="12" nesting="0" /> <WordsStyle name="DEFAULT" fgColor="C3C3C3" bgColor="293135" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x632E;&#x6D6F;&#x656D;&#x746E;s&#x6F77;&#x6472;&#x3873;&#xD900;&#x0005;" fontStyle="0" fontSize="12" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="808080" bgColor="293134" fontName="math.frexp()" fontStyle="0" fontSize="12" nesting="0" /> <WordsStyle name="COMMENTS" fgColor="808080" bgColor="293134" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x662E;&#x6C6F;&#x6564;&#x7372;&#x6E49;&#x6F43;&#x6564;&#x4D31;&#x6469;&#x6C64;e&#x4CD8;&#x1400;&#x10A8;&#x8E00;&#x6966;&#x656C;&#x7973;&#x7473;&#x6D65;&#x6500;&#x7478;&#x6E65;&#x6564;&#x4464;&#x6665;&#x6E69;e" fontStyle="0" fontSize="12" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="808080" bgColor="293134" fontName="math.min()" fontStyle="0" fontSize="12" nesting="0" /> <WordsStyle name="LINE COMMENTS" fgColor="808080" bgColor="293134" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x662E;&#x6C6F;&#x6564;&#x7372;&#x6E49;&#x6F43;&#x6564;&#x4331;&#x6F6C;&#x6573;" fontStyle="0" fontSize="12" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="FF8080" bgColor="293134" fontName="object.height" fontStyle="0" fontSize="12" nesting="0" /> <WordsStyle name="NUMBERS" fgColor="FF8080" bgColor="293134" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x642E;&#x6365;&#x6D69;&#x6C61;&#x6553;&#x6170;&#x6172;&#x6F74;r" fontStyle="0" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="FF8000" bgColor="293134" fontName="math.sin()" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="KEYWORDS1" fgColor="FF8000" bgColor="293134" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x702E;&#x6572;&#x6966;&#x4B78;&#x7965;&#x6F77;&#x6472;&#x3373;" fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="0080C0" bgColor="293134" fontName="object.align" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="KEYWORDS2" fgColor="0080C0" bgColor="293134" fontName="&#xCF78;&#x0307;&#x9E90;&#x0295;&#x080B;" fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="408080" bgColor="293134" fontName="object.maskX" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="KEYWORDS3" fgColor="408080" bgColor="293134" fontName="0o&#x237B;&#x78FE;&#xCD98;&#x0307; " fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="5959AC" bgColor="293134" fontName="object.text" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="KEYWORDS4" fgColor="5959AC" bgColor="293134" fontName="&#x0001;" fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="FF0080" bgColor="293134" fontName="object.xScale" fontStyle="0" fontSize="12" nesting="0" /> <WordsStyle name="KEYWORDS5" fgColor="FF0080" bgColor="293134" fontName="&#xA308;&#x0308;&#x0001;&#x78FE;&#xCFF0;&#x0307;&#xA200;&#x0295;&#x080B;" fontStyle="0" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="149311" bgColor="293134" fontName="0" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="KEYWORDS6" fgColor="149311" bgColor="293134" fontName="&#x95A8;&#x0295;MMENT" fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="0080C0" bgColor="293134" fontName="0" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="KEYWORDS7" fgColor="0080C0" bgColor="293134" fontName="293134" fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="-1" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="&#xE1E8;&#x0308;STRUC" fontStyle="0" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="EAC195" bgColor="293134" fontName="os.execute()" fontStyle="1" nesting="0" /> <WordsStyle name="OPERATORS" fgColor="EAC195" bgColor="293134" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x6E2E;&#x7365;&#x6974;&#x676E;&#x322E;0&#x030F;&#x271F;&#x1478;&#x0234;&#x8000;&#x271E;&#x1479;&#x0318;&#x8800;&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x6E2E;&#x7365;&#x6974;&#x676E;&#x322E;3" fontStyle="1" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="EAC195" bgColor="293134" fontName="require()" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="FOLDER IN CODE1" fgColor="EAC195" bgColor="293134" fontName="&#x0015;" fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="Lua" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="FFCD22" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="-1" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="8080C0" bgColor="293134" fontName="timer.pause()" fontStyle="1" fontSize="12" nesting="0" /> <WordsStyle name="DELIMITERS1" fgColor="8080C0" bgColor="293134" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x6E2E;&#x7365;&#x6974;&#x676E;&#x312E;9(&#x008E;" fontStyle="1" fontSize="12" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="808040" bgColor="293134" fontName="string.upper()" fontStyle="0" fontSize="12" nesting="0" /> <WordsStyle name="DELIMITERS2" fgColor="808040" bgColor="293134" fontName="&#x7375;&#x7265;&#x6544;&#x6966;&#x656E;&#x6E2E;&#x7365;&#x6974;&#x676E;&#x312E;2r&#x009C;" fontStyle="0" fontSize="12" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="FFA346" bgColor="293134" fontName="string.gsub()" fontStyle="0" fontSize="12" nesting="0" /> <WordsStyle name="DELIMITERS3" fgColor="FFA346" bgColor="293134" fontName="InnoSetup" fontStyle="0" fontSize="12" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="408080" bgColor="293134" fontName="165" fontStyle="1" nesting="0" /> <WordsStyle name="DELIMITERS4" fgColor="408080" bgColor="293134" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="FFA346" bgColor="293134" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS5" fgColor="FFA346" bgColor="293134" fontName="&#x2278;&#x029A;ARACT" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="E0E2E4" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="0" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="8" fontStyle="0" nesting="0" />
</Styles> </Styles>
</UserLang> </UserLang>
</NotepadPlus> </NotepadPlus>

View File

@ -22,5 +22,4 @@ int main()
{ {
LineParser parser = LineParser("test.dms"); LineParser parser = LineParser("test.dms");
parser.Parse(); parser.Parse();
print("Goodbye!");
} }

View File

@ -147,6 +147,7 @@
<ClCompile Include="codes.cpp" /> <ClCompile Include="codes.cpp" />
<ClCompile Include="DMS.cpp" /> <ClCompile Include="DMS.cpp" />
<ClCompile Include="dms_state.cpp" /> <ClCompile Include="dms_state.cpp" />
<ClCompile Include="LineParserExtended.cpp" />
<ClCompile Include="string_utils.cpp" /> <ClCompile Include="string_utils.cpp" />
<ClCompile Include="dms_exceptions.cpp" /> <ClCompile Include="dms_exceptions.cpp" />
<ClCompile Include="LineParser.cpp" /> <ClCompile Include="LineParser.cpp" />

View File

@ -54,6 +54,9 @@
<ClCompile Include="chunk.cpp"> <ClCompile Include="chunk.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="LineParserExtended.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="value.h"> <ClInclude Include="value.h">

View File

@ -1,5 +1,5 @@
#include "LineParser.h" #include "LineParser.h"
#include "errors.h"
using namespace dms::tokens; using namespace dms::tokens;
using namespace dms::utils; using namespace dms::utils;
namespace dms { namespace dms {
@ -77,6 +77,9 @@ namespace dms {
return isBlock(bt_block); // Default block type return isBlock(bt_block); // Default block type
} }
bool LineParser::isBlock(blocktype bk_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; return current_chunk->type == bk_type;
} }
void doCheck(passer* stream,std::vector<token>* t_vec, size_t line, bool &isNum, bool &hasDec, std::vector<uint8_t>* buffer) { void doCheck(passer* stream,std::vector<token>* t_vec, size_t line, bool &isNum, bool &hasDec, std::vector<uint8_t>* buffer) {
@ -177,8 +180,8 @@ namespace dms {
} }
bool LineParser::createBlock(std::string bk_name, blocktype bk_type) { bool LineParser::createBlock(std::string bk_name, blocktype bk_type) {
if (current_chunk != nullptr) { if (current_chunk != nullptr) {
if (!chunks.count(current_chunk->name)) if (!state->chunks.count(current_chunk->name))
chunks.insert_or_assign(current_chunk->name, current_chunk); state->chunks.insert_or_assign(current_chunk->name, current_chunk);
else else
{ {
std::stringstream str; std::stringstream str;
@ -192,13 +195,12 @@ namespace dms {
chunk_type = bk_type; chunk_type = bk_type;
current_chunk->type = bk_type; current_chunk->type = bk_type;
print("Created Block: ",bk_name," <",bk_type,">"); print("Created Block: ",bk_name," <",bk_type,">");
return true;
} }
void LineParser::_Parse(tokenstream stream) { void LineParser::_Parse(tokenstream stream) {
token current = stream.next(); token current = stream.next();
while (stream.peek().type != tokens::eof) { while (stream.peek().type != tokens::eof) {
print(current); print(current);
if (current.type == tokens::tab)
tabs++;
if (current.type == tokens::flag) { if (current.type == tokens::flag) {
temp = stream.next(tokens::newline); temp = stream.next(tokens::newline);
stream.prev(); // Unconsume the newline piece 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? // TODO add usings, kinda useless atm since everything will be packed in. Perhaps extensions?
} }
else if (code == codes::LOAD && tok == tokens::string) { 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 { else {
std::stringstream str; std::stringstream str;
@ -239,7 +243,6 @@ namespace dms {
std::string name = stream.next().name; std::string name = stream.next().name;
createBlock(name,bt_block); createBlock(name,bt_block);
line = stream.next().line_num; // Consume line = stream.next().line_num; // Consume
stream.next(); // Consume
} }
// This handles a few block types since they all follow a similar format // 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)) { 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") { else if (temp == "menu") {
createBlock(name, bt_menu); createBlock(name, bt_menu);
} }
stream.next();
} }
// Function block type // Function block type
else if (stream.match(tokens::newline, tokens::bracketo, tokens::name, tokens::colon, tokens::name, tokens::parao)) { 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 // Control Handle all controls here
if (stream.match(tokens::tab, tokens::control)) { if (stream.match(tokens::control)) {
stream.next(); // Standard consumption
token control = stream.next(); token control = stream.next();
if (control.raw == codes::CHOI && stream.peek().type == tokens::string) { if (control.raw == codes::CHOI && stream.peek().type == tokens::string) {
// Let's parse choice blocks. // Let's parse choice blocks.
std::string prompt = stream.next().name; std::string prompt = stream.next().name;
print("Prompt: ", prompt); print("Prompt: ", prompt);
bool good = true; bool good = true;
size_t c = 0; std::string option;
while (good) { cmd* c = new cmd;
// We need to template the matches // Create a unique label name by using the line number
if (stream.match(tokens::tab, tokens::string, tokens::name, tokens::parao)) { std::string choicelabel = concat("$CHOI_END_", stream.peek().line_num);
stream.next(); wait();
std::string prompt = stream.next().name; 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 What's going on here might be tough to understand just by looking at the code
// We just grabbed the prompt, we don't yet know how many choices we have. So we have to figure out how we can The bytecode generated by this code might look something like this:
// 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);
//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)) { // Last Match
stream.next(); // Allow tabs and newlines to pass like normal else if (stream.match(tokens::newline)) {
stream.next(); // Consume
} }
else { else if (!stream.match(tokens::cbracketc)) {
good = false; state->push_error(errors::error{errors::choice_unknown,"Unexpected symbol!"});
print("Choice handled!");
wait();
} }
} }
} }
@ -345,26 +396,8 @@ namespace dms {
} }
} }
// Displays both with a target and without // Displays both with a target and without
if (stream.match(tokens::tab, tokens::string, tokens::newline)) { match_process_disp(&stream);
// 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
}
}
// function stuff // function stuff
/*if (match(stream, tokens::name, tokens::parao)) { /*if (match(stream, tokens::name, tokens::parao)) {
std::string n = stream.next().name; std::string n = stream.next().name;
@ -379,9 +412,10 @@ namespace dms {
tabs = 0; tabs = 0;
current = stream.next(); 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<token> &toks) { void LineParser::tokenizer(dms_state* state,std::vector<token> &toks) {
tokenstream stream;
stream.init(&toks); stream.init(&toks);
this->state = state; // Grab the pointer to the state and store it within the parser object this->state = state; // Grab the pointer to the state and store it within the parser object
_Parse(stream); _Parse(stream);
@ -414,7 +448,10 @@ namespace dms {
if (myfile.is_open()) if (myfile.is_open())
{ {
std::string line; 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)) { while (std::getline(myfile, line)) {
trim(line);
rawdata << line << "\n"; rawdata << line << "\n";
} }
myfile.close(); myfile.close();
@ -550,6 +587,10 @@ namespace dms {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::colon,codes::NOOP,"",line }); 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 == '!') { else if (data == '!') {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::Not,codes::NOOP,"",line }); t_vec.push_back(token{ tokens::Not,codes::NOOP,"",line });

View File

@ -43,19 +43,26 @@ namespace dms {
class LineParser class LineParser
{ {
std::string fn; std::string fn;
std::map<std::string, chunk*> chunks;
chunk* current_chunk = nullptr; chunk* current_chunk = nullptr;
std::string chunk_name; std::string chunk_name;
blocktype chunk_type = bt_block; blocktype chunk_type = bt_block;
std::stack<scope> scopes; std::stack<scope> scopes;
size_t line = 1; size_t line = 1;
tokenstream stream;
std::vector<tokens::token> temp; std::vector<tokens::token> temp;
size_t tabs = 0; size_t tabs = 0;
dms_state* state; dms_state* state;
void _Parse(tokenstream stream); 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: public:
//Refer to streams.cpp for the match_process_CMD code.
dms_state* Parse(); dms_state* Parse();
dms_state* Parse(std::string l); dms_state* Parse(std::string l);
dms_state* Parse(dms_state* state, std::string l); dms_state* Parse(dms_state* state, std::string l);

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
#include "chunk.h" #include "chunk.h"
namespace dms { namespace dms {
void chunk::addCmd(cmd c) { void chunk::addCmd(cmd* c) {
cmds.push_back(c); cmds.push_back(c);
} }
} }

View File

@ -14,10 +14,11 @@ namespace dms {
blocktype type = bt_block; blocktype type = bt_block;
dms_args params; dms_args params;
std::string name = ""; std::string name = "";
std::vector<cmd> cmds = std::vector<cmd>(); std::vector<cmd*> cmds;
size_t pos = 0; size_t pos = 0;
size_t line = 0; size_t line = 0;
void addCmd(cmd c); void addCmd(cmd* c);
chunk(){}
}; };
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <string>
#include "errors.h" #include "errors.h"
#include <map> #include "chunk.h"
#include <string>
#include <iostream> #include <iostream>
namespace dms { namespace dms {
class dms_state class dms_state
@ -10,6 +10,7 @@ namespace dms {
void push_error(errors::error err); void push_error(errors::error err);
void push_warning(errors::error err); void push_warning(errors::error err);
double version=1.0; double version=1.0;
std::map<std::string, chunk*> chunks;
std::string entry = "start"; std::string entry = "start";
std::map<std::string, bool> enables; std::map<std::string, bool> enables;
}; };

View File

@ -1,526 +1,128 @@
Token Dump: Token Dump:
Line <1>ENTR flag
Line <1>NOOP name main
Line <1>NOOP newline Line <1>NOOP newline
Line <2>ENAB flag
Line <2>NOOP name warnings
Line <2>NOOP newline Line <2>NOOP newline
Line <3>DISA flag Line <3>NOOP bracketo
Line <3>NOOP name omniscient Line <3>NOOP name default
Line <3>NOOP colon
Line <3>NOOP name char
Line <3>NOOP bracketc
Line <3>NOOP newline Line <3>NOOP newline
Line <4>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 <5>NOOP newline
Line <6>VERN flag
Line <6>NOOP number 1.2
Line <6>NOOP newline Line <6>NOOP newline
Line <7>USIN flag Line <7>NOOP bracketo
Line <7>NOOP name extendedDefine Line <7>NOOP name Ryan
Line <7>NOOP colon
Line <7>NOOP name char
Line <7>NOOP bracketc
Line <7>NOOP newline Line <7>NOOP newline
Line <8>NOOP bracketo Line <8>NOOP name age
Line <8>NOOP name default Line <8>NOOP equal
Line <8>NOOP colon Line <8>NOOP number 21
Line <8>NOOP name char
Line <8>NOOP bracketc
Line <8>NOOP newline 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 <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 <10>NOOP newline
Line <11>NOOP bracketo Line <11>NOOP name calm
Line <11>NOOP name Ryan
Line <11>NOOP colon Line <11>NOOP colon
Line <11>NOOP name char Line <11>NOOP string ./path/to/file
Line <11>NOOP bracketc
Line <11>NOOP newline Line <11>NOOP newline
Line <12>NOOP tab Line <12>NOOP name excited
Line <12>NOOP name age Line <12>NOOP colon
Line <12>NOOP equal Line <12>NOOP string ./path/to/file
Line <12>NOOP number 21
Line <12>NOOP newline 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 <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 <14>NOOP newline
Line <15>NOOP tab Line <15>NOOP string Testing...
Line <15>NOOP name calm
Line <15>NOOP colon
Line <15>NOOP string ./path/to/file
Line <15>NOOP newline Line <15>NOOP newline
Line <16>NOOP tab Line <16>NOOP name d
Line <16>NOOP name excited Line <16>NOOP equal
Line <16>NOOP colon Line <16>NOOP parao
Line <16>NOOP string ./path/to/file 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 <16>NOOP newline
Line <17>NOOP name e
Line <17>NOOP equal
Line <17>NOOP string somestring
Line <17>NOOP newline Line <17>NOOP newline
Line <18>NOOP bracketo Line <18>NOOP name e
Line <18>NOOP name step Line <18>NOOP equal
Line <18>NOOP colon Line <18>NOOP nil nil
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 newline Line <18>NOOP newline
Line <19>NOOP tab Line <19>NOOP name g
Line <19>NOOP string Testing... Line <19>NOOP equal
Line <19>NOOP false false
Line <19>NOOP newline Line <19>NOOP newline
Line <20>NOOP tab Line <20>RETN ret
Line <20>NOOP name d 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 <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 <21>NOOP newline
Line <22>NOOP tab Line <22>NOOP bracketo
Line <22>NOOP name e Line <22>NOOP name inventory
Line <22>NOOP equal Line <22>NOOP colon
Line <22>NOOP nil nil Line <22>NOOP name env
Line <22>NOOP bracketc
Line <22>NOOP newline Line <22>NOOP newline
Line <23>NOOP tab Line <23>NOOP name slot1
Line <23>NOOP name g Line <23>NOOP number
Line <23>NOOP equal Line <23>NOOP equal
Line <23>NOOP false false Line <23>NOOP string
Line <23>NOOP newline Line <23>NOOP newline
Line <24>NOOP tab Line <24>NOOP name slot2
Line <24>RETN ret Line <24>NOOP number
Line <24>NOOP name d Line <24>NOOP equal
Line <24>NOOP string
Line <24>NOOP newline 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 <25>NOOP newline
Line <26>NOOP bracketo Line <26>NOOP name slot4
Line <26>NOOP name inventory Line <26>NOOP number
Line <26>NOOP colon Line <26>NOOP equal
Line <26>NOOP name env Line <26>NOOP string
Line <26>NOOP bracketc
Line <26>NOOP newline Line <26>NOOP newline
Line <27>NOOP tab Line <27>NOOP name slot5
Line <27>NOOP name slot1
Line <27>NOOP number Line <27>NOOP number
Line <27>NOOP equal Line <27>NOOP equal
Line <27>NOOP string Line <27>NOOP string
Line <27>NOOP newline Line <27>NOOP newline
Line <28>NOOP tab Line <28>NOOP name slot6
Line <28>NOOP name slot2
Line <28>NOOP number Line <28>NOOP number
Line <28>NOOP equal Line <28>NOOP equal
Line <28>NOOP string Line <28>NOOP string
Line <28>NOOP newline Line <28>NOOP newline
Line <29>NOOP tab Line <29>NOOP name slot7
Line <29>NOOP name slot3
Line <29>NOOP number Line <29>NOOP number
Line <29>NOOP equal Line <29>NOOP equal
Line <29>NOOP string Line <29>NOOP string
Line <29>NOOP newline Line <29>NOOP newline
Line <30>NOOP tab Line <30>NOOP name slot8
Line <30>NOOP name slot4
Line <30>NOOP number Line <30>NOOP number
Line <30>NOOP equal Line <30>NOOP equal
Line <30>NOOP string Line <30>NOOP string
Line <30>NOOP newline Line <30>NOOP newline
Line <31>NOOP tab Line <32>NOOP eof
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

View File

@ -8,7 +8,8 @@ namespace dms::errors {
invalie_type, invalie_type,
array_out_of_bounds, array_out_of_bounds,
badtoken, badtoken,
block_already_defined block_already_defined,
choice_unknown
}; };
struct error { struct error {
errortype code=unknown; errortype code=unknown;

28
DMS/loadtest.dms Normal file
View File

@ -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 = ""

View File

View File

@ -1 +0,0 @@
#pragma once

View File

@ -2,43 +2,15 @@ entry main
enable warnings enable warnings
disable omniscient disable omniscient
//enable debugging //enable debugging
//loadfile "loadtest.dms" loadfile "loadtest.dms"
version 1.2 version 1.2
using extendedDefine 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] { [main] {
Ryan: "This works!" Ryan: "This works!"
DEBUG "What's up" // Debug lines are removed when debug mode is disabled DEBUG "What's up" // Debug lines are removed when debug mode is disabled
Ryan: { Ryan: {
speed 100% speed 100%;calm "Hello Bob, "
calm "Hello Bob, "
wait 0.455 wait 0.455
excited "how are you doing?" excited "how are you doing?"
// Becomes: Hello Bob, how are you doing? // Becomes: Hello Bob, how are you doing?
@ -86,6 +58,7 @@ using extendedDefine
"sixth" goto name "sixth" goto name
"sevinth" jump "there" "sevinth" jump "there"
"eight" jump name "eight" jump name
"nine" exit
} }
} }

View File

@ -98,4 +98,11 @@ namespace dms::utils {
std::string temp = str.str(); std::string temp = str.str();
return temp.substr(1, temp.size() - 3); 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);
}
} }

View File

@ -24,4 +24,5 @@ namespace dms::utils {
bool isalphanum(std::string str); bool isalphanum(std::string str);
bool isalpha(std::string str); bool isalpha(std::string str);
bool isNum(std::string str); bool isNum(std::string str);
void trim(std::string& s);
} }