conditions implemented, todo if statements
This commit is contained in:
parent
ea05df4529
commit
378e5ec0ec
40
DMS/DMS.cpp
40
DMS/DMS.cpp
@ -1,37 +1,47 @@
|
|||||||
#include "dms.h"
|
#include "dms.h"
|
||||||
//#include "memory.h"
|
#include "memory.h"
|
||||||
//#include <windows.h>
|
#include <windows.h>
|
||||||
//#include "utils.h"
|
#include "utils.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "value.h"
|
#include "value.h"
|
||||||
#include <chrono>
|
//#include <chrono>
|
||||||
|
//#include <fast_io.h>
|
||||||
using namespace dms;
|
using namespace dms;
|
||||||
using namespace utils;
|
|
||||||
//typedef void(*FNPTR)();
|
//typedef void(*FNPTR)();
|
||||||
using namespace std::chrono;
|
//using namespace std::chrono;
|
||||||
value invokeTest(void* self, dms_state* state, dms_args* args) {
|
//value invokeTest(void* self, dms_state* state, dms_args* args) {
|
||||||
utils::print(args->args[0].getPrintable());
|
// utils::print(args->args[0].getPrintable());
|
||||||
return "I work!";
|
// return "I work!";
|
||||||
}
|
//}
|
||||||
value print(void* self, dms_state* state, dms_args* args) {
|
value print(void* self, dms_state* state, dms_args* args) {
|
||||||
for (size_t i = 0; i < args->size()-1; i++)
|
std::string str = "";
|
||||||
std::cout << args->args[i].getPrintable() << '\t';
|
for (size_t i = 0; i < args->args.size()-1; i++) {
|
||||||
std::cout << std::endl;
|
str += args->args[i].getPrintable() + "\t";
|
||||||
return value();
|
}
|
||||||
|
printf((str + "\n").c_str());
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
//value concat(void* self, dms_state* state, dms_args* args) {
|
||||||
|
// std::stringstream str;
|
||||||
|
// for (size_t i = 0; i < args->size() - 1; i++)
|
||||||
|
// str << args->args[i].getPrintable();
|
||||||
|
// return value(str.str());
|
||||||
|
//}
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
/*milliseconds ms = duration_cast<milliseconds>(
|
/*milliseconds ms = duration_cast<milliseconds>(
|
||||||
system_clock::now().time_since_epoch()
|
system_clock::now().time_since_epoch()
|
||||||
);
|
);
|
||||||
utils::print(ms.count());*/
|
utils::print(ms.count());*/
|
||||||
|
|
||||||
LineParser parser = LineParser("test.dms");
|
LineParser parser = LineParser("test.dms");
|
||||||
dms_state* state = parser.Parse();
|
dms_state* state = parser.Parse();
|
||||||
state->invoker.registerFunction("invokeTest", invokeTest);
|
|
||||||
state->invoker.registerFunction("print", print);
|
state->invoker.registerFunction("print", print);
|
||||||
state->dump();
|
state->dump();
|
||||||
state->run();
|
state->run();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*HINSTANCE hInst = LoadLibrary(L"C:\\Users\\rayam\\Desktop\\test.dll");
|
/*HINSTANCE hInst = LoadLibrary(L"C:\\Users\\rayam\\Desktop\\test.dll");
|
||||||
if (!hInst) {
|
if (!hInst) {
|
||||||
std::cout << "\nCould not load the library!";
|
std::cout << "\nCould not load the library!";
|
||||||
|
|||||||
@ -119,12 +119,19 @@
|
|||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
<Optimization>Disabled</Optimization>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
|
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<MultiProcessorCompilation>false</MultiProcessorCompilation>
|
||||||
|
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||||
|
<SupportJustMyCode>false</SupportJustMyCode>
|
||||||
|
<Optimization>Full</Optimization>
|
||||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>C:\includes\include;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
DMS.cpp
|
|
||||||
dms_state.cpp
|
|
||||||
dms_state_interpret.cpp
|
|
||||||
LineParserBuilds.cpp
|
|
||||||
LineParserMatchProcess.cpp
|
|
||||||
LineParserParse.cpp
|
|
||||||
string_utils.cpp
|
|
||||||
F:\VSCWorkspace\DMS\DMS\string_utils.cpp(9,45): warning C4244: 'initializing': conversion from 'double' to 'unsigned int', possible loss of data
|
|
||||||
F:\VSCWorkspace\DMS\DMS\string_utils.cpp(36,17): warning C4244: 'initializing': conversion from 'double' to 'size_t', possible loss of data
|
|
||||||
F:\VSCWorkspace\DMS\DMS\string_utils.cpp(37,16): warning C4244: 'initializing': conversion from 'double' to 'size_t', possible loss of data
|
|
||||||
F:\VSCWorkspace\DMS\DMS\string_utils.cpp(93,22): warning C4018: '<': signed/unsigned mismatch
|
|
||||||
F:\VSCWorkspace\DMS\DMS\string_utils.cpp(134,22): warning C4018: '<': signed/unsigned mismatch
|
|
||||||
F:\VSCWorkspace\DMS\DMS\string_utils.cpp(135,25): warning C4018: '<': signed/unsigned mismatch
|
|
||||||
LineParserUtils.cpp
|
|
||||||
number_utils.cpp
|
|
||||||
F:\VSCWorkspace\DMS\DMS\number_utils.cpp(21,21): warning C4018: '<': signed/unsigned mismatch
|
|
||||||
utils.cpp
|
|
||||||
value.cpp
|
|
||||||
Generating Code...
|
|
||||||
F:\VSCWorkspace\DMS\DMS\LineParserMatchProcess.cpp(773): warning C4715: 'dms::LineParser::match_process_expression': not all control paths return a value
|
|
||||||
DMS.vcxproj -> F:\VSCWorkspace\DMS\Debug\DMS.exe
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.27.29110:TargetPlatformVersion=10.0.18362.0:
|
|
||||||
Debug|Win32|F:\VSCWorkspace\DMS\|
|
|
||||||
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.
@ -30,6 +30,7 @@ namespace dms {
|
|||||||
tokens::token peek();
|
tokens::token peek();
|
||||||
tokens::token last();
|
tokens::token last();
|
||||||
std::vector<tokens::token> next(tokens::tokentype tk);
|
std::vector<tokens::token> next(tokens::tokentype tk);
|
||||||
|
bool match(codes::op t1 = codes::NOOP);
|
||||||
bool match(tokens::tokentype t1 = tokens::none, tokens::tokentype t2 = tokens::none, tokens::tokentype t3 = tokens::none, tokens::tokentype t4 = tokens::none, tokens::tokentype t5 = tokens::none, tokens::tokentype t6 = tokens::none, tokens::tokentype t7 = tokens::none, tokens::tokentype t8 = tokens::none, tokens::tokentype t9 = tokens::none, tokens::tokentype t10 = tokens::none, tokens::tokentype t11 = tokens::none, tokens::tokentype t12 = tokens::none);
|
bool match(tokens::tokentype t1 = tokens::none, tokens::tokentype t2 = tokens::none, tokens::tokentype t3 = tokens::none, tokens::tokentype t4 = tokens::none, tokens::tokentype t5 = tokens::none, tokens::tokentype t6 = tokens::none, tokens::tokentype t7 = tokens::none, tokens::tokentype t8 = tokens::none, tokens::tokentype t9 = tokens::none, tokens::tokentype t10 = tokens::none, tokens::tokentype t11 = tokens::none, tokens::tokentype t12 = tokens::none);
|
||||||
bool match(tokens::tokentype* t1 = nullptr, tokens::tokentype* t2 = nullptr, tokens::tokentype* t3 = nullptr, tokens::tokentype* t4 = nullptr, tokens::tokentype* t5 = nullptr, tokens::tokentype* t6 = nullptr, tokens::tokentype* t7 = nullptr, tokens::tokentype* t8 = nullptr, tokens::tokentype* t9 = nullptr, tokens::tokentype* t10 = nullptr, tokens::tokentype* t11 = nullptr, tokens::tokentype* t12 = nullptr);
|
bool match(tokens::tokentype* t1 = nullptr, tokens::tokentype* t2 = nullptr, tokens::tokentype* t3 = nullptr, tokens::tokentype* t4 = nullptr, tokens::tokentype* t5 = nullptr, tokens::tokentype* t6 = nullptr, tokens::tokentype* t7 = nullptr, tokens::tokentype* t8 = nullptr, tokens::tokentype* t9 = nullptr, tokens::tokentype* t10 = nullptr, tokens::tokentype* t11 = nullptr, tokens::tokentype* t12 = nullptr);
|
||||||
bool hasScope(size_t tabs);
|
bool hasScope(size_t tabs);
|
||||||
@ -78,6 +79,7 @@ namespace dms {
|
|||||||
bool match_process_index(tokenstream* stream,value& v, bool leftside = false);
|
bool match_process_index(tokenstream* stream,value& v, bool leftside = false);
|
||||||
bool match_process_return(tokenstream* stream);
|
bool match_process_return(tokenstream* stream);
|
||||||
bool match_process_condition(tokenstream* stream, value& v);
|
bool match_process_condition(tokenstream* stream, value& v);
|
||||||
|
bool match_process_andor(tokenstream* stream,value& v);
|
||||||
bool match_process_if(tokenstream* stream);
|
bool match_process_if(tokenstream* stream);
|
||||||
|
|
||||||
// Build
|
// Build
|
||||||
|
|||||||
@ -4,6 +4,27 @@ using namespace dms::utils;
|
|||||||
// TODO: process if elseif else statements, for loops and while loops
|
// TODO: process if elseif else statements, for loops and while loops
|
||||||
namespace dms {
|
namespace dms {
|
||||||
bool LineParser::match_process_standard(tokenstream* stream, value& v) {
|
bool LineParser::match_process_standard(tokenstream* stream, value& v) {
|
||||||
|
if (stream->match(tokens::parao)) {
|
||||||
|
std::vector<tokens::token> toks = stream->next(tokens::parao, tokens::parac);
|
||||||
|
//toks.pop_back(); // Remove the ')'
|
||||||
|
toks.push_back(tokens::token{tokens::newline,codes::NOOP,"",stream->peek().line_num});
|
||||||
|
tokenstream tempstream;
|
||||||
|
tempstream.init(&toks);
|
||||||
|
value var(datatypes::variable);
|
||||||
|
if (match_process_standard(&tempstream, var)) {
|
||||||
|
v.set(var.s);
|
||||||
|
v.type = datatypes::variable;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
badSymbol(stream);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (match_process_andor(stream, v)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (match_process_expression(stream, v)) {
|
if (match_process_expression(stream, v)) {
|
||||||
match_process_condition(stream,v);
|
match_process_condition(stream,v);
|
||||||
return true;
|
return true;
|
||||||
@ -38,12 +59,12 @@ namespace dms {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (stream->match(tokens::string)) {
|
else if (stream->match(tokens::string)) {
|
||||||
v.set(buildString(stream->next().name));
|
v.set(stream->next().name);
|
||||||
match_process_condition(stream, v);
|
match_process_condition(stream, v);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (stream->match(tokens::name)) {
|
else if (stream->match(tokens::name)) {
|
||||||
v.set(buildString(stream->next().name));
|
v.set(stream->next().name);
|
||||||
v.type = datatypes::variable;
|
v.type = datatypes::variable;
|
||||||
match_process_condition(stream, v);
|
match_process_condition(stream, v);
|
||||||
return true;
|
return true;
|
||||||
@ -57,22 +78,50 @@ namespace dms {
|
|||||||
else if (stream->match(tokens::bracketo, tokens::name, tokens::bracketc)) {
|
else if (stream->match(tokens::bracketo, tokens::name, tokens::bracketc)) {
|
||||||
// We are assigning a block as a variable
|
// We are assigning a block as a variable
|
||||||
stream->next();
|
stream->next();
|
||||||
v.set(buildString(stream->next().name));
|
v.set(stream->next().name);
|
||||||
v.type = datatypes::block;
|
v.type = datatypes::block;
|
||||||
stream->next();
|
stream->next();
|
||||||
match_process_condition(stream, v);
|
match_process_condition(stream, v);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (stream->match(tokens::newline)) {
|
else if (stream->match(tokens::newline)) {
|
||||||
return false;
|
return match_process_standard(stream,v);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool LineParser::match_process_andor(tokenstream* stream, value& v) {
|
||||||
|
codes::op code = codes::MUL;
|
||||||
|
if (stream->match(tokens::Or)) {
|
||||||
|
code = codes::ADD;
|
||||||
|
}
|
||||||
|
else if (!stream->match(tokens::And)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stream->next();
|
||||||
|
value right = value(datatypes::variable);
|
||||||
|
value left = v;
|
||||||
|
value var = value(datatypes::variable);
|
||||||
|
// We have some work to do here
|
||||||
|
if (match_process_standard(stream, right)) {
|
||||||
|
v.set(var.s);
|
||||||
|
v.type = datatypes::variable;
|
||||||
|
cmd* c = new cmd;
|
||||||
|
c->opcode = code;
|
||||||
|
c->args.push(v);
|
||||||
|
c->args.push(left);
|
||||||
|
c->args.push(right);
|
||||||
|
current_chunk->addCmd(c);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
badSymbol(stream);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
bool LineParser::match_process_condition(tokenstream* stream, value& v) {
|
bool LineParser::match_process_condition(tokenstream* stream, value& v) {
|
||||||
// This has taken way too long, but there exists only a few places where this needs to be interjected
|
// This has taken way too long, but there exists only a few places where this needs to be interjected
|
||||||
// The reference to v needs some work if we have a comparison!
|
// The reference to v needs some work if we have a comparison!
|
||||||
// First we need to get a copy of v store it somewhere do the comparision and convert v into a variable that points to the output of the comparison
|
// First we need to get a copy of v store it somewhere do the comparision and convert v into a variable that points to the output of the comparison
|
||||||
|
|
||||||
comp cmp;
|
comp cmp;
|
||||||
// We only need to see if one of these conditions are true
|
// We only need to see if one of these conditions are true
|
||||||
//==
|
//==
|
||||||
@ -118,7 +167,7 @@ namespace dms {
|
|||||||
value var = value(datatypes::variable);
|
value var = value(datatypes::variable);
|
||||||
// COMP cmp out v1 v2
|
// COMP cmp out v1 v2
|
||||||
if (match_process_standard(stream,right)) {
|
if (match_process_standard(stream,right)) {
|
||||||
v.set(buildString(var.s->getValue()));
|
v.set(var.s);
|
||||||
v.type = datatypes::variable;
|
v.type = datatypes::variable;
|
||||||
cmd* c = new cmd;
|
cmd* c = new cmd;
|
||||||
c->opcode = codes::COMP;
|
c->opcode = codes::COMP;
|
||||||
@ -127,6 +176,9 @@ namespace dms {
|
|||||||
c->args.push(left);
|
c->args.push(left);
|
||||||
c->args.push(right);
|
c->args.push(right);
|
||||||
current_chunk->addCmd(c);
|
current_chunk->addCmd(c);
|
||||||
|
if (match_process_andor(stream, v)) {
|
||||||
|
match_process_standard(stream, v);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -135,9 +187,6 @@ namespace dms {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Covers if, elseif, else
|
//Covers if, elseif, else
|
||||||
bool LineParser::match_process_if(tokenstream* stream) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool LineParser::match_process_list(tokenstream* stream, value& v) {
|
bool LineParser::match_process_list(tokenstream* stream, value& v) {
|
||||||
if (stream->match(tokens::cbracketo)) {
|
if (stream->match(tokens::cbracketo)) {
|
||||||
token start = stream->peek();
|
token start = stream->peek();
|
||||||
@ -628,13 +677,11 @@ namespace dms {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
value tempval;
|
value tempval;
|
||||||
token tok;
|
|
||||||
value ref = value(datatypes::variable);
|
value ref = value(datatypes::variable);
|
||||||
// This part we add values to the opcodes for the bytecode FUNC val a1 a2 a3 ... an
|
// This part we add values to the opcodes for the bytecode FUNC val a1 a2 a3 ... an
|
||||||
while (tempstream.peek().type != tokens::none) { // End of stream
|
while (tempstream.peek().type != tokens::none) { // End of stream
|
||||||
debugInvoker(stream);
|
debugInvoker(stream);
|
||||||
tempval = value(datatypes::variable);
|
tempval = value(datatypes::variable);
|
||||||
tok = tempstream.peek();
|
|
||||||
if (tempstream.match(tokens::seperator)) {
|
if (tempstream.match(tokens::seperator)) {
|
||||||
// We have a seperator for function arguments
|
// We have a seperator for function arguments
|
||||||
tempstream.next(); // Consume it
|
tempstream.next(); // Consume it
|
||||||
@ -651,6 +698,7 @@ namespace dms {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
utils::debug(tempstream.peek());
|
||||||
badSymbol(&tempstream);
|
badSymbol(&tempstream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -807,6 +855,21 @@ namespace dms {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool LineParser::match_process_IFFF(tokenstream* stream) {
|
bool LineParser::match_process_IFFF(tokenstream* stream) {
|
||||||
|
/*if(this) {
|
||||||
|
* then()
|
||||||
|
* }
|
||||||
|
* else if(that){
|
||||||
|
* doThis()
|
||||||
|
* } else {
|
||||||
|
* this()
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
// We match a condition, or anything that is non nil/false
|
||||||
|
// God controls are from a time past... I could refactor, but I'm lazy and would have to change a lot of old code... So we will deal with controls
|
||||||
|
if (stream->match(tokens::name) && stream->peek().name == "if") {
|
||||||
|
utils::debug("Let's process an if");
|
||||||
|
}
|
||||||
return false; // TODO finish this
|
return false; // TODO finish this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,7 +911,8 @@ namespace dms {
|
|||||||
debugInvoker(stream);
|
debugInvoker(stream);
|
||||||
if (stream->match(tokens::parao)) {
|
if (stream->match(tokens::parao)) {
|
||||||
tokenstream temp;
|
tokenstream temp;
|
||||||
temp.init(&(stream->next(tokens::parao, tokens::parac))); // Balanced match!
|
auto ts = stream->next(tokens::parao, tokens::parac);
|
||||||
|
temp.init(&ts); // Balanced match!
|
||||||
value tmpvalue = value(datatypes::variable);
|
value tmpvalue = value(datatypes::variable);
|
||||||
if (match_process_expression(&temp, tmpvalue)) {
|
if (match_process_expression(&temp, tmpvalue)) {
|
||||||
if (left.isNil())
|
if (left.isNil())
|
||||||
|
|||||||
@ -235,7 +235,7 @@ namespace dms {
|
|||||||
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
|
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
|
||||||
t_vec.push_back(token{ tokens::anglebracketC,codes::NOOP,">",line });
|
t_vec.push_back(token{ tokens::anglebracketC,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::anglebracketO,codes::NOOP,"<",line });
|
t_vec.push_back(token{ tokens::anglebracketO,codes::NOOP,"<",line });
|
||||||
}
|
}
|
||||||
@ -244,8 +244,9 @@ namespace dms {
|
|||||||
t_vec.push_back(token{ tokens::tab,codes::NOOP,"\t",line });
|
t_vec.push_back(token{ tokens::tab,codes::NOOP,"\t",line });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data == ' ' && !isStr) { // tokens end with a space
|
if ((data == ' ' || data == '(') && !isStr) { // tokens end with a space
|
||||||
std::string str = stream.processBuffer(buffer);
|
std::string str = stream.processBuffer(buffer);
|
||||||
|
utils::debug("> ",str);
|
||||||
tolower(str);
|
tolower(str);
|
||||||
if (str == "enable") {
|
if (str == "enable") {
|
||||||
t_vec.push_back(token{ tokens::flag,codes::ENAB,"",line });
|
t_vec.push_back(token{ tokens::flag,codes::ENAB,"",line });
|
||||||
@ -265,33 +266,18 @@ namespace dms {
|
|||||||
else if (str == "disable") {
|
else if (str == "disable") {
|
||||||
t_vec.push_back(token{ tokens::flag,codes::DISA,"",line });
|
t_vec.push_back(token{ tokens::flag,codes::DISA,"",line });
|
||||||
}
|
}
|
||||||
else if (str == "if") {
|
|
||||||
t_vec.push_back(token{ tokens::control,codes::IFFF,"",line });
|
|
||||||
}
|
|
||||||
else if (str == "elseif") {
|
|
||||||
t_vec.push_back(token{ tokens::control,codes::ELIF,"",line });
|
|
||||||
}
|
|
||||||
else if (str == "while") {
|
|
||||||
t_vec.push_back(token{ tokens::control,codes::WHLE,"",line });
|
|
||||||
}
|
|
||||||
else if (str == "true") {
|
else if (str == "true") {
|
||||||
t_vec.push_back(token{ tokens::True,codes::NOOP,"",line });
|
t_vec.push_back(token{ tokens::True,codes::NOOP,"",line });
|
||||||
}
|
}
|
||||||
else if (str == "false") {
|
else if (str == "false") {
|
||||||
t_vec.push_back(token{ tokens::False,codes::NOOP,"",line });
|
t_vec.push_back(token{ tokens::False,codes::NOOP,"",line });
|
||||||
}
|
}
|
||||||
else if (str == "else") {
|
|
||||||
t_vec.push_back(token{ tokens::control,codes::ELSE,"",line });
|
|
||||||
}
|
|
||||||
else if (str == "and") {
|
else if (str == "and") {
|
||||||
t_vec.push_back(token{ tokens::And,codes::NOOP,"",line });
|
t_vec.push_back(token{ tokens::And,codes::NOOP,"",line });
|
||||||
}
|
}
|
||||||
else if (str == "or") {
|
else if (str == "or") {
|
||||||
t_vec.push_back(token{ tokens::Or,codes::NOOP,"",line });
|
t_vec.push_back(token{ tokens::Or,codes::NOOP,"",line });
|
||||||
}
|
}
|
||||||
else if (str == "for") {
|
|
||||||
t_vec.push_back(token{ tokens::For,codes::NOOP,"",line });
|
|
||||||
}
|
|
||||||
else if (str == "choice") {
|
else if (str == "choice") {
|
||||||
t_vec.push_back(token{ tokens::control,codes::CHOI,"",line });
|
t_vec.push_back(token{ tokens::control,codes::CHOI,"",line });
|
||||||
}
|
}
|
||||||
@ -473,7 +459,7 @@ namespace dms {
|
|||||||
// We got a name which is refering to a variable so lets build one
|
// We got a name which is refering to a variable so lets build one
|
||||||
value v;
|
value v;
|
||||||
v.type = datatypes::variable; // Special type, it writes data to the string portion, but is interperted as a lookup
|
v.type = datatypes::variable; // Special type, it writes data to the string portion, but is interperted as a lookup
|
||||||
v.s = buildString(tokens[i].name);
|
v.s = tokens[i].name;
|
||||||
args.push(v);
|
args.push(v);
|
||||||
}
|
}
|
||||||
else if (tokens[i].type == tokens::seperator) {
|
else if (tokens[i].type == tokens::seperator) {
|
||||||
@ -499,15 +485,7 @@ namespace dms {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Control Handle all controls here
|
// Control Handle all controls here
|
||||||
if (stream->match(tokens::control)) {
|
match_process_IFFF(stream);
|
||||||
//token control = stream->next();
|
|
||||||
if (match_process_choice(stream)) {
|
|
||||||
// Handle choice stuff
|
|
||||||
}
|
|
||||||
else if (match_process_IFFF(stream)) {
|
|
||||||
// This will probably be the toughest one of them all
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Let's handle function stuff!
|
// Let's handle function stuff!
|
||||||
//utils::print("[return]");
|
//utils::print("[return]");
|
||||||
match_process_return(stream);
|
match_process_return(stream);
|
||||||
|
|||||||
@ -210,7 +210,7 @@ namespace dms {
|
|||||||
if (current_chunk->cmds.size() >= 2 && current_chunk->cmds[current_chunk->cmds.size() - 1]!=nullptr && current_chunk->cmds[current_chunk->cmds.size() - 1]->opcode==codes::LINE && (size_t)current_chunk->cmds[current_chunk->cmds.size()-1]->args.args[0].n== (size_t)stream->peek().line_num) {
|
if (current_chunk->cmds.size() >= 2 && current_chunk->cmds[current_chunk->cmds.size() - 1]!=nullptr && current_chunk->cmds[current_chunk->cmds.size() - 1]->opcode==codes::LINE && (size_t)current_chunk->cmds[current_chunk->cmds.size()-1]->args.args[0].n== (size_t)stream->peek().line_num) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int current_line = stream->peek().line_num;
|
int current_line = (int)stream->peek().line_num;
|
||||||
cmd* ln = new cmd;
|
cmd* ln = new cmd;
|
||||||
ln->opcode = codes::LINE;
|
ln->opcode = codes::LINE;
|
||||||
ln->args.push(value(current_line));
|
ln->args.push(value(current_line));
|
||||||
|
|||||||
@ -11,6 +11,7 @@ namespace dms {
|
|||||||
return "character";
|
return "character";
|
||||||
if (b == bt_menu)
|
if (b == bt_menu)
|
||||||
return "menu";
|
return "menu";
|
||||||
|
return "unknown";
|
||||||
}
|
}
|
||||||
void chunk::addCmd(cmd* c) {
|
void chunk::addCmd(cmd* c) {
|
||||||
cmds.push_back(c);
|
cmds.push_back(c);
|
||||||
|
|||||||
@ -180,7 +180,7 @@ namespace dms {
|
|||||||
// Flags handled
|
// Flags handled
|
||||||
case EXIT:
|
case EXIT:
|
||||||
if (c->args.args.size()) {
|
if (c->args.args.size()) {
|
||||||
exitcode = c->args.args[0].n;
|
exitcode = (int)c->args.args[0].n;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
@ -301,7 +301,7 @@ namespace dms {
|
|||||||
value assn = c->args.args[0];
|
value assn = c->args.args[0];
|
||||||
value o1 = c->args.args[1];
|
value o1 = c->args.args[1];
|
||||||
value o2 = c->args.args[2];
|
value o2 = c->args.args[2];
|
||||||
value ret = value(o1.resolve(this).n+o2.resolve(this).n);
|
value ret = value(o1.resolve(this)+o2.resolve(this));
|
||||||
assign(assn, ret);
|
assign(assn, ret);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -310,7 +310,7 @@ namespace dms {
|
|||||||
value assn = c->args.args[0];
|
value assn = c->args.args[0];
|
||||||
value o1 = c->args.args[1];
|
value o1 = c->args.args[1];
|
||||||
value o2 = c->args.args[2];
|
value o2 = c->args.args[2];
|
||||||
value ret = value(o1.resolve(this).n - o2.resolve(this).n);
|
value ret = value(o1.resolve(this) - o2.resolve(this));
|
||||||
assign(assn, ret);
|
assign(assn, ret);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -319,7 +319,7 @@ namespace dms {
|
|||||||
value assn = c->args.args[0];
|
value assn = c->args.args[0];
|
||||||
value o1 = c->args.args[1];
|
value o1 = c->args.args[1];
|
||||||
value o2 = c->args.args[2];
|
value o2 = c->args.args[2];
|
||||||
value ret = value(o1.resolve(this).n * o2.resolve(this).n);
|
value ret = value(o1.resolve(this) * o2.resolve(this));
|
||||||
assign(assn, ret);
|
assign(assn, ret);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -328,7 +328,7 @@ namespace dms {
|
|||||||
value assn = c->args.args[0];
|
value assn = c->args.args[0];
|
||||||
value o1 = c->args.args[1];
|
value o1 = c->args.args[1];
|
||||||
value o2 = c->args.args[2];
|
value o2 = c->args.args[2];
|
||||||
value ret = value(o1.resolve(this).n / o2.resolve(this).n);
|
value ret = value(o1.resolve(this) / o2.resolve(this));
|
||||||
assign(assn, ret);
|
assign(assn, ret);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -450,29 +450,31 @@ namespace dms {
|
|||||||
break;
|
break;
|
||||||
case SSPK:
|
case SSPK:
|
||||||
//Because we are using void* we must cast our pointers
|
//Because we are using void* we must cast our pointers
|
||||||
if (characterExists(c->args.args[0].s->getValue())){
|
if (characterExists(c->args.args[0].s)){
|
||||||
speaker = getCharacter(c->args.args[0].s->getValue());
|
speaker = getCharacter(c->args.args[0].s);
|
||||||
if (!handler->handleSpeaker(this, speaker))
|
if (!handler->handleSpeaker(this, speaker))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
push_error(errors::error{ errors::disp_unknown,concat("Unknown character '",c->args.args[0].s->getValue(),"'!")});
|
push_error(errors::error{ errors::disp_unknown,concat("Unknown character '",c->args.args[0].s,"'!")});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APND:
|
case APND:
|
||||||
if (!handler->handleMessageAppend(this, c->args.args[0].s->getValue(this)))
|
//FIX STRING STER
|
||||||
|
if (!handler->handleMessageAppend(this, c->args.args[0].s))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case DISP:
|
case DISP:
|
||||||
if (!handler->handleMessageDisplay(this, c->args.args[0].s->getValue(this)))
|
//FIX STRING STER
|
||||||
|
if (!handler->handleMessageDisplay(this, c->args.args[0].s))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case ASGN:
|
case ASGN:
|
||||||
assign(c->args.args[0], c->args.args[1]);
|
assign(c->args.args[0], c->args.args[1]);
|
||||||
break;
|
break;
|
||||||
case LINE:
|
case LINE:
|
||||||
cur_line = c->args.args[0].n;
|
cur_line = (size_t)c->args.args[0].n;
|
||||||
break;
|
break;
|
||||||
case NOOP:
|
case NOOP:
|
||||||
break;
|
break;
|
||||||
@ -480,10 +482,10 @@ namespace dms {
|
|||||||
//Because we are using void* we must cast our pointers
|
//Because we are using void* we must cast our pointers
|
||||||
{
|
{
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
std::string prompt = c->args.args[0].s->getValue();
|
std::string prompt = c->args.args[0].s;
|
||||||
std::string fn = c->args.args[1].s->getValue();
|
std::string fn = c->args.args[1].s;
|
||||||
for (size_t i = 2; i < c->args.args.size(); i++)
|
for (size_t i = 2; i < c->args.args.size(); i++)
|
||||||
args.push_back(c->args.args[i].resolve(this).s->getValue());
|
args.push_back(c->args.args[i].resolve(this).s);
|
||||||
size_t npos = handler->handleChoice(this, prompt, args);
|
size_t npos = handler->handleChoice(this, prompt, args);
|
||||||
size_t nnpos = seek(concat("CHOI_", fn, "_", npos),cmds,LABL,pos);
|
size_t nnpos = seek(concat("CHOI_", fn, "_", npos),cmds,LABL,pos);
|
||||||
if (!nnpos) {
|
if (!nnpos) {
|
||||||
@ -498,7 +500,7 @@ namespace dms {
|
|||||||
case JUMP:
|
case JUMP:
|
||||||
// Value assert resolves the data so a variable must eventually equal a string
|
// Value assert resolves the data so a variable must eventually equal a string
|
||||||
if (utils::valueassert(c->args, this, datatypes::string)) {
|
if (utils::valueassert(c->args, this, datatypes::string)) {
|
||||||
std::string block = c->args.args[0].resolve(this).s->getValue();
|
std::string block = c->args.args[0].resolve(this).s;
|
||||||
if (chunks[block] == NULL) {
|
if (chunks[block] == NULL) {
|
||||||
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block [",block,"]") });
|
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block [",block,"]") });
|
||||||
return false;
|
return false;
|
||||||
@ -515,7 +517,7 @@ namespace dms {
|
|||||||
//utils::print(c->args.args[0].type);
|
//utils::print(c->args.args[0].type);
|
||||||
datatypes set = c->args.args[0].resolve(this).type;
|
datatypes set = c->args.args[0].resolve(this).type;
|
||||||
//utils::print("> ",set);
|
//utils::print("> ",set);
|
||||||
push_error(errors::error{ errors::invalid_arguments, utils::concat("String expected got ",datatype[set]), true,ln });
|
push_error(errors::error{ errors::invalid_arguments, utils::concat("String expected got ",datatype[set]), true, ln });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
BIN
DMS/dump.bin
BIN
DMS/dump.bin
Binary file not shown.
232
DMS/dump.txt
232
DMS/dump.txt
@ -39,211 +39,153 @@ Line <12> name main
|
|||||||
Line <12> bracketc ]
|
Line <12> bracketc ]
|
||||||
Line <12> newline
|
Line <12> newline
|
||||||
Line <12> newline
|
Line <12> newline
|
||||||
Line <13> name Ryan
|
Line <13> name a
|
||||||
Line <13> colon :
|
Line <13> equal =
|
||||||
Line <13> string Hello `Bob`, how are you doing?
|
Line <13> number 10
|
||||||
Line <13> newline
|
Line <13> newline
|
||||||
Line <13> newline
|
Line <13> newline
|
||||||
Line <14> name Bob
|
Line <14> name b
|
||||||
Line <14> colon :
|
Line <14> equal =
|
||||||
Line <14> string Hi `Ryan`, I'm good, I'm Bob by the way.
|
Line <14> number 15
|
||||||
Line <14> newline
|
Line <14> newline
|
||||||
Line <14> newline
|
Line <14> newline
|
||||||
Line <15> name Ryan
|
Line <15> name print
|
||||||
Line <15> colon :
|
Line <15> parao (
|
||||||
Line <15> string Oh so your name is `Bob`, nice to meet you!
|
Line <15> name a
|
||||||
|
Line <15> equal =
|
||||||
|
Line <15> equal =
|
||||||
|
Line <15> name b
|
||||||
|
Line <15> or
|
||||||
|
Line <15> parao (
|
||||||
|
Line <15> name a
|
||||||
|
Line <15> not !
|
||||||
|
Line <15> equal =
|
||||||
|
Line <15> name b
|
||||||
|
Line <15> and
|
||||||
|
Line <15> name a
|
||||||
|
Line <15> equal =
|
||||||
|
Line <15> equal =
|
||||||
|
Line <15> name a
|
||||||
|
Line <15> parac )
|
||||||
|
Line <15> or
|
||||||
|
Line <15> name a
|
||||||
|
Line <15> anglebracketC >
|
||||||
|
Line <15> name b
|
||||||
|
Line <15> parac )
|
||||||
Line <15> newline
|
Line <15> newline
|
||||||
Line <15> newline
|
Line <15> newline
|
||||||
|
Line <16> name if
|
||||||
|
Line <16> parao (
|
||||||
Line <16> name a
|
Line <16> name a
|
||||||
Line <16> equal =
|
Line <16> equal =
|
||||||
Line <16> number 1000
|
Line <16> equal =
|
||||||
|
Line <16> name b
|
||||||
|
Line <16> parac )
|
||||||
|
Line <16> cbracketo {
|
||||||
Line <16> newline
|
Line <16> newline
|
||||||
Line <16> newline
|
Line <16> newline
|
||||||
Line <17> name imp
|
|
||||||
Line <17> equal =
|
|
||||||
Line <17> string this
|
|
||||||
Line <17> newline
|
Line <17> newline
|
||||||
Line <17> newline
|
Line <17> newline
|
||||||
Line <18> name print
|
Line <18> cbracketc }
|
||||||
Line <18> parao (
|
|
||||||
Line <18> string Hello
|
|
||||||
Line <18> seperator ,
|
|
||||||
Line <18> number 122
|
|
||||||
Line <18> equal =
|
|
||||||
Line <18> equal =
|
|
||||||
Line <18> number 123
|
|
||||||
Line <18> parac )
|
|
||||||
Line <18> newline
|
Line <18> newline
|
||||||
Line <18> newline
|
Line <18> newline
|
||||||
Line <19> name test
|
|
||||||
Line <19> equal =
|
|
||||||
Line <19> name invokeTest
|
|
||||||
Line <19> parao (
|
|
||||||
Line <19> string Running external code!
|
|
||||||
Line <19> parac )
|
|
||||||
Line <19> newline
|
Line <19> newline
|
||||||
Line <19> newline
|
|
||||||
Line <19> newline
|
|
||||||
Line <20> string Loop Test... `test`
|
|
||||||
Line <20> newline
|
Line <20> newline
|
||||||
Line <20> newline
|
Line <20> newline
|
||||||
Line <21> control
|
|
||||||
Line <21> string Pick one
|
|
||||||
Line <21> cbracketo {
|
|
||||||
Line <21> newline
|
Line <21> newline
|
||||||
Line <21> newline
|
|
||||||
Line <22> string this
|
|
||||||
Line <22> gotoo
|
|
||||||
Line <22> name imp
|
|
||||||
Line <22> newline
|
Line <22> newline
|
||||||
Line <22> newline
|
Line <22> newline
|
||||||
Line <23> string that
|
|
||||||
Line <23> gotoo
|
|
||||||
Line <23> parao (
|
|
||||||
Line <23> string that
|
|
||||||
Line <23> parac )
|
|
||||||
Line <23> newline
|
Line <23> newline
|
||||||
Line <23> newline
|
Line <23> newline
|
||||||
Line <24> cbracketc }
|
|
||||||
Line <24> newline
|
Line <24> newline
|
||||||
Line <24> newline
|
|
||||||
Line <25> flag
|
|
||||||
Line <25> name test
|
|
||||||
Line <25> newline
|
Line <25> newline
|
||||||
Line <25> newline
|
Line <25> newline
|
||||||
Line <26> label this
|
|
||||||
Line <26> newline
|
Line <26> newline
|
||||||
Line <26> newline
|
|
||||||
Line <27> string At "this"
|
|
||||||
Line <27> newline
|
Line <27> newline
|
||||||
Line <27> newline
|
Line <27> newline
|
||||||
Line <28> gotoo
|
|
||||||
Line <28> string loop
|
|
||||||
Line <28> newline
|
Line <28> newline
|
||||||
Line <28> newline
|
|
||||||
Line <29> label that
|
|
||||||
Line <29> newline
|
Line <29> newline
|
||||||
Line <29> newline
|
Line <29> newline
|
||||||
Line <30> string At "that"
|
|
||||||
Line <30> newline
|
Line <30> newline
|
||||||
Line <30> newline
|
|
||||||
Line <31> label loop
|
|
||||||
Line <31> newline
|
Line <31> newline
|
||||||
Line <31> newline
|
Line <31> newline
|
||||||
Line <32> name a
|
Line <32> bracketo [
|
||||||
Line <32> equal =
|
Line <32> name Bob
|
||||||
Line <32> name a
|
Line <32> colon :
|
||||||
Line <32> plus +
|
Line <32> name char
|
||||||
Line <32> number 1
|
Line <32> bracketc ]
|
||||||
Line <32> newline
|
Line <32> newline
|
||||||
Line <32> newline
|
Line <32> newline
|
||||||
Line <33> string a = `a`
|
|
||||||
Line <33> newline
|
Line <33> newline
|
||||||
Line <33> newline
|
|
||||||
Line <34> gotoo
|
|
||||||
Line <34> parao (
|
|
||||||
Line <34> string loop
|
|
||||||
Line <34> parac )
|
|
||||||
Line <34> newline
|
|
||||||
Line <34> newline
|
Line <34> newline
|
||||||
Line <35> newline
|
Line <35> newline
|
||||||
Line <35> newline
|
Line <36> name unknown
|
||||||
|
Line <36> equal =
|
||||||
|
Line <36> string Some Random Guy
|
||||||
Line <36> newline
|
Line <36> newline
|
||||||
Line <36> newline
|
Line <36> newline
|
||||||
|
Line <37> name age
|
||||||
|
Line <37> equal =
|
||||||
|
Line <37> number 0.24
|
||||||
Line <37> newline
|
Line <37> newline
|
||||||
|
Line <37> newline
|
||||||
|
Line <38> name money
|
||||||
|
Line <38> equal =
|
||||||
|
Line <38> number 100
|
||||||
Line <38> newline
|
Line <38> newline
|
||||||
Line <38> newline
|
Line <38> newline
|
||||||
|
Line <39> name excited
|
||||||
|
Line <39> colon :
|
||||||
|
Line <39> string path/to/file
|
||||||
Line <39> newline
|
Line <39> newline
|
||||||
Line <39> newline
|
Line <39> newline
|
||||||
Line <40> newline
|
Line <40> newline
|
||||||
|
Line <40> newline
|
||||||
|
Line <41> bracketo [
|
||||||
|
Line <41> name test1
|
||||||
|
Line <41> colon :
|
||||||
|
Line <41> name function
|
||||||
|
Line <41> parao (
|
||||||
|
Line <41> parac )
|
||||||
|
Line <41> bracketc ]
|
||||||
Line <41> newline
|
Line <41> newline
|
||||||
Line <41> newline
|
Line <41> newline
|
||||||
|
Line <42> string Inside a function!
|
||||||
|
Line <42> newline
|
||||||
Line <42> newline
|
Line <42> newline
|
||||||
Line <43> newline
|
|
||||||
Line <43> newline
|
Line <43> newline
|
||||||
Line <44> newline
|
Line <44> newline
|
||||||
Line <45> newline
|
Line <45> newline
|
||||||
Line <45> newline
|
Line <45> newline
|
||||||
|
Line <46> bracketo [
|
||||||
|
Line <46> name newblock
|
||||||
|
Line <46> colon :
|
||||||
|
Line <46> name function
|
||||||
|
Line <46> parao (
|
||||||
|
Line <46> name a
|
||||||
|
Line <46> seperator ,
|
||||||
|
Line <46> name b
|
||||||
|
Line <46> seperator ,
|
||||||
|
Line <46> name c
|
||||||
|
Line <46> parac )
|
||||||
|
Line <46> bracketc ]
|
||||||
Line <46> newline
|
Line <46> newline
|
||||||
|
Line <46> newline
|
||||||
|
Line <47> string Func Arguments: a = `a`, b = `b`, c = `c`
|
||||||
Line <47> newline
|
Line <47> newline
|
||||||
Line <47> newline
|
Line <47> newline
|
||||||
Line <48> bracketo [
|
Line <48> string Time to return
|
||||||
Line <48> name Bob
|
|
||||||
Line <48> colon :
|
|
||||||
Line <48> name char
|
|
||||||
Line <48> bracketc ]
|
|
||||||
Line <48> newline
|
Line <48> newline
|
||||||
Line <48> newline
|
Line <48> newline
|
||||||
|
Line <49> ret
|
||||||
|
Line <49> name a
|
||||||
|
Line <49> plus +
|
||||||
|
Line <49> name b
|
||||||
|
Line <49> plus +
|
||||||
|
Line <49> name c
|
||||||
Line <49> newline
|
Line <49> newline
|
||||||
Line <50> newline
|
Line <49> newline
|
||||||
Line <51> newline
|
Line <49> eof
|
||||||
Line <52> name unknown
|
|
||||||
Line <52> equal =
|
|
||||||
Line <52> string Some Random Guy
|
|
||||||
Line <52> newline
|
|
||||||
Line <52> newline
|
|
||||||
Line <53> name age
|
|
||||||
Line <53> equal =
|
|
||||||
Line <53> number 0.24
|
|
||||||
Line <53> newline
|
|
||||||
Line <53> newline
|
|
||||||
Line <54> name money
|
|
||||||
Line <54> equal =
|
|
||||||
Line <54> number 100
|
|
||||||
Line <54> newline
|
|
||||||
Line <54> newline
|
|
||||||
Line <55> name excited
|
|
||||||
Line <55> colon :
|
|
||||||
Line <55> string path/to/file
|
|
||||||
Line <55> newline
|
|
||||||
Line <55> newline
|
|
||||||
Line <56> newline
|
|
||||||
Line <56> newline
|
|
||||||
Line <57> bracketo [
|
|
||||||
Line <57> name test1
|
|
||||||
Line <57> colon :
|
|
||||||
Line <57> name function
|
|
||||||
Line <57> parao (
|
|
||||||
Line <57> parac )
|
|
||||||
Line <57> bracketc ]
|
|
||||||
Line <57> newline
|
|
||||||
Line <57> newline
|
|
||||||
Line <58> string Inside a function!
|
|
||||||
Line <58> newline
|
|
||||||
Line <58> newline
|
|
||||||
Line <59> newline
|
|
||||||
Line <60> newline
|
|
||||||
Line <61> newline
|
|
||||||
Line <61> newline
|
|
||||||
Line <62> bracketo [
|
|
||||||
Line <62> name newblock
|
|
||||||
Line <62> colon :
|
|
||||||
Line <62> name function
|
|
||||||
Line <62> parao (
|
|
||||||
Line <62> name a
|
|
||||||
Line <62> seperator ,
|
|
||||||
Line <62> name b
|
|
||||||
Line <62> seperator ,
|
|
||||||
Line <62> name c
|
|
||||||
Line <62> parac )
|
|
||||||
Line <62> bracketc ]
|
|
||||||
Line <62> newline
|
|
||||||
Line <62> newline
|
|
||||||
Line <63> string Func Arguments: a = `a`, b = `b`, c = `c`
|
|
||||||
Line <63> newline
|
|
||||||
Line <63> newline
|
|
||||||
Line <64> string Time to return
|
|
||||||
Line <64> newline
|
|
||||||
Line <64> newline
|
|
||||||
Line <65> ret
|
|
||||||
Line <65> name a
|
|
||||||
Line <65> plus +
|
|
||||||
Line <65> name b
|
|
||||||
Line <65> plus +
|
|
||||||
Line <65> name c
|
|
||||||
Line <65> newline
|
|
||||||
Line <65> newline
|
|
||||||
Line <65> eof
|
|
||||||
Line <1> newline
|
Line <1> newline
|
||||||
Line <1> newline
|
Line <1> newline
|
||||||
Line <1> bracketo [
|
Line <1> bracketo [
|
||||||
|
|||||||
28
DMS/test.dms
28
DMS/test.dms
@ -10,29 +10,13 @@ loadfile "loadtest.dms"
|
|||||||
version 0.2
|
version 0.2
|
||||||
using extendedDefine
|
using extendedDefine
|
||||||
[main]
|
[main]
|
||||||
Ryan: "Hello `Bob`, how are you doing?"
|
a = 10
|
||||||
Bob: "Hi `Ryan`, I'm good, I'm Bob by the way."
|
b = 15
|
||||||
Ryan: "Oh so your name is `Bob`, nice to meet you!"
|
print(a==b or (a!=b and a==a) or a>b)
|
||||||
a = 1000
|
if(a==b){
|
||||||
imp = "this"
|
|
||||||
print("Hello",122==123)
|
|
||||||
test = invokeTest("Running external code!");
|
|
||||||
"Loop Test... `test`"
|
|
||||||
choice "Pick one" {
|
|
||||||
"this" goto imp
|
|
||||||
"that" goto ("that")
|
|
||||||
}
|
|
||||||
enable test
|
|
||||||
::this::
|
|
||||||
"At \"this\""
|
|
||||||
goto "loop"
|
|
||||||
::that::
|
|
||||||
"At \"that\""
|
|
||||||
::loop::
|
|
||||||
a = a + 1
|
|
||||||
"a = `a`"
|
|
||||||
goto ("loop")
|
|
||||||
|
|
||||||
|
}
|
||||||
|
// 0 + (1 * 0) + 0
|
||||||
|
|
||||||
// if (this==that) this()|that()
|
// if (this==that) this()|that()
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,19 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
namespace dms::utils {
|
namespace dms::utils {
|
||||||
|
void print(const value val) {
|
||||||
|
printf(val.getPrintable().c_str());
|
||||||
|
}
|
||||||
|
std::string concat(value& v1, value& v2, value& v3, value& v4, value& v5, value& v7, value& v8, value& v9, value& v10, value& v11, value& v12) {
|
||||||
|
std::vector<value> list{v1,v2,v3,v4,v5,v7,v8,v9,v10,v11,v12};
|
||||||
|
std::string str="";
|
||||||
|
for (size_t i = 0; i < list.size(); i++) {
|
||||||
|
if (list[i] != nullptr)
|
||||||
|
str = (str + list[i].toString());
|
||||||
|
else
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
void sleep(unsigned int mseconds)
|
void sleep(unsigned int mseconds)
|
||||||
{
|
{
|
||||||
clock_t goal = mseconds + clock();
|
clock_t goal = mseconds + clock();
|
||||||
|
|||||||
@ -10,13 +10,14 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
namespace dms::utils {
|
namespace dms::utils {
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
void print(const Args... args) {
|
void debug(const Args... args) {
|
||||||
(std::cout << ... << args) << std::endl;
|
(std::cout << ... << args) << std::endl;
|
||||||
}
|
}
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
void write(const Args... args) {
|
void write(const Args... args) {
|
||||||
(std::cout << ... << args);
|
(std::cout << ... << args);
|
||||||
}
|
}
|
||||||
|
void print(const value values...);
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
std::string concat(Args... args) {
|
std::string concat(Args... args) {
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
|
|||||||
103
DMS/value.cpp
103
DMS/value.cpp
@ -2,25 +2,29 @@
|
|||||||
#include "dms_state.h"
|
#include "dms_state.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
namespace dms {
|
namespace dms {
|
||||||
const std::string datatype[] = { "escape", "nil", "number", "boolean", "env", "string", "custom", "variable", "block" };
|
const std::string datatype[] = { "escape", "nil", "number", "boolean", "env", "string", "custom", "variable", "block" , "error"};
|
||||||
value::value() {
|
value::value() {
|
||||||
// Nothing to do here yet!
|
// Nothing to do here yet!
|
||||||
}
|
}
|
||||||
value::value(char const* str, datatypes t) {
|
value::value(char const* str, datatypes t) {
|
||||||
type = t;
|
type = t;
|
||||||
s = buildString(str);
|
s = str;
|
||||||
}
|
}
|
||||||
value::value(char const* str) {
|
value::value(char const* str) {
|
||||||
type = datatypes::string;
|
type = datatypes::string;
|
||||||
s = buildString(str);
|
s = str;
|
||||||
|
}
|
||||||
|
value::value(size_t val) {
|
||||||
|
type = datatypes::number;
|
||||||
|
n = val;
|
||||||
}
|
}
|
||||||
value::value(std::string str) {
|
value::value(std::string str) {
|
||||||
type = datatypes::string;
|
type = datatypes::string;
|
||||||
s = buildString(str);
|
s = str;
|
||||||
}
|
}
|
||||||
value::value(std::string str,datatypes t) {
|
value::value(std::string str,datatypes t) {
|
||||||
type = t;
|
type = t;
|
||||||
s = buildString(str);
|
s = str;
|
||||||
}
|
}
|
||||||
value::value(double d) {
|
value::value(double d) {
|
||||||
type = datatypes::number;
|
type = datatypes::number;
|
||||||
@ -40,7 +44,7 @@ namespace dms {
|
|||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
value::value(datatypes t) : value() {
|
value::value(datatypes t) : value() {
|
||||||
if (t == datatypes::variable) {
|
if (t == datatypes::variable) {
|
||||||
set(buildString(utils::concat("$",++count)));
|
set(utils::concat("$",++count));
|
||||||
}
|
}
|
||||||
type = t;
|
type = t;
|
||||||
}
|
}
|
||||||
@ -49,7 +53,7 @@ namespace dms {
|
|||||||
type = other.type;
|
type = other.type;
|
||||||
switch (other.type) {
|
switch (other.type) {
|
||||||
case datatypes::block:
|
case datatypes::block:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::boolean:
|
case datatypes::boolean:
|
||||||
b = other.b;
|
b = other.b;
|
||||||
@ -61,7 +65,7 @@ namespace dms {
|
|||||||
// Handle this later
|
// Handle this later
|
||||||
break;
|
break;
|
||||||
case datatypes::escape:
|
case datatypes::escape:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::nil:
|
case datatypes::nil:
|
||||||
// No need to do anything
|
// No need to do anything
|
||||||
@ -70,10 +74,10 @@ namespace dms {
|
|||||||
n = other.n;
|
n = other.n;
|
||||||
break;
|
break;
|
||||||
case datatypes::string:
|
case datatypes::string:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::variable:
|
case datatypes::variable:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -86,7 +90,7 @@ namespace dms {
|
|||||||
type = other.type;
|
type = other.type;
|
||||||
switch (other.type) {
|
switch (other.type) {
|
||||||
case datatypes::block:
|
case datatypes::block:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::boolean:
|
case datatypes::boolean:
|
||||||
b = other.b;
|
b = other.b;
|
||||||
@ -98,7 +102,7 @@ namespace dms {
|
|||||||
// Handle this later
|
// Handle this later
|
||||||
break;
|
break;
|
||||||
case datatypes::escape:
|
case datatypes::escape:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::nil:
|
case datatypes::nil:
|
||||||
// No need to do anything
|
// No need to do anything
|
||||||
@ -107,10 +111,10 @@ namespace dms {
|
|||||||
n = other.n;
|
n = other.n;
|
||||||
break;
|
break;
|
||||||
case datatypes::string:
|
case datatypes::string:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::variable:
|
case datatypes::variable:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -129,7 +133,7 @@ namespace dms {
|
|||||||
type = other.type;
|
type = other.type;
|
||||||
switch (other.type) {
|
switch (other.type) {
|
||||||
case datatypes::block:
|
case datatypes::block:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::boolean:
|
case datatypes::boolean:
|
||||||
b = other.b;
|
b = other.b;
|
||||||
@ -141,7 +145,7 @@ namespace dms {
|
|||||||
// Handle this later
|
// Handle this later
|
||||||
break;
|
break;
|
||||||
case datatypes::escape:
|
case datatypes::escape:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::nil:
|
case datatypes::nil:
|
||||||
// No need to do anything
|
// No need to do anything
|
||||||
@ -150,10 +154,10 @@ namespace dms {
|
|||||||
n = other.n;
|
n = other.n;
|
||||||
break;
|
break;
|
||||||
case datatypes::string:
|
case datatypes::string:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
case datatypes::variable:
|
case datatypes::variable:
|
||||||
s = buildString(other.s->val);
|
s = other.s;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -169,9 +173,15 @@ namespace dms {
|
|||||||
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
|
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
|
||||||
return value(lhs.n + rhs.n);
|
return value(lhs.n + rhs.n);
|
||||||
}
|
}
|
||||||
else {
|
else if (lhs.type == datatypes::boolean && rhs.type == datatypes::boolean) {
|
||||||
|
return value((bool)(lhs.b + rhs.b));
|
||||||
|
}
|
||||||
|
else if (lhs.type == datatypes::string || rhs.type == datatypes::string) {
|
||||||
return lhs.getPrintable() + rhs.getPrintable();
|
return lhs.getPrintable() + rhs.getPrintable();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return value("Invalid use of '+'!", datatypes::error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
value operator-(const value& lhs, const value& rhs) {
|
value operator-(const value& lhs, const value& rhs) {
|
||||||
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
|
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
|
||||||
@ -193,6 +203,9 @@ namespace dms {
|
|||||||
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
|
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
|
||||||
return value(lhs.n * rhs.n);
|
return value(lhs.n * rhs.n);
|
||||||
}
|
}
|
||||||
|
else if (lhs.type == datatypes::boolean && rhs.type == datatypes::boolean) {
|
||||||
|
return value((bool)(lhs.b * rhs.b));
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return value(datatypes::error);
|
return value(datatypes::error);
|
||||||
}
|
}
|
||||||
@ -237,6 +250,9 @@ namespace dms {
|
|||||||
return args.size();
|
return args.size();
|
||||||
}
|
}
|
||||||
std::string dms_string::getValue(dms_state* state) {
|
std::string dms_string::getValue(dms_state* state) {
|
||||||
|
std::vector<char> _temp;
|
||||||
|
std::vector<char> _var;
|
||||||
|
std::vector<char> _ind;
|
||||||
std::stringstream temp;
|
std::stringstream temp;
|
||||||
std::stringstream var;
|
std::stringstream var;
|
||||||
std::stringstream ind;
|
std::stringstream ind;
|
||||||
@ -316,8 +332,8 @@ namespace dms {
|
|||||||
if (state->getMem()->count(lookup)) {
|
if (state->getMem()->count(lookup)) {
|
||||||
value v = (*state->getMem())[lookup];
|
value v = (*state->getMem())[lookup];
|
||||||
if (v.type == datatypes::block) {
|
if (v.type == datatypes::block) {
|
||||||
if (state->getCharacter(v.s->getValue())) {
|
if (state->getCharacter(v.s)) {
|
||||||
temp << state->characters[v.s->getValue()]->getName();
|
temp << state->characters[v.s]->getName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
temp << "nil";
|
temp << "nil";
|
||||||
@ -351,60 +367,51 @@ namespace dms {
|
|||||||
return temp.str();
|
return temp.str();
|
||||||
}
|
}
|
||||||
std::string value::getPrintable() const {
|
std::string value::getPrintable() const {
|
||||||
std::stringstream out;
|
|
||||||
if (type == string) {
|
if (type == string) {
|
||||||
out << s->getValue();
|
return s;
|
||||||
}
|
}
|
||||||
else if (type == number) {
|
else if (type == number) {
|
||||||
out << n;
|
return std::to_string(n);
|
||||||
}
|
}
|
||||||
else if (type == nil) {
|
else if (type == nil) {
|
||||||
out << "nil";
|
return "nil";
|
||||||
}
|
}
|
||||||
else if (type == boolean) {
|
else if (type == boolean) {
|
||||||
if (b)
|
if (b)
|
||||||
out << "true";
|
return "true";
|
||||||
else
|
else
|
||||||
out << "false";
|
return "false";
|
||||||
}
|
}
|
||||||
else if (type == env) {
|
else if (type == env) {
|
||||||
out << "Env: " << this;
|
return "env";
|
||||||
}
|
}
|
||||||
else if (type == custom) {
|
else if (type == custom) {
|
||||||
out << "Custom Data: " << this;
|
return "custom";
|
||||||
}
|
}
|
||||||
else if (type == block) {
|
else if (type == block) {
|
||||||
out << s->getValue();
|
return s;
|
||||||
}
|
}
|
||||||
else if (type == datatypes::variable) {
|
else if (type == datatypes::variable) {
|
||||||
out << s->getValue(); // Do the lookup
|
return s; // Do the lookup
|
||||||
}
|
}
|
||||||
return out.str();
|
else if (type == datatypes::error) {
|
||||||
|
return std::string("ERROR: ") + s;
|
||||||
}
|
}
|
||||||
dms_string* buildString(std::string str) {
|
return "unknown";
|
||||||
std::stringstream newstr;
|
|
||||||
for (int i = 0; i < str.size(); i++)
|
|
||||||
newstr << str[i];
|
|
||||||
dms_string* dms_str = new dms_string{ newstr.str() };
|
|
||||||
return dms_str;
|
|
||||||
}
|
}
|
||||||
std::string value::toString() const {
|
std::string value::toString() const {
|
||||||
std::stringstream temp;
|
return getPrintable();
|
||||||
temp << this;
|
|
||||||
return temp.str();
|
|
||||||
}
|
}
|
||||||
// Compile time
|
// Compile time
|
||||||
void value::nuke() {
|
void value::nuke() {
|
||||||
delete s;
|
|
||||||
delete e;
|
delete e;
|
||||||
delete c;
|
delete c;
|
||||||
s = nullptr;
|
|
||||||
e = nullptr;
|
e = nullptr;
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
}
|
}
|
||||||
std::ostream& operator << (std::ostream& out, const value& c) {
|
std::ostream& operator << (std::ostream& out, const value& c) {
|
||||||
if (c.type == string) {
|
if (c.type == string) {
|
||||||
out << (char)c.type << c.s->getValue() << (char)0;
|
out << (char)c.type << c.s << (char)0;
|
||||||
}
|
}
|
||||||
else if (c.type == number) {
|
else if (c.type == number) {
|
||||||
out << (char)c.type << c.n;
|
out << (char)c.type << c.n;
|
||||||
@ -425,10 +432,10 @@ namespace dms {
|
|||||||
out << (char)c.type << "Custom Data: " << c;
|
out << (char)c.type << "Custom Data: " << c;
|
||||||
}
|
}
|
||||||
else if (c.type == block) {
|
else if (c.type == block) {
|
||||||
out << (char)c.type << c.s->getValue();
|
out << (char)c.type << c.s;
|
||||||
}
|
}
|
||||||
else if (c.type == datatypes::variable) {
|
else if (c.type == datatypes::variable) {
|
||||||
out << (char)c.type << c.s->getValue(); // Do the lookup
|
out << (char)c.type << c.s; // Do the lookup
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
@ -441,7 +448,7 @@ namespace dms {
|
|||||||
n = val->n;
|
n = val->n;
|
||||||
}
|
}
|
||||||
else if (type == datatypes::string || type == datatypes::block || type == datatypes::variable) {
|
else if (type == datatypes::string || type == datatypes::block || type == datatypes::variable) {
|
||||||
s->val = val->s->val;
|
s = val->s;
|
||||||
}
|
}
|
||||||
else if (type == datatypes::boolean) {
|
else if (type == datatypes::boolean) {
|
||||||
b = val->b;
|
b = val->b;
|
||||||
@ -451,7 +458,7 @@ namespace dms {
|
|||||||
}
|
}
|
||||||
type = val->type;
|
type = val->type;
|
||||||
}
|
}
|
||||||
void value::set(dms_string* str) {
|
void value::set(std::string str) {
|
||||||
nuke();
|
nuke();
|
||||||
s = str;
|
s = str;
|
||||||
type = string;
|
type = string;
|
||||||
|
|||||||
@ -50,13 +50,12 @@ namespace dms {
|
|||||||
dms_state* state=nullptr;
|
dms_state* state=nullptr;
|
||||||
value* self;
|
value* self;
|
||||||
};
|
};
|
||||||
dms_string* buildString(std::string str);
|
|
||||||
struct value {
|
struct value {
|
||||||
public:
|
public:
|
||||||
datatypes type = datatypes::nil;
|
datatypes type = datatypes::nil;
|
||||||
bool b=false;
|
bool b=false;
|
||||||
double n=0;
|
double n=0;
|
||||||
dms_string* s = nullptr;
|
std::string s;
|
||||||
dms_list* e = nullptr;
|
dms_list* e = nullptr;
|
||||||
dms_custom* c = nullptr;
|
dms_custom* c = nullptr;
|
||||||
value();
|
value();
|
||||||
@ -67,6 +66,7 @@ namespace dms {
|
|||||||
value(char const*);
|
value(char const*);
|
||||||
value(double);
|
value(double);
|
||||||
value(int);
|
value(int);
|
||||||
|
value(size_t);
|
||||||
value(bool);
|
value(bool);
|
||||||
~value();
|
~value();
|
||||||
value(const value& other);
|
value(const value& other);
|
||||||
@ -87,7 +87,7 @@ namespace dms {
|
|||||||
value resolve(dms_state*);
|
value resolve(dms_state*);
|
||||||
void nuke();
|
void nuke();
|
||||||
void set(value*);
|
void set(value*);
|
||||||
void set(dms_string* str);
|
void set(std::string str);
|
||||||
void set(bool bo);
|
void set(bool bo);
|
||||||
void set(double num);
|
void set(double num);
|
||||||
void set(dms_list* en);
|
void set(dms_list* en);
|
||||||
|
|||||||
BIN
Debug/DMS.exe
BIN
Debug/DMS.exe
Binary file not shown.
BIN
Debug/DMS.ilk
BIN
Debug/DMS.ilk
Binary file not shown.
BIN
Debug/DMS.pdb
BIN
Debug/DMS.pdb
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user