Blocks finished, progress on commands starts
This commit is contained in:
parent
04eb7ba944
commit
c1b97b83a3
@ -1,2 +1,5 @@
|
||||
LineParser.cpp
|
||||
DMS.cpp
|
||||
LineParser.cpp
|
||||
chunk.cpp
|
||||
Generating Code...
|
||||
DMS.vcxproj -> C:\Users\Ryan\source\repos\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.
@ -14,7 +14,7 @@ namespace dms {
|
||||
token tokenstream::peek() {
|
||||
return this->tokens[pos];
|
||||
}
|
||||
std::vector<token> tokenstream::next(tokens::tokentype tk, size_t n) {
|
||||
std::vector<token> tokenstream::next(tokens::tokentype tk) {
|
||||
std::vector<token> temp;
|
||||
while (peek().type!=tk) {
|
||||
temp.push_back(next());
|
||||
@ -86,16 +86,16 @@ namespace dms {
|
||||
return true;
|
||||
if (stream.tokens[stream.pos+i].type != types[i])
|
||||
return false;
|
||||
print(stream.tokens[stream.pos + i].type, " | ", types[i]);
|
||||
//print(stream.tokens[stream.pos + i].type, " | ", types[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::map<std::string, chunk> LineParser::tokenizer(dms_state* state,std::vector<token> &toks) {
|
||||
std::map<std::string,chunk> chunks;
|
||||
std::map<std::string, chunk*> LineParser::tokenizer(dms_state* state,std::vector<token> &toks) {
|
||||
std::map<std::string,chunk*> chunks;
|
||||
chunk* current_chunk = nullptr;
|
||||
std::string chunk_name;
|
||||
blocktype chunk_type;
|
||||
|
||||
size_t line=1;
|
||||
tokenstream stream;
|
||||
stream.init(&toks);
|
||||
token current = stream.next();
|
||||
@ -105,7 +105,7 @@ namespace dms {
|
||||
if (current.type == tokens::flag) {
|
||||
temp = stream.next(tokens::newline);
|
||||
if (temp.size() != 2) {
|
||||
std::cout << "";
|
||||
std::cout << "Error";
|
||||
}
|
||||
codes::op code = current.raw;
|
||||
tokens::tokentype tok = temp[0].type;
|
||||
@ -129,49 +129,120 @@ namespace dms {
|
||||
}
|
||||
else {
|
||||
std::stringstream str;
|
||||
str << "Expected <FLAG IDENTIFIER> " << " got: " << current << " ";
|
||||
state->push_error(errors::error{errors::badtoken,str.str(),true,current.line_num});
|
||||
str << "Expected <FLAG IDENTIFIER> " << " got: " << current << temp[0];
|
||||
state->push_error(errors::error{errors::badtoken,str.str(),true,line});
|
||||
}
|
||||
std::cout << temp.size() << std::endl;
|
||||
std::cout << temp[0] << std::endl;
|
||||
}
|
||||
// To implement function we need to match stuff
|
||||
|
||||
//Todo Finish the chunk data stuff
|
||||
if (match(stream,tokens::newline,tokens::bracketo,tokens::name,tokens::bracketc)) {
|
||||
stream.next();
|
||||
if (current_chunk != nullptr)
|
||||
chunks.insert_or_assign(current_chunk->name, *current_chunk);
|
||||
|
||||
if (current_chunk != nullptr) {
|
||||
if (!chunks.count(current_chunk->name))
|
||||
chunks.insert_or_assign(current_chunk->name, current_chunk);
|
||||
else
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "Block <" << current_chunk->name << "> already defined!";
|
||||
state->push_error(errors::error{ errors::block_already_defined,str.str(),true,line });
|
||||
}
|
||||
}
|
||||
current_chunk = new chunk;
|
||||
stream.next(); // Consume
|
||||
chunk_type = bt_block;
|
||||
line = stream.next().line_num; // Consume
|
||||
current_chunk->name = stream.next().name;
|
||||
stream.next(); // Consume
|
||||
}
|
||||
// This handles a few block types since they all follow a similar format
|
||||
else if (match(stream, tokens::newline, tokens::bracketo, tokens::name,tokens::colon,tokens::name, tokens::bracketc)) {
|
||||
stream.next();
|
||||
stream.next();
|
||||
if (current_chunk != nullptr)
|
||||
chunks.insert_or_assign(current_chunk->name, *current_chunk);
|
||||
if (current_chunk != nullptr) {
|
||||
if (!chunks.count(current_chunk->name))
|
||||
chunks.insert_or_assign(current_chunk->name, current_chunk);
|
||||
else
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "Block <" << current_chunk->name << "> already defined!";
|
||||
state->push_error(errors::error{ errors::block_already_defined,str.str(),true,line });
|
||||
}
|
||||
}
|
||||
|
||||
current_chunk = new chunk;
|
||||
current_chunk->name = stream.next().name;
|
||||
stream.next();
|
||||
line = stream.next().line_num;
|
||||
std::string temp = stream.next().name;
|
||||
// Characters are a feature I want to have intergrated into the language
|
||||
if (temp == "char") {
|
||||
current_chunk->type = bt_character;
|
||||
chunk_type = bt_character;
|
||||
}
|
||||
// Enviroments are sortof like objects, they can be uses as an object. They are a cleaner way to build a hash map like object
|
||||
else if (temp == "env") {
|
||||
current_chunk->type = bt_env;
|
||||
chunk_type = bt_env;
|
||||
}
|
||||
// Menus are what they say on the tin. They provide the framework for having menus within your game
|
||||
else if (temp == "menu") {
|
||||
current_chunk->type = bt_menu;
|
||||
chunk_type = bt_menu;
|
||||
}
|
||||
stream.next();
|
||||
}
|
||||
wait();
|
||||
else if (match(stream, tokens::newline,tokens::bracketo,tokens::name,tokens::colon,tokens::name,tokens::parao)) {
|
||||
std::stringstream str;
|
||||
stream.next();
|
||||
stream.next();
|
||||
if (current_chunk != nullptr) {
|
||||
if (!chunks.count(current_chunk->name))
|
||||
chunks.insert_or_assign(current_chunk->name, current_chunk);
|
||||
else
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "Block <" << current_chunk->name << "> already defined!";
|
||||
state->push_error(errors::error{ errors::block_already_defined,str.str(),true,line });
|
||||
}
|
||||
}
|
||||
|
||||
current_chunk = new chunk;
|
||||
current_chunk->name = stream.next().name;
|
||||
line = stream.next().line_num; // The color, not needed after the inital match, but we still need to consume it
|
||||
std::string b = stream.next().name;
|
||||
if (b == "function") {
|
||||
current_chunk->type = bt_method; // We have a method let's set the block type to that, but we aren't done yet
|
||||
// We need to set the params if any so the method can be supplied with arguments
|
||||
stream.next(); // parao
|
||||
std::vector<token> tokens = stream.next(tokens::parac); // Consume until we see parac
|
||||
dms_args args;
|
||||
for (size_t i = 0; i < tokens.size()-1; i++) {//The lase symbol is parac since that was the consume condition
|
||||
if (tokens[i].type == tokens::name) {
|
||||
// We got a name which is refering to a variable so lets build one
|
||||
value v;
|
||||
v.type = variable; // Special type, it writes data to the string portion, but is interperted as a lookup
|
||||
v.s = buildString(tokens[i].name);
|
||||
args.push(v);
|
||||
}
|
||||
else if (tokens[i].type == tokens::seperator) {
|
||||
// We just ignore this
|
||||
}
|
||||
else {
|
||||
std::stringstream str;
|
||||
str << "Unexpected symbol: " << tokens[i];
|
||||
state->push_error(errors::error{errors::badtoken,str.str(),true,line });
|
||||
}
|
||||
}
|
||||
// If all went well the 'args' now has all of tha params for the method we will be working with
|
||||
current_chunk->params = args;
|
||||
// Thats should be all we need to do
|
||||
}
|
||||
else {
|
||||
str << "'function' keyword expected got " << b;
|
||||
state->push_error(errors::error{errors::badtoken, str.str(),true,line });
|
||||
}
|
||||
}
|
||||
current = stream.next();
|
||||
}
|
||||
chunks.insert_or_assign(current_chunk->name, current_chunk);
|
||||
return chunks;
|
||||
}
|
||||
void LineParser::tolower(std::string &s1) {
|
||||
@ -224,7 +295,7 @@ namespace dms {
|
||||
size_t line = 1;
|
||||
while (data != NULL) {
|
||||
if (data == '/' && stream.peek()=='/') {
|
||||
line++;
|
||||
//line++;
|
||||
stream.next('\n'); // Seek until you find a newline
|
||||
}
|
||||
else if (data == '\n') {
|
||||
@ -398,6 +469,12 @@ namespace dms {
|
||||
else if (str == "choice") {
|
||||
t_vec.push_back(token{ tokens::control,codes::CHOI,"",line });
|
||||
}
|
||||
else if (str == "return") {
|
||||
t_vec.push_back(token{ tokens::ret,codes::RETN,"",line });
|
||||
}
|
||||
else if (str == "nil") {
|
||||
t_vec.push_back(token{ tokens::nil,codes::NOOP,"",line });
|
||||
}
|
||||
else if (utils::isalphanum(str) && str.size()>0) {
|
||||
t_vec.push_back(token{ tokens::name,codes::NOOP,str,line });
|
||||
}
|
||||
@ -419,7 +496,8 @@ namespace dms {
|
||||
outputFile.close();
|
||||
print("Running tokenizer");
|
||||
// Tokens build let's parse
|
||||
tokenizer(state, t_vec);
|
||||
std::map<std::string,chunk*> test = tokenizer(state, t_vec);
|
||||
print(test.size());
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ namespace dms {
|
||||
void init(std::vector<tokens::token>* ptr);
|
||||
tokens::token next();
|
||||
tokens::token peek();
|
||||
std::vector<tokens::token> next(tokens::tokentype tk, size_t n=0);
|
||||
std::vector<tokens::token> next(tokens::tokentype tk);
|
||||
};
|
||||
struct passer {
|
||||
std::string stream;
|
||||
@ -45,6 +45,6 @@ namespace dms {
|
||||
//Matches tokens from the stream, if the tokens match it will return true and YOU should call next on the stream. This method does not change the current position
|
||||
bool match(tokenstream stream, 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);
|
||||
void tolower(std::string &str);
|
||||
std::map<std::string, chunk> tokenizer(dms_state* state, std::vector<tokens::token> &tok);
|
||||
std::map<std::string, chunk*> tokenizer(dms_state* state, std::vector<tokens::token> &tok);
|
||||
};
|
||||
}
|
||||
@ -12,9 +12,11 @@ namespace dms {
|
||||
struct chunk
|
||||
{
|
||||
blocktype type = bt_block;
|
||||
dms_args params;
|
||||
std::string name = "";
|
||||
std::vector<cmd> cmds = std::vector<cmd>();
|
||||
size_t pos = 0;
|
||||
size_t line = 0;
|
||||
void addCmd(cmd c);
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
#include "Codes.h"
|
||||
const std::string dms::codes::list[] = { "NOOP","ENTR","ENAB","DISA","LOAD","VERN","USIN","STAT","DISP","ASGN","LABL","CHOI","OPTN","FORE","????","WHLE","FNWR","FNNR","IFFF","ELIF","ELSE","DEFN","SKIP","COMP","INDX","JMPZ","INST","ERRO" };
|
||||
const std::string dms::codes::list[] = { "NOOP","ENTR","ENAB","DISA","LOAD","VERN","USIN","STAT","DISP","ASGN","LABL","CHOI","OPTN","FORE","????","WHLE","FNWR","FNNR","IFFF","ELIF","ELSE","DEFN","SKIP","COMP","INDX","JMPZ","INST","ERRO" ,"RETN" };
|
||||
@ -30,7 +30,8 @@ namespace dms::codes {
|
||||
INDX,
|
||||
JMPZ,
|
||||
INST,
|
||||
ERRO
|
||||
ERRO,
|
||||
RETN
|
||||
};
|
||||
extern const std::string list[];
|
||||
static bool isControl(const op code) {
|
||||
|
||||
@ -1 +1,12 @@
|
||||
#include "dms_state.h"
|
||||
namespace dms {
|
||||
void dms_state::push_error(errors::error err) {
|
||||
std::cout << err.err_msg << " On Line <" << err.linenum << ">" << std::endl;
|
||||
if(err.crash)
|
||||
std::exit(err.code);
|
||||
}
|
||||
void dms_state::push_warning(errors::error err) {
|
||||
err.crash = false; // Force code to not crash then push the error
|
||||
push_error(err);
|
||||
}
|
||||
}
|
||||
@ -2,11 +2,13 @@
|
||||
#include <string>
|
||||
#include "errors.h"
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
namespace dms {
|
||||
class dms_state
|
||||
{
|
||||
public:
|
||||
void push_error(errors::error err) {};
|
||||
void push_error(errors::error err);
|
||||
void push_warning(errors::error err);
|
||||
double version=1.0;
|
||||
std::string entry = "start";
|
||||
std::map<std::string, bool> enables;
|
||||
|
||||
317
DMS/dump.txt
317
DMS/dump.txt
@ -5,193 +5,207 @@ Line <1>NOOP newline
|
||||
Line <2>ENAB flag
|
||||
Line <2>NOOP name warnings
|
||||
Line <2>NOOP newline
|
||||
Line <3>NOOP newline
|
||||
Line <4>NOOP newline
|
||||
Line <5>VERN flag
|
||||
Line <5>NOOP number 1.2
|
||||
Line <5>NOOP newline
|
||||
Line <6>USIN flag
|
||||
Line <6>NOOP name extendedDefine
|
||||
Line <6>NOOP newline
|
||||
Line <7>VERN flag
|
||||
Line <7>NOOP number 1.2
|
||||
Line <7>NOOP newline
|
||||
Line <8>USIN flag
|
||||
Line <8>NOOP name extendedDefine
|
||||
Line <8>NOOP bracketo
|
||||
Line <8>NOOP name Ryan
|
||||
Line <8>NOOP colon
|
||||
Line <8>NOOP name char
|
||||
Line <8>NOOP bracketc
|
||||
Line <8>NOOP newline
|
||||
Line <9>NOOP tab
|
||||
Line <9>NOOP name name
|
||||
Line <9>NOOP equal
|
||||
Line <9>NOOP string Ryan
|
||||
Line <9>NOOP newline
|
||||
Line <10>NOOP bracketo
|
||||
Line <10>NOOP name Ryan
|
||||
Line <10>NOOP colon
|
||||
Line <10>NOOP name char
|
||||
Line <10>NOOP bracketc
|
||||
Line <10>NOOP cbracketo
|
||||
Line <10>NOOP tab
|
||||
Line <10>NOOP name age
|
||||
Line <10>NOOP equal
|
||||
Line <10>NOOP number 21
|
||||
Line <10>NOOP newline
|
||||
Line <11>NOOP tab
|
||||
Line <11>NOOP name name
|
||||
Line <11>NOOP equal
|
||||
Line <11>NOOP string Ryan
|
||||
Line <11>NOOP newline
|
||||
Line <12>NOOP tab
|
||||
Line <12>NOOP name age
|
||||
Line <12>NOOP equal
|
||||
Line <12>NOOP number 21
|
||||
Line <12>NOOP bracketo
|
||||
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 <13>NOOP cbracketc
|
||||
Line <13>NOOP tab
|
||||
Line <13>NOOP string Testing...
|
||||
Line <13>NOOP newline
|
||||
Line <14>NOOP tab
|
||||
Line <14>NOOP name d
|
||||
Line <14>NOOP equal
|
||||
Line <14>NOOP parao
|
||||
Line <14>NOOP name 100
|
||||
Line <14>NOOP number
|
||||
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 name nil
|
||||
Line <14>NOOP newline
|
||||
Line <15>NOOP bracketo
|
||||
Line <15>NOOP name main
|
||||
Line <15>NOOP bracketc
|
||||
Line <15>NOOP tab
|
||||
Line <15>RETN ret
|
||||
Line <15>NOOP name d
|
||||
Line <15>NOOP newline
|
||||
Line <16>NOOP tab
|
||||
Line <16>NOOP string This works!
|
||||
Line <16>NOOP newline
|
||||
Line <17>NOOP tab
|
||||
Line <17>NOOP string What's up
|
||||
Line <17>NOOP bracketo
|
||||
Line <17>NOOP name main
|
||||
Line <17>NOOP bracketc
|
||||
Line <17>NOOP newline
|
||||
Line <18>NOOP tab
|
||||
Line <18>NOOP string This works!
|
||||
Line <18>NOOP newline
|
||||
Line <19>NOOP tab
|
||||
Line <19>NOOP name ryan
|
||||
Line <19>NOOP string Hello "how" are you doing?
|
||||
Line <19>NOOP string What's up
|
||||
Line <19>NOOP newline
|
||||
Line <20>NOOP newline
|
||||
Line <21>NOOP tab
|
||||
Line <21>NOOP name bob
|
||||
Line <21>NOOP string I'm good you?
|
||||
Line <21>NOOP name ryan
|
||||
Line <21>NOOP string Hello "how" are you doing?
|
||||
Line <21>NOOP newline
|
||||
Line <22>NOOP tab
|
||||
Line <22>NOOP name bob
|
||||
Line <22>NOOP string I'm good you?
|
||||
Line <22>NOOP newline
|
||||
Line <23>NOOP tab
|
||||
Line <23>NOOP name tester
|
||||
Line <23>NOOP equal
|
||||
Line <23>NOOP string Hello
|
||||
Line <23>NOOP newline
|
||||
Line <24>NOOP tab
|
||||
Line <24>NOOP name tester
|
||||
Line <24>NOOP equal
|
||||
Line <24>NOOP string Hello
|
||||
Line <24>NOOP newline
|
||||
Line <25>NOOP tab
|
||||
Line <25>NOOP name food
|
||||
Line <25>NOOP equal
|
||||
Line <25>NOOP number 3
|
||||
Line <25>NOOP newline
|
||||
Line <26>NOOP tab
|
||||
Line <26>NOOP name food
|
||||
Line <26>NOOP equal
|
||||
Line <26>NOOP number 3
|
||||
Line <26>NOOP newline
|
||||
Line <27>NOOP tab
|
||||
Line <27>NOOP name hi
|
||||
Line <27>NOOP equal
|
||||
Line <27>NOOP cbracketo
|
||||
Line <27>NOOP number 1
|
||||
Line <27>NOOP seperator
|
||||
Line <27>NOOP number 2
|
||||
Line <27>NOOP seperator
|
||||
Line <27>NOOP number 3
|
||||
Line <27>NOOP cbracketc
|
||||
Line <27>NOOP newline
|
||||
Line <28>NOOP tab
|
||||
Line <28>NOOP name hi
|
||||
Line <28>NOOP equal
|
||||
Line <28>NOOP cbracketo
|
||||
Line <28>NOOP number 1
|
||||
Line <28>NOOP seperator
|
||||
Line <28>NOOP number 2
|
||||
Line <28>NOOP seperator
|
||||
Line <28>NOOP number 3
|
||||
Line <28>NOOP cbracketc
|
||||
Line <28>NOOP newline
|
||||
Line <29>NOOP tab
|
||||
Line <29>NOOP name list
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP name test
|
||||
Line <29>NOOP equal
|
||||
Line <29>NOOP cbracketo
|
||||
Line <29>NOOP cbracketo
|
||||
Line <29>NOOP number 1
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP number 2
|
||||
Line <29>NOOP plus
|
||||
Line <29>NOOP name food
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP name hi
|
||||
Line <29>NOOP bracketo
|
||||
Line <29>NOOP number 3
|
||||
Line <29>NOOP bracketc
|
||||
Line <29>NOOP cbracketc
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP name true
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP name tester
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP number 123
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP string This is a string!
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP name false
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP cbracketo
|
||||
Line <29>NOOP number 3
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP number 2
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP number 1
|
||||
Line <29>NOOP cbracketc
|
||||
Line <29>NOOP cbracketc
|
||||
Line <29>NOOP seperator
|
||||
Line <29>NOOP number 5
|
||||
Line <29>NOOP newline
|
||||
Line <30>NOOP tab
|
||||
Line <30>NOOP name a
|
||||
Line <30>NOOP equal
|
||||
Line <30>NOOP name list
|
||||
Line <30>NOOP bracketo
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP name test
|
||||
Line <30>NOOP equal
|
||||
Line <30>NOOP cbracketo
|
||||
Line <30>NOOP cbracketo
|
||||
Line <30>NOOP number 1
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP number 2
|
||||
Line <30>NOOP plus
|
||||
Line <30>NOOP name food
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP name hi
|
||||
Line <30>NOOP bracketo
|
||||
Line <30>NOOP number 3
|
||||
Line <30>NOOP bracketc
|
||||
Line <30>NOOP cbracketc
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP name true
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP name tester
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP number 123
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP string This is a string!
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP name false
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP cbracketo
|
||||
Line <30>NOOP number 3
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP number 2
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP number 1
|
||||
Line <30>NOOP cbracketc
|
||||
Line <30>NOOP cbracketc
|
||||
Line <30>NOOP seperator
|
||||
Line <30>NOOP number 5
|
||||
Line <30>NOOP newline
|
||||
Line <31>NOOP tab
|
||||
Line <31>NOOP name a
|
||||
Line <31>NOOP equal
|
||||
Line <31>NOOP name list
|
||||
Line <31>NOOP bracketo
|
||||
Line <31>NOOP number 1
|
||||
Line <31>NOOP bracketc
|
||||
Line <31>NOOP newline
|
||||
Line <32>NOOP tab
|
||||
Line <32>NOOP name hungry
|
||||
Line <32>NOOP equal
|
||||
Line <32>NOOP parao
|
||||
Line <32>NOOP minus
|
||||
Line <32>NOOP number 2
|
||||
Line <32>NOOP plus
|
||||
Line <32>NOOP number 4
|
||||
Line <32>NOOP minus
|
||||
Line <32>NOOP parao
|
||||
Line <32>NOOP parao
|
||||
Line <32>NOOP number 5
|
||||
Line <32>NOOP multiply
|
||||
Line <32>NOOP number 5
|
||||
Line <32>NOOP parac
|
||||
Line <32>NOOP divide
|
||||
Line <32>NOOP name sqrt
|
||||
Line <32>NOOP parao
|
||||
Line <32>NOOP number 144
|
||||
Line <32>NOOP plus
|
||||
Line <32>NOOP number 5
|
||||
Line <32>NOOP parac
|
||||
Line <32>NOOP parac
|
||||
Line <32>NOOP parac
|
||||
Line <32>NOOP pow
|
||||
Line <32>NOOP number 2
|
||||
Line <32>NOOP multiply
|
||||
Line <32>NOOP number 2
|
||||
Line <32>NOOP plus
|
||||
Line <32>NOOP number 2
|
||||
Line <32>NOOP newline
|
||||
Line <33>NOOP tab
|
||||
Line <33>NOOP name list
|
||||
Line <33>NOOP bracketo
|
||||
Line <33>NOOP number 1
|
||||
Line <33>NOOP bracketc
|
||||
Line <33>NOOP name hungry
|
||||
Line <33>NOOP equal
|
||||
Line <33>NOOP string Hello
|
||||
Line <33>NOOP parao
|
||||
Line <33>NOOP minus
|
||||
Line <33>NOOP number 2
|
||||
Line <33>NOOP plus
|
||||
Line <33>NOOP number 4
|
||||
Line <33>NOOP minus
|
||||
Line <33>NOOP parao
|
||||
Line <33>NOOP parao
|
||||
Line <33>NOOP number 5
|
||||
Line <33>NOOP multiply
|
||||
Line <33>NOOP number 5
|
||||
Line <33>NOOP parac
|
||||
Line <33>NOOP divide
|
||||
Line <33>NOOP name sqrt
|
||||
Line <33>NOOP parao
|
||||
Line <33>NOOP number 144
|
||||
Line <33>NOOP plus
|
||||
Line <33>NOOP number 5
|
||||
Line <33>NOOP parac
|
||||
Line <33>NOOP parac
|
||||
Line <33>NOOP parac
|
||||
Line <33>NOOP pow
|
||||
Line <33>NOOP number 2
|
||||
Line <33>NOOP multiply
|
||||
Line <33>NOOP number 2
|
||||
Line <33>NOOP plus
|
||||
Line <33>NOOP number 2
|
||||
Line <33>NOOP newline
|
||||
Line <34>NOOP tab
|
||||
Line <34>NOOP number var1
|
||||
Line <34>NOOP seperator
|
||||
Line <34>NOOP name var2
|
||||
Line <34>NOOP number
|
||||
Line <34>NOOP equal
|
||||
Line <34>NOOP name func
|
||||
Line <34>NOOP parao
|
||||
Line <34>NOOP name list
|
||||
Line <34>NOOP bracketo
|
||||
Line <34>NOOP number 1
|
||||
Line <34>NOOP seperator
|
||||
Line <34>NOOP string string
|
||||
Line <34>NOOP seperator
|
||||
Line <34>NOOP number 2
|
||||
Line <34>NOOP plus
|
||||
Line <34>NOOP number 5
|
||||
Line <34>NOOP parac
|
||||
Line <34>NOOP bracketc
|
||||
Line <34>NOOP equal
|
||||
Line <34>NOOP string Hello
|
||||
Line <34>NOOP newline
|
||||
Line <35>NOOP tab
|
||||
Line <35>NOOP name a
|
||||
Line <35>NOOP equal
|
||||
Line <35>NOOP name 100
|
||||
Line <35>NOOP number var1
|
||||
Line <35>NOOP seperator
|
||||
Line <35>NOOP name var2
|
||||
Line <35>NOOP number
|
||||
Line <35>NOOP plus
|
||||
Line <35>NOOP equal
|
||||
Line <35>NOOP name func
|
||||
Line <35>NOOP parao
|
||||
Line <35>NOOP number 1
|
||||
@ -202,10 +216,13 @@ Line <35>NOOP number 2
|
||||
Line <35>NOOP plus
|
||||
Line <35>NOOP number 5
|
||||
Line <35>NOOP parac
|
||||
Line <35>NOOP plus
|
||||
Line <35>NOOP number 100
|
||||
Line <35>NOOP newline
|
||||
Line <36>NOOP tab
|
||||
Line <36>NOOP name a
|
||||
Line <36>NOOP equal
|
||||
Line <36>NOOP name 100
|
||||
Line <36>NOOP number
|
||||
Line <36>NOOP plus
|
||||
Line <36>NOOP name func
|
||||
Line <36>NOOP parao
|
||||
Line <36>NOOP number 1
|
||||
@ -216,11 +233,25 @@ Line <36>NOOP number 2
|
||||
Line <36>NOOP plus
|
||||
Line <36>NOOP number 5
|
||||
Line <36>NOOP parac
|
||||
Line <36>NOOP plus
|
||||
Line <36>NOOP number 100
|
||||
Line <36>NOOP newline
|
||||
Line <37>NOOP tab
|
||||
Line <37>NOOP label label
|
||||
Line <37>NOOP name func
|
||||
Line <37>NOOP parao
|
||||
Line <37>NOOP number 1
|
||||
Line <37>NOOP seperator
|
||||
Line <37>NOOP string string
|
||||
Line <37>NOOP seperator
|
||||
Line <37>NOOP number 2
|
||||
Line <37>NOOP plus
|
||||
Line <37>NOOP number 5
|
||||
Line <37>NOOP parac
|
||||
Line <37>NOOP newline
|
||||
Line <38>NOOP tab
|
||||
Line <38>NOOP label label
|
||||
Line <38>NOOP newline
|
||||
Line <39>NOOP tab
|
||||
Line <39>NOOP newline
|
||||
Line <40>NOOP tab
|
||||
Line <40>NOOP newline
|
||||
|
||||
@ -7,7 +7,8 @@ namespace dms::errors {
|
||||
invalid_arguments,
|
||||
invalie_type,
|
||||
array_out_of_bounds,
|
||||
badtoken
|
||||
badtoken,
|
||||
block_already_defined
|
||||
};
|
||||
struct error {
|
||||
errortype code=unknown;
|
||||
|
||||
@ -5,10 +5,14 @@ enable warnings
|
||||
version 1.2
|
||||
using extendedDefine
|
||||
|
||||
[Ryan:char]{
|
||||
[Ryan:char]
|
||||
name = "Ryan"
|
||||
age = 21
|
||||
}
|
||||
|
||||
[step:function(a,b,c)]
|
||||
"Testing..."
|
||||
d = (100 + b) / c nil
|
||||
return d
|
||||
|
||||
[main]
|
||||
"This works!"
|
||||
|
||||
@ -35,7 +35,9 @@ namespace dms::tokens {
|
||||
label,
|
||||
newline,
|
||||
tab,
|
||||
eof
|
||||
eof,
|
||||
ret,
|
||||
nil
|
||||
};//stream, t_vec, line, isNum, buffer
|
||||
struct token {
|
||||
tokentype type = noop;
|
||||
@ -89,7 +91,9 @@ namespace dms::tokens {
|
||||
"label",
|
||||
"newline",
|
||||
"tab",
|
||||
"eof"
|
||||
"eof",
|
||||
"ret",
|
||||
"nil"
|
||||
};
|
||||
out << "Line <" << c.line_num << ">" << codes::list[c.raw] << " " << temp1[c.type] << " \t\t " << c.name;
|
||||
return out;
|
||||
|
||||
@ -5,6 +5,9 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
namespace dms {
|
||||
void dms_args::push(value val) {
|
||||
args.push_back(val);
|
||||
}
|
||||
dms_string* buildString(std::string str) {
|
||||
size_t len = str.length();
|
||||
uint8_t* arr = new uint8_t[len];
|
||||
@ -22,7 +25,7 @@ namespace dms {
|
||||
dms_number* dms_num = new dms_number{ num };
|
||||
return dms_num;
|
||||
}
|
||||
std::string value::toString() {
|
||||
std::string value::toString() const {
|
||||
std::stringstream temp;
|
||||
temp << this;
|
||||
return temp.str();
|
||||
@ -47,6 +50,18 @@ namespace dms {
|
||||
val->set(buildBool(b));
|
||||
return val;
|
||||
}
|
||||
void value::nuke() {
|
||||
delete[] s;
|
||||
delete[] b;
|
||||
delete[] n;
|
||||
delete[] e;
|
||||
delete[] c;
|
||||
s = nullptr;
|
||||
b = nullptr;
|
||||
n = nullptr;
|
||||
e = nullptr;
|
||||
c = nullptr;
|
||||
}
|
||||
bool value::typeMatch(const value o) const {
|
||||
return type == o.type;
|
||||
}
|
||||
|
||||
18
DMS/value.h
18
DMS/value.h
@ -6,7 +6,7 @@
|
||||
|
||||
namespace dms {
|
||||
struct dms_env;
|
||||
enum datatypes { nil, number, boolean, env, string, custom };
|
||||
enum datatypes { nil, number, boolean, env, string, custom, variable };
|
||||
struct dms_number {
|
||||
double val;
|
||||
double getValue() { return val; }
|
||||
@ -47,13 +47,14 @@ namespace dms {
|
||||
dms_string* s = nullptr;
|
||||
dms_env* e = nullptr;
|
||||
dms_custom* c = nullptr;
|
||||
void nuke();
|
||||
void set(dms_string* str);
|
||||
void set(dms_boolean* bo);
|
||||
void set(dms_number* num);
|
||||
void set(dms_env* en);
|
||||
void set();
|
||||
bool typeMatch(const value o) const;
|
||||
std::string toString();
|
||||
std::string toString() const;
|
||||
friend bool operator<(const value& l, const value& r)
|
||||
{
|
||||
if (l.typeMatch(r)) {
|
||||
@ -84,6 +85,9 @@ namespace dms {
|
||||
else if (c.type == custom) {
|
||||
out << "Custom Data: " << c;
|
||||
}
|
||||
else if (c.type == variable) {
|
||||
out << c.s->getValue(); // Do the lookup
|
||||
}
|
||||
return out;
|
||||
};
|
||||
};
|
||||
@ -94,6 +98,16 @@ namespace dms {
|
||||
|
||||
struct dms_args {
|
||||
std::vector<value> args;
|
||||
void push(value val);
|
||||
friend std::ostream& operator << (std::ostream& out, const dms_args& c) {
|
||||
for (size_t i=0; i < c.args.size(); i++) {
|
||||
if(i==c.args.size()-1)
|
||||
out << c.args[i];
|
||||
else
|
||||
out << c.args[i] << ", ";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
struct dms_env
|
||||
{
|
||||
|
||||
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