Need to fix loading file bug

This commit is contained in:
Ryan Ward 2020-08-30 23:14:01 -04:00
parent 6f07a4d604
commit eb2b53569c
29 changed files with 115 additions and 346 deletions

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="LineParserBuilds.cpp" />
<ClCompile Include="LineParserMatchProcess.cpp" /> <ClCompile Include="LineParserMatchProcess.cpp" />
<ClCompile Include="LineParserParse.cpp" /> <ClCompile Include="LineParserParse.cpp" />
<ClCompile Include="string_utils.cpp" /> <ClCompile Include="string_utils.cpp" />

View File

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

View File

@ -1,2 +1,9 @@
 LineParserParse.cpp  DMS.cpp
LineParserBuilds.cpp
LineParserMatchProcess.cpp
LineParserParse.cpp
LineParserUtils.cpp
chunk.cpp
dms_state.cpp
Generating Code...
DMS.vcxproj -> F:\VSCWorkspace\DMS\Debug\DMS.exe DMS.vcxproj -> F:\VSCWorkspace\DMS\Debug\DMS.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -66,9 +66,13 @@ namespace dms {
bool match_process_goto(tokenstream* stream); bool match_process_goto(tokenstream* stream);
bool match_process_jump(tokenstream* stream); bool match_process_jump(tokenstream* stream);
bool match_process_exit(tokenstream* stream); bool match_process_exit(tokenstream* stream);
bool match_process_label(tokenstream* stream);
bool match_process_expression(tokenstream* stream, value* v); bool match_process_expression(tokenstream* stream, value* v);
bool match_process_IFFF(tokenstream* stream); bool match_process_IFFF(tokenstream* stream);
// Build
void buildGoto(std::string g, bool v = false);
void buildNoop();
void buildLabel(std::string l);
// Utils // Utils
bool createBlock(std::string bk_name, blocktype bk_type); bool createBlock(std::string bk_name, blocktype bk_type);

26
DMS/LineParserBuilds.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "LineParser.h"
namespace dms {
void LineParser::buildGoto(std::string g, bool v) {
cmd* c = new cmd;
c->opcode = codes::GOTO;
if (v) {
c->args.push(buildVariable(g));
}
else {
c->args.push(buildValue(g));
}
current_chunk->addCmd(c);
}
void LineParser::buildNoop() {
cmd* c = new cmd;
c->opcode = codes::NOOP;
current_chunk->addCmd(c);
}
void LineParser::buildLabel(std::string l) {
cmd* c = new cmd;
c->opcode = codes::LABL;
c->args.push(buildValue(l));
current_chunk->addCmd(c);
current_chunk->addLabel(l);
}
}

View File

@ -75,7 +75,6 @@ namespace dms {
print(stream->peek()); print(stream->peek());
stream->next(); stream->next();
std::string prompt = stream->next().name; std::string prompt = stream->next().name;
print("Prompt: ", prompt);
bool good = true; bool good = true;
std::string option; std::string option;
cmd* c = new cmd; cmd* c = new cmd;
@ -116,18 +115,8 @@ namespace dms {
The NOOP ensures the pattern stays. The NOOP ensures the pattern stays.
If we are provided with a number greater than 3 then we can push an execption. If we are provided with a number greater than 3 then we can push an execption.
*/ */
std::string str = concat("$",stream->peek().line_num);
while (!stream->match(tokens::cbracketc)) { 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::cbracketo) && !start) { if (stream->match(tokens::cbracketo) && !start) {
start = true; start = true;
stream->next(); stream->next();
@ -137,31 +126,32 @@ namespace dms {
} }
else if (stream->match(tokens::string)) { else if (stream->match(tokens::string)) {
std::string name = stream->next().name; std::string name = stream->next().name;
print("Option: ", name);
c->args.push(buildValue(name)); // We append the choice to the first part of the CHOI cmd 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! // 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,nullptr,false)) { // No returns and also no nesting of functions! if (match_process_function(stream,nullptr,false)) { // No returns and also no nesting of functions!
// We collect // We cannot have a nested function here, but if we dont have that then we add our goto
buildGoto(str);
} }
else if (match_process_goto(stream)) { else if (match_process_goto(stream)) {
current_chunk->addCmd(new cmd{codes::NOOP }); // Add noop to post-goto command buildNoop(); // Add noop to post-goto command
} }
else if (match_process_jump(stream)) { else if (match_process_jump(stream)) {
current_chunk->addCmd(new cmd{ codes::NOOP }); // Add noop to post-jump command buildNoop(); // Add noop to post-jump command
} }
else if (match_process_exit(stream)) { else if (match_process_exit(stream)) {
current_chunk->addCmd(new cmd{ codes::NOOP }); // Add noop to post-exit command buildNoop(); // Add noop to post-exit command
} }
} }
// Last Match // Last Match
else if (stream->match(tokens::newline)) { else if (stream->match(tokens::newline)) {
stream->next(); // Consume stream->next(); // Consume
} }
else if (!stream->match(tokens::cbracketc)) { else {
state->push_error(errors::error{ errors::choice_unknown,concat("Unexpected symbol ",stream->next()),true,stream->peek().line_num,current_chunk }); state->push_error(errors::error{ errors::choice_unknown,concat("Unexpected symbol ",stream->next()),true,stream->peek().line_num,current_chunk });
} }
} }
buildLabel(str);
return true; return true;
} }
return false; return false;
@ -217,7 +207,6 @@ namespace dms {
cmd* c = new cmd; cmd* c = new cmd;
c->opcode = codes::FUNC; c->opcode = codes::FUNC;
std::string n = stream->next().name; std::string n = stream->next().name;
print("FUNC ",n);
c->args.push(buildVariable(n)); // Set the func identifier as the first variable c->args.push(buildVariable(n)); // Set the func identifier as the first variable
// Let's set the target // Let's set the target
if (v != nullptr) { if (v != nullptr) {
@ -271,11 +260,10 @@ namespace dms {
} }
// Final match this could be a function it might also be an expression // Final match this could be a function it might also be an expression
else if (match_process_function(&tempstream, tempval)) { else if (match_process_function(&tempstream, tempval)) {
/*if (!nested) { if (!nested) {
print("No nested!"); print("No nested!");
state->push_error(errors::error{ errors::nested_function,"Nested functions are not allowed in this context!",true, tempstream.peek().line_num }); state->push_error(errors::error{ errors::nested_function,"Nested functions are not allowed in this context!",true, tempstream.peek().line_num });
}*/ }
print("Nested ok!");
c->args.push(tempval); c->args.push(tempval);
} }
else if (tempstream.match(tokens::name)) { else if (tempstream.match(tokens::name)) {
@ -302,16 +290,13 @@ namespace dms {
} }
bool LineParser::match_process_goto(tokenstream* stream) { bool LineParser::match_process_goto(tokenstream* stream) {
if (stream->match(tokens::gotoo,tokens::name) || tokens::gotoo,tokens::string) { if (stream->match(tokens::gotoo,tokens::name) || tokens::gotoo,tokens::string) {
cmd* c = new cmd;
c->opcode = codes::GOTO;
stream->next(); // consume gotoo stream->next(); // consume gotoo
if (stream->match(tokens::name)) { if (stream->match(tokens::name)) {
c->args.push(buildVariable(stream->next().name)); buildGoto(stream->next().name,true);
} }
else { else {
c->args.push(buildValue(stream->next().name)); buildGoto(stream->next().name);
} }
current_chunk->addCmd(c);
return true; return true;
} }
return false; return false;
@ -349,21 +334,6 @@ namespace dms {
} }
return false; return false;
} }
bool LineParser::match_process_label(tokenstream* stream) {
if (stream->match(tokens::colon, tokens::colon, tokens::name, tokens::colon, tokens::colon)) {
cmd* c = new cmd;
c->opcode = codes::LABL;
stream->next();
stream->next();
std::string str = stream->next().name;
c->args.push(buildValue(str));
current_chunk->addCmd(c);
current_chunk->addLabel(str);
stream->next();
stream->next();
}
return false;
}
bool LineParser::match_process_IFFF(tokenstream* stream) { bool LineParser::match_process_IFFF(tokenstream* stream) {
return false; // TODO finish this return false; // TODO finish this
} }

View File

@ -15,7 +15,6 @@ namespace dms {
return Parse(state, fn); return Parse(state, fn);
} }
dms_state* dms::LineParser::Parse(dms_state* state, std::string file) { dms_state* dms::LineParser::Parse(dms_state* state, std::string file) {
std::unordered_map<std::string, chunk> chunks;
std::vector<token> t_vec; std::vector<token> t_vec;
std::string li; std::string li;
std::ifstream myfile(file); std::ifstream myfile(file);
@ -304,7 +303,7 @@ namespace dms {
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::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
@ -421,7 +420,10 @@ namespace dms {
// Displays both with a target and without // Displays both with a target and without
match_process_disp(&stream); // Match and process displays match_process_disp(&stream); // Match and process displays
match_process_label(&stream); // Match and process labels if (stream.match(tokens::newline,tokens::label)) { // Match and process labels
stream.next();
buildLabel(stream.next().name);
}
match_process_debug(&stream); match_process_debug(&stream);
//if (current.type != tokens::tab) // Old code for an old system... //if (current.type != tokens::tab) // Old code for an old system...

View File

@ -15,7 +15,7 @@ namespace dms {
return false; return false;
} }
void dms_state::dump(errors::error err) { void dms_state::dump(errors::error err) {
std::cout << "Number of chunks: " << chunks.size(); std::cout << std::endl << "STATE DUMP" << std::endl << "Number of chunks: " << chunks.size();
std::ofstream outputFile("dump.bin"); std::ofstream outputFile("dump.bin");
for (const auto& [key, val] : chunks) { for (const auto& [key, val] : chunks) {
std::cout << "Key: " << key << " Value: " << *val << '\n'; std::cout << "Key: " << key << " Value: " << *val << '\n';

View File

@ -1,314 +1,70 @@
Token Dump: Token Dump:
Line <4294967295>NOOP newline Line <4294967295>NOOP newline
Line <0>NOOP newline Line <0>NOOP newline
Line <1>ENTR flag Line <1>NOOP bracketo
Line <1>NOOP name main 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>ENAB flag
Line <2>NOOP name warnings
Line <2>NOOP newline Line <2>NOOP newline
Line <3>DISA flag Line <3>NOOP name money
Line <3>NOOP name omniscient Line <3>NOOP equal
Line <3>NOOP number 0
Line <3>NOOP newline Line <3>NOOP newline
Line <4>NOOP newline Line <4>NOOP newline
Line <5>NOOP bracketo
Line <5>NOOP name Ryan
Line <5>NOOP colon
Line <5>NOOP name char
Line <5>NOOP bracketc
Line <5>NOOP newline Line <5>NOOP newline
Line <6>VERN flag Line <6>NOOP name age
Line <6>NOOP number 1.2 Line <6>NOOP equal
Line <6>NOOP number 21
Line <6>NOOP newline Line <6>NOOP newline
Line <7>USIN flag Line <7>NOOP name money
Line <7>NOOP name extendedDefine Line <7>NOOP equal
Line <7>NOOP number 1000
Line <7>NOOP newline Line <7>NOOP newline
Line <8>NOOP newline Line <8>NOOP newline
Line <9>NOOP name calm
Line <9>NOOP colon
Line <9>NOOP string ./path/to/file
Line <9>NOOP newline Line <9>NOOP newline
Line <10>NOOP bracketo Line <10>NOOP name excited
Line <10>NOOP name main Line <10>NOOP colon
Line <10>NOOP bracketc Line <10>NOOP string ./path/to/file
Line <10>NOOP cbracketo
Line <10>NOOP newline Line <10>NOOP newline
Line <11>NOOP name Ryan
Line <11>NOOP colon
Line <11>NOOP string This works!
Line <11>NOOP newline Line <11>NOOP newline
Line <12>NOOP nil Line <12>NOOP bracketo
Line <12>NOOP string What's up Line <12>NOOP name step
Line <12>NOOP colon
Line <12>NOOP name function
Line <12>NOOP parao
Line <12>NOOP name a
Line <12>NOOP seperator
Line <12>NOOP name b
Line <12>NOOP seperator
Line <12>NOOP name c
Line <12>NOOP parac
Line <12>NOOP bracketc
Line <12>NOOP newline Line <12>NOOP newline
Line <13>NOOP name Ryan Line <13>NOOP string Testing...
Line <13>NOOP colon
Line <13>NOOP cbracketo
Line <13>NOOP newline Line <13>NOOP newline
Line <14>NOOP name speed Line <14>NOOP name d
Line <14>NOOP equal
Line <14>NOOP parao
Line <14>NOOP number 100 Line <14>NOOP number 100
Line <14>NOOP mod Line <14>NOOP plus
Line <14>NOOP name b
Line <14>NOOP parac
Line <14>NOOP divide
Line <14>NOOP name c
Line <14>NOOP newline Line <14>NOOP newline
Line <14>NOOP name calm Line <15>NOOP name e
Line <14>NOOP string Hello Bob, Line <15>NOOP equal
Line <14>NOOP newline Line <15>NOOP string somestring
Line <15>NOOP name wait
Line <15>NOOP number 0.455
Line <15>NOOP newline Line <15>NOOP newline
Line <16>NOOP name excited Line <16>NOOP name e
Line <16>NOOP string how are you doing? Line <16>NOOP equal
Line <16>NOOP newline
Line <17>NOOP newline
Line <18>NOOP cbracketc
Line <18>NOOP newline
Line <19>NOOP newline
Line <20>NOOP name tester
Line <20>NOOP equal
Line <20>NOOP string Hello
Line <20>NOOP newline
Line <21>NOOP name food
Line <21>NOOP equal
Line <21>NOOP number 3
Line <21>NOOP newline
Line <22>NOOP name a
Line <22>NOOP equal
Line <22>NOOP name list
Line <22>NOOP bracketo
Line <22>NOOP number 1
Line <22>NOOP bracketc
Line <22>NOOP newline
Line <23>NOOP newline
Line <24>IFFF control
Line <24>NOOP name statment
Line <24>NOOP cbracketo
Line <24>NOOP newline
Line <25>NOOP string test
Line <25>NOOP newline
Line <26>NOOP cbracketc
Line <26>ELIF control
Line <26>NOOP name statement
Line <26>NOOP cbracketo
Line <26>NOOP newline
Line <27>NOOP string test
Line <27>NOOP newline
Line <28>NOOP cbracketc
Line <28>IFFF control
Line <28>NOOP name statement
Line <28>NOOP cbracketo
Line <28>NOOP newline
Line <29>NOOP string test
Line <29>NOOP newline
Line <30>NOOP string test
Line <30>NOOP newline
Line <31>IFFF control
Line <31>NOOP name statement
Line <31>NOOP cbracketo
Line <31>NOOP newline
Line <32>NOOP string test
Line <32>NOOP newline
Line <33>NOOP cbracketc
Line <33>ELSE control
Line <33>NOOP cbracketo
Line <33>NOOP newline
Line <34>NOOP string test
Line <34>NOOP newline
Line <35>NOOP cbracketc
Line <35>NOOP newline
Line <36>NOOP cbracketc
Line <36>ELIF control
Line <36>NOOP name statement
Line <36>NOOP cbracketo
Line <36>NOOP newline
Line <37>NOOP string test
Line <37>NOOP newline
Line <38>NOOP cbracketc
Line <38>ELSE control
Line <38>NOOP cbracketo
Line <38>NOOP newline
Line <39>NOOP string test
Line <39>NOOP newline
Line <40>NOOP cbracketc
Line <40>NOOP newline
Line <41>NOOP newline
Line <42>NOOP gotoo
Line <42>NOOP string somewhere
Line <42>NOOP newline
Line <43>NOOP jump
Line <43>NOOP string overhere
Line <43>NOOP newline
Line <44>NOOP newline
Line <45>NOOP name hungry
Line <45>NOOP equal
Line <45>NOOP parao
Line <45>NOOP minus
Line <45>NOOP number 2
Line <45>NOOP plus
Line <45>NOOP number 4
Line <45>NOOP minus
Line <45>NOOP parao
Line <45>NOOP parao
Line <45>NOOP number 5
Line <45>NOOP multiply
Line <45>NOOP number 5
Line <45>NOOP parac
Line <45>NOOP divide
Line <45>NOOP name sqrt
Line <45>NOOP parao
Line <45>NOOP number 144
Line <45>NOOP plus
Line <45>NOOP number 5
Line <45>NOOP parac
Line <45>NOOP parac
Line <45>NOOP parac
Line <45>NOOP pow
Line <45>NOOP number 2
Line <45>NOOP multiply
Line <45>NOOP number 2
Line <45>NOOP plus
Line <45>NOOP number 2
Line <45>NOOP newline
Line <46>NOOP name list
Line <46>NOOP bracketo
Line <46>NOOP number 1
Line <46>NOOP bracketc
Line <46>NOOP equal
Line <46>NOOP string Hello
Line <46>NOOP newline
Line <47>NOOP name var1
Line <47>NOOP number
Line <47>NOOP equal
Line <47>NOOP name func
Line <47>NOOP parao
Line <47>NOOP number 1
Line <47>NOOP seperator
Line <47>NOOP string string
Line <47>NOOP seperator
Line <47>NOOP number 2
Line <47>NOOP plus
Line <47>NOOP number 5
Line <47>NOOP parac
Line <47>NOOP newline
Line <48>NOOP name a
Line <48>NOOP equal
Line <48>NOOP number 100
Line <48>NOOP plus
Line <48>NOOP name func
Line <48>NOOP parao
Line <48>NOOP number 1
Line <48>NOOP seperator
Line <48>NOOP string string
Line <48>NOOP seperator
Line <48>NOOP number 2
Line <48>NOOP plus
Line <48>NOOP number 5
Line <48>NOOP parac
Line <48>NOOP plus
Line <48>NOOP number 100
Line <48>NOOP newline
Line <49>NOOP name func
Line <49>NOOP parao
Line <49>NOOP number 1
Line <49>NOOP seperator
Line <49>NOOP string string
Line <49>NOOP seperator
Line <49>NOOP number 2
Line <49>NOOP plus
Line <49>NOOP number 5
Line <49>NOOP parac
Line <49>NOOP newline
Line <50>NOOP label label
Line <50>NOOP newline
Line <51>NOOP newline
Line <52>NOOP newline
Line <53>CHOI control
Line <53>NOOP string Pick one:
Line <53>NOOP cbracketo
Line <53>NOOP newline
Line <54>NOOP string first
Line <54>NOOP name func
Line <54>NOOP parao
Line <54>NOOP number 1
Line <54>NOOP seperator
Line <54>NOOP number 2
Line <54>NOOP seperator
Line <54>NOOP number 3
Line <54>NOOP parac
Line <54>NOOP newline
Line <55>NOOP string second
Line <55>NOOP name func
Line <55>NOOP parao
Line <55>NOOP true true
Line <55>NOOP seperator
Line <55>NOOP false false
Line <55>NOOP seperator
Line <55>NOOP name func
Line <55>NOOP parao
Line <55>NOOP string heehee
Line <55>NOOP parac
Line <55>NOOP parac
Line <55>NOOP newline
Line <56>NOOP string third
Line <56>NOOP name func
Line <56>NOOP parao
Line <56>NOOP string hehe
Line <56>NOOP parac
Line <56>NOOP newline
Line <57>NOOP string forth
Line <57>NOOP name func
Line <57>NOOP parao
Line <57>NOOP string 1
Line <57>NOOP seperator
Line <57>NOOP number 2
Line <57>NOOP seperator
Line <57>NOOP false false
Line <57>NOOP parac
Line <57>NOOP newline
Line <58>NOOP string fifth
Line <58>NOOP gotoo
Line <58>NOOP string here
Line <58>NOOP newline
Line <59>NOOP string sixth
Line <59>NOOP gotoo
Line <59>NOOP name name
Line <59>NOOP newline
Line <60>NOOP string sevinth
Line <60>NOOP jump
Line <60>NOOP string there
Line <60>NOOP newline
Line <61>NOOP string eight
Line <61>NOOP jump
Line <61>NOOP name name
Line <61>NOOP newline
Line <62>NOOP string nine
Line <62>NOOP name exit
Line <62>NOOP newline
Line <63>NOOP string ten
Line <63>NOOP exit
Line <63>NOOP number 0
Line <63>NOOP newline
Line <64>NOOP cbracketc
Line <64>NOOP newline
Line <65>NOOP cbracketc
Line <65>NOOP newline
Line <66>NOOP newline
Line <67>NOOP newline
Line <68>NOOP newline
Line <69>NOOP bracketo
Line <69>NOOP name Bob
Line <69>NOOP colon
Line <69>NOOP name char
Line <69>NOOP bracketc
Line <69>NOOP newline
Line <70>NOOP name age
Line <70>NOOP equal
Line <70>NOOP number 24
Line <70>NOOP newline
Line <71>NOOP name money
Line <71>NOOP equal
Line <71>NOOP number 100
Line <71>NOOP newline
Line <72>NOOP newline
Line <73>NOOP bracketo
Line <73>NOOP name newblock
Line <73>NOOP colon
Line <73>NOOP name function
Line <73>NOOP parao
Line <73>NOOP parac
Line <73>NOOP bracketc
Line <73>NOOP newline
Line <74>NOOP string Test #2
Line <74>NOOP newline
Line <75>NOOP string Does it parse this part properly?
Line <75>NOOP newline
Line <77>NOOP eof

View File

@ -2,7 +2,7 @@ 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
@ -47,12 +47,12 @@ using extendedDefine
var1 = func(1,"string", 2+5) var1 = func(1,"string", 2+5)
a = 100 + func(1,"string", 2+5) + 100 a = 100 + func(1,"string", 2+5) + 100
func(1,"string", 2+5) func(1,"string", 2+5)
::label:: ::mylabel::
//Hello im testing stuff //Hello im testing stuff
CHOICE "Pick one:" { CHOICE "Pick one:" {
"first" func(1,2,3) "first" func(1,2,3)
"second" func(true,false,func("heehee")) "second" func(true,false)
"third" func("hehe") "third" func("hehe")
"forth" func("1",2,false) "forth" func("1",2,false)
"fifth" goto "here" "fifth" goto "here"

Binary file not shown.

Binary file not shown.

Binary file not shown.