Started matching the tokens

This commit is contained in:
Ryan Wardm 2020-08-09 23:10:17 -04:00
parent 8b850e0eae
commit 04eb7ba944
33 changed files with 530 additions and 369 deletions

View File

@ -2,21 +2,24 @@
// //
#include <iostream> #include <iostream>
#include <string> //#include <string>
#include <exception> //#include <exception>
#include "value.h"
#include "codes.h"
#include "cmd.h"
#include "dms_exceptions.h"
#include "errors.h"
#include "utils.h"
#include "number_utils.h"
#include "string_utils.h"
#include "LineParser.h"
#include "dms.h" #include "dms.h"
#include "chunk.h"
#include "token.h"
using namespace dms; using namespace dms;
using namespace dms::utils; using namespace dms::utils;
int main() int main()
{ {
/*
TODO
Work on LineParser, chunk and state
We need to parse the dms file.
Might need to rework the syntax a bit
*/
LineParser parser = LineParser("test.dms"); LineParser parser = LineParser("test.dms");
parser.Parse(); parser.Parse();
print("Goodbye!"); print("Goodbye!");

View File

@ -103,6 +103,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,25 @@
using namespace dms::tokens; using namespace dms::tokens;
using namespace dms::utils; using namespace dms::utils;
namespace dms { namespace dms {
void tokenstream::init(std::vector<token>* ptr) {
this->tokens = *ptr;
}
token tokenstream::next() {
if (pos > this->tokens.size())
return token{ tokentype::noop,codes::NOOP,"EOF",0 };
return this->tokens[pos++];
}
token tokenstream::peek() {
return this->tokens[pos];
}
std::vector<token> tokenstream::next(tokens::tokentype tk, size_t n) {
std::vector<token> temp;
while (peek().type!=tk) {
temp.push_back(next());
}
temp.push_back(next());
return temp;
}
uint8_t passer::next() { uint8_t passer::next() {
if (stream.size() == pos) { if (stream.size() == pos) {
return NULL; return NULL;
@ -57,14 +76,102 @@ namespace dms {
} }
} }
} }
cmd* LineParser::getPattern(std::vector<tokens::token> &tok) { void wait() {
cmd* c = new cmd(); std::cin.ignore();
return c;
} }
std::vector<chunk> LineParser::tokenizer(std::vector<token> &tok) { bool LineParser::match(tokenstream stream, tokens::tokentype t1, tokens::tokentype t2, tokens::tokentype t3, tokens::tokentype t4, tokens::tokentype t5, tokens::tokentype t6, tokens::tokentype t7, tokens::tokentype t8, tokens::tokentype t9, tokens::tokentype t10, tokens::tokentype t11, tokens::tokentype t12) {
std::vector<chunk> chunks; tokens::tokentype types[12] = { t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12 };
// turn token data into for (size_t i = 0; i < 12; i++) {
if (types[i] == tokens::none)
return true;
if (stream.tokens[stream.pos+i].type != types[i])
return false;
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;
chunk* current_chunk = nullptr;
std::string chunk_name;
blocktype chunk_type;
tokenstream stream;
stream.init(&toks);
token current = stream.next();
std::vector<token> temp;
while (stream.peek().type != tokens::eof) {
print(current);
if (current.type == tokens::flag) {
temp = stream.next(tokens::newline);
if (temp.size() != 2) {
std::cout << "";
}
codes::op code = current.raw;
tokens::tokentype tok = temp[0].type;
if (code == codes::ENAB && tok == tokens::name) {
state->enables.insert_or_assign(temp[0].name,true);
}
else if (code == codes::ENTR && tok == tokens::name) {
state->entry = temp[0].name;
}
else if (code == codes::DISA && tok == tokens::name) {
state->enables.insert_or_assign(temp[0].name, false);
}
else if (code == codes::VERN && tok == tokens::number) {
state->version = std::stod(temp[0].name);
}
else if (code == codes::USIN && tok == tokens::name) {
// TODO add usings, kinda useless since everything will be packed in. Perhaps extensions might work
}
else if (code == codes::LOAD && tok == tokens::string) {
Parse(state, temp[0].name); // Load another file
}
else {
std::stringstream str;
str << "Expected <FLAG IDENTIFIER> " << " got: " << current << " ";
state->push_error(errors::error{errors::badtoken,str.str(),true,current.line_num});
}
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);
current_chunk = new chunk;
stream.next(); // Consume
current_chunk->name = stream.next().name;
stream.next(); // Consume
}
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);
current_chunk = new chunk;
current_chunk->name = stream.next().name;
stream.next();
std::string temp = stream.next().name;
if (temp == "char") {
current_chunk->type = bt_character;
}
else if (temp == "env") {
current_chunk->type = bt_env;
}
else if (temp == "menu") {
current_chunk->type = bt_menu;
}
stream.next();
}
wait();
current = stream.next();
}
return chunks; return chunks;
} }
void LineParser::tolower(std::string &s1) { void LineParser::tolower(std::string &s1) {
@ -229,7 +336,7 @@ namespace dms {
} }
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::bracket,codes::NOOP,"",line }); t_vec.push_back(token{ tokens::colon,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);
@ -241,79 +348,78 @@ namespace dms {
} }
if (data == ' ' && !isStr) { // tokens end with a space if (data == ' ' && !isStr) { // tokens end with a space
token tok;
std::string str = stream.processBuffer(buffer); std::string str = stream.processBuffer(buffer);
tolower(str); tolower(str);
buffer.clear(); buffer.clear();
if (str == "enable") { if (str == "enable") {
tok.build(tokens::flag, codes::ENAB); t_vec.push_back(token{ tokens::flag,codes::ENAB,"",line });
} else if (str == "entry") { } else if (str == "entry") {
tok.build(tokens::flag, codes::ENTR); t_vec.push_back(token{ tokens::flag,codes::ENTR,"",line });
} }
else if (str == "loadfile") { else if (str == "loadfile") {
tok.build(tokens::flag, codes::LOAD); t_vec.push_back(token{ tokens::flag,codes::LOAD,"",line });
} }
else if (str == "version") { else if (str == "version") {
tok.build(tokens::flag,codes::VERN); t_vec.push_back(token{ tokens::flag,codes::VERN,"",line });
} }
else if (str == "using") { else if (str == "using") {
tok.build(tokens::flag, codes::USIN); t_vec.push_back(token{ tokens::flag,codes::USIN,"",line });
}
else if (str == "disable") {
t_vec.push_back(token{ tokens::flag,codes::DISA,"",line });
} }
else if (str == "if") { else if (str == "if") {
tok.build(tokens::control, codes::IFFF); t_vec.push_back(token{ tokens::control,codes::IFFF,"",line });
} }
else if (str == "elseif") { else if (str == "elseif") {
tok.build(tokens::control, codes::ELIF); t_vec.push_back(token{ tokens::control,codes::ELIF,"",line });
} }
else if (str == "while") { else if (str == "while") {
tok.build(tokens::control, codes::WHLE); t_vec.push_back(token{ tokens::control,codes::WHLE,"",line });
} }
else if (str == "true") { else if (str == "true") {
tok.build(tokens::True, codes::NOOP); t_vec.push_back(token{ tokens::True,codes::NOOP,"",line });
} }
else if (str == "False") { else if (str == "False") {
tok.build(tokens::False, codes::NOOP); t_vec.push_back(token{ tokens::False,codes::NOOP,"",line });
} }
else if (str == "else") { else if (str == "else") {
tok.build(tokens::control, codes::ELSE); t_vec.push_back(token{ tokens::control,codes::ELSE,"",line });
} }
else if (str == "and") { else if (str == "and") {
tok.build(tokens::And, codes::NOOP); t_vec.push_back(token{ tokens::And,codes::NOOP,"",line });
} }
else if (str == "or") { else if (str == "or") {
tok.build(tokens::Or, codes::NOOP); t_vec.push_back(token{ tokens::Or,codes::NOOP,"",line });
} }
else if (str == "for") { else if (str == "for") {
tok.build(tokens::For, codes::NOOP); t_vec.push_back(token{ tokens::For,codes::NOOP,"",line });
} }
else if (str == "choice") { else if (str == "choice") {
tok.build(tokens::control, codes::CHOI); t_vec.push_back(token{ tokens::control,codes::CHOI,"",line });
} }
else if (utils::isalphanum(str) && str.size()>0) { else if (utils::isalphanum(str) && str.size()>0) {
tok.build(tokens::name, str); t_vec.push_back(token{ tokens::name,codes::NOOP,str,line });
} }
else { else {
// Unknown command! // Unknown command!
tok.build(tokens::noop, codes::UNWN); /*tok.build(tokens::noop, codes::UNWN);
tok.name = str; tok.name = str;
tok.line_num = line; tok.line_num = line;*/
std::cout << tok;
}
if (tok.raw!=codes::UNWN && tok.type != tokens::noop) {
tok.line_num = line;
t_vec.push_back(tok);
} }
} }
data = stream.next(); data = stream.next();
} }
t_vec.push_back(token{ tokens::eof,codes::NOOP,"",line+1 });
std::ofstream outputFile("dump.txt"); std::ofstream outputFile("dump.txt");
outputFile << "Token Dump:" << std::endl; outputFile << "Token Dump:" << std::endl;
for (size_t i = 0; i < t_vec.size(); i++) { for (size_t i = 0; i < t_vec.size(); i++) {
outputFile << t_vec[i] << std::endl; outputFile << t_vec[i] << std::endl;
} }
outputFile.close(); outputFile.close();
print("Running tokenizer");
// Tokens build let's parse // Tokens build let's parse
tokenizer(t_vec); tokenizer(state, t_vec);
return state; return state;
} }
} }

View File

@ -4,8 +4,8 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include<stdio.h> #include <stdio.h>
#include<ctype.h> #include <ctype.h>
#include "codes.h" #include "codes.h"
#include "cmd.h" #include "cmd.h"
#include "dms_state.h" #include "dms_state.h"
@ -13,7 +13,16 @@
#include "token.h" #include "token.h"
#include "utils.h" #include "utils.h"
namespace dms { namespace dms {
struct tokenstream {
std::vector<tokens::token> tokens;
size_t pos = 0;
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);
};
struct passer { struct passer {
std::string stream; std::string stream;
uint8_t next(); uint8_t next();
@ -33,8 +42,9 @@ namespace dms {
dms_state* Parse(dms_state* state, std::string l); dms_state* Parse(dms_state* state, std::string l);
LineParser(std::string fn); LineParser(std::string fn);
LineParser(); LineParser();
//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); void tolower(std::string &str);
std::vector<chunk> tokenizer(std::vector<tokens::token> &tok); std::map<std::string, chunk> tokenizer(dms_state* state, std::vector<tokens::token> &tok);
cmd* getPattern(std::vector<tokens::token>& tok);
}; };
} }

View File

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

View File

@ -12,8 +12,10 @@ namespace dms {
struct chunk struct chunk
{ {
blocktype type = bt_block; blocktype type = bt_block;
std::string name = "";
std::vector<cmd> cmds = std::vector<cmd>(); std::vector<cmd> cmds = std::vector<cmd>();
size_t pos = 0; size_t pos = 0;
void addCmd(cmd c);
}; };
} }

View File

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

View File

@ -6,467 +6,486 @@ Line <2>ENAB flag
Line <2>NOOP name warnings Line <2>NOOP name warnings
Line <2>NOOP newline Line <2>NOOP newline
Line <4>NOOP newline Line <4>NOOP newline
Line <5>LOAD flag
Line <5>NOOP string loadtest.dms
Line <5>NOOP newline
Line <6>VERN flag
Line <6>NOOP number 1.2
Line <6>NOOP newline Line <6>NOOP newline
Line <7>USIN flag Line <7>VERN flag
Line <7>NOOP name extendedDefine Line <7>NOOP number 1.2
Line <7>NOOP newline Line <7>NOOP newline
Line <8>USIN flag
Line <8>NOOP name extendedDefine
Line <8>NOOP newline Line <8>NOOP newline
Line <9>NOOP bracketo
Line <9>NOOP name main
Line <9>NOOP bracketc
Line <9>NOOP newline Line <9>NOOP newline
Line <10>NOOP tab Line <10>NOOP bracketo
Line <10>NOOP string This works! 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 newline Line <10>NOOP newline
Line <11>NOOP tab Line <11>NOOP tab
Line <11>NOOP string What's up Line <11>NOOP name name
Line <11>NOOP equal
Line <11>NOOP string Ryan
Line <11>NOOP newline 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 newline Line <12>NOOP newline
Line <13>NOOP tab Line <13>NOOP cbracketc
Line <13>NOOP name ryan Line <13>NOOP newline
Line <13>NOOP string Hello "how" are you doing?
Line <14>NOOP newline Line <14>NOOP newline
Line <15>NOOP tab Line <15>NOOP bracketo
Line <15>NOOP name bob Line <15>NOOP name main
Line <15>NOOP string I'm good you? Line <15>NOOP bracketc
Line <15>NOOP newline Line <15>NOOP newline
Line <16>NOOP tab Line <16>NOOP tab
Line <16>NOOP string This works!
Line <16>NOOP newline Line <16>NOOP newline
Line <17>NOOP tab Line <17>NOOP tab
Line <17>NOOP name tester Line <17>NOOP string What's up
Line <17>NOOP equal
Line <17>NOOP string Hello
Line <17>NOOP newline Line <17>NOOP newline
Line <18>NOOP tab
Line <18>NOOP newline Line <18>NOOP newline
Line <19>NOOP tab Line <19>NOOP tab
Line <19>NOOP name food Line <19>NOOP name ryan
Line <19>NOOP equal Line <19>NOOP string Hello "how" are you doing?
Line <19>NOOP number 3
Line <19>NOOP newline
Line <20>NOOP tab
Line <20>NOOP newline Line <20>NOOP newline
Line <21>NOOP tab Line <21>NOOP tab
Line <21>NOOP name hi Line <21>NOOP name bob
Line <21>NOOP equal Line <21>NOOP string I'm good you?
Line <21>NOOP cbracketo
Line <21>NOOP number 1
Line <21>NOOP seperator
Line <21>NOOP number 2
Line <21>NOOP seperator
Line <21>NOOP number 3
Line <21>NOOP cbracketc
Line <21>NOOP newline Line <21>NOOP newline
Line <22>NOOP tab
Line <22>NOOP newline Line <22>NOOP newline
Line <23>NOOP tab Line <23>NOOP tab
Line <23>NOOP name list
Line <23>NOOP seperator
Line <23>NOOP name test
Line <23>NOOP equal
Line <23>NOOP cbracketo
Line <23>NOOP cbracketo
Line <23>NOOP number 1
Line <23>NOOP seperator
Line <23>NOOP number 2
Line <23>NOOP plus
Line <23>NOOP name food
Line <23>NOOP seperator
Line <23>NOOP name hi
Line <23>NOOP bracketo
Line <23>NOOP number 3
Line <23>NOOP bracketc
Line <23>NOOP cbracketc
Line <23>NOOP seperator
Line <23>NOOP name true
Line <23>NOOP seperator
Line <23>NOOP name tester Line <23>NOOP name tester
Line <23>NOOP seperator Line <23>NOOP equal
Line <23>NOOP number 123 Line <23>NOOP string Hello
Line <23>NOOP seperator
Line <23>NOOP string This is a string!
Line <23>NOOP seperator
Line <23>NOOP name false
Line <23>NOOP seperator
Line <23>NOOP cbracketo
Line <23>NOOP number 3
Line <23>NOOP seperator
Line <23>NOOP number 2
Line <23>NOOP seperator
Line <23>NOOP number 1
Line <23>NOOP cbracketc
Line <23>NOOP cbracketc
Line <23>NOOP seperator
Line <23>NOOP number 5
Line <23>NOOP newline Line <23>NOOP newline
Line <24>NOOP tab Line <24>NOOP tab
Line <24>NOOP name a
Line <24>NOOP equal
Line <24>NOOP name list
Line <24>NOOP bracketo
Line <24>NOOP number 1
Line <24>NOOP bracketc
Line <24>NOOP newline 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 <25>NOOP newline
Line <26>NOOP tab Line <26>NOOP tab
Line <26>NOOP name hungry
Line <26>NOOP equal
Line <26>NOOP parao
Line <26>NOOP minus
Line <26>NOOP number 2
Line <26>NOOP plus
Line <26>NOOP number 4
Line <26>NOOP minus
Line <26>NOOP parao
Line <26>NOOP parao
Line <26>NOOP number 5
Line <26>NOOP multiply
Line <26>NOOP number 5
Line <26>NOOP parac
Line <26>NOOP divide
Line <26>NOOP name sqrt
Line <26>NOOP parao
Line <26>NOOP number 144
Line <26>NOOP plus
Line <26>NOOP number 5
Line <26>NOOP parac
Line <26>NOOP parac
Line <26>NOOP parac
Line <26>NOOP pow
Line <26>NOOP number 2
Line <26>NOOP multiply
Line <26>NOOP number 2
Line <26>NOOP plus
Line <26>NOOP number 2
Line <26>NOOP newline Line <26>NOOP newline
Line <27>NOOP tab Line <27>NOOP tab
Line <27>NOOP name list Line <27>NOOP name hi
Line <27>NOOP bracketo
Line <27>NOOP number 1
Line <27>NOOP bracketc
Line <27>NOOP equal Line <27>NOOP equal
Line <27>NOOP string Hello 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 <27>NOOP newline
Line <28>NOOP tab
Line <28>NOOP number var1
Line <28>NOOP seperator
Line <28>NOOP name var2
Line <28>NOOP number
Line <28>NOOP equal
Line <28>NOOP name func
Line <28>NOOP parao
Line <28>NOOP number 1
Line <28>NOOP seperator
Line <28>NOOP string string
Line <28>NOOP seperator
Line <28>NOOP number 2
Line <28>NOOP plus
Line <28>NOOP number 5
Line <28>NOOP parac
Line <28>NOOP newline Line <28>NOOP newline
Line <29>NOOP tab Line <29>NOOP tab
Line <29>NOOP name a Line <29>NOOP name list
Line <29>NOOP equal
Line <29>NOOP name 100
Line <29>NOOP number
Line <29>NOOP plus
Line <29>NOOP name func
Line <29>NOOP parao
Line <29>NOOP number 1
Line <29>NOOP seperator Line <29>NOOP seperator
Line <29>NOOP string string 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 seperator
Line <29>NOOP number 2 Line <29>NOOP number 2
Line <29>NOOP plus 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 number 5
Line <29>NOOP parac
Line <29>NOOP plus
Line <29>NOOP number 100
Line <29>NOOP newline Line <29>NOOP newline
Line <30>NOOP tab Line <30>NOOP tab
Line <30>NOOP name func Line <30>NOOP name a
Line <30>NOOP parao Line <30>NOOP equal
Line <30>NOOP name list
Line <30>NOOP bracketo
Line <30>NOOP number 1 Line <30>NOOP number 1
Line <30>NOOP seperator Line <30>NOOP bracketc
Line <30>NOOP string string
Line <30>NOOP seperator
Line <30>NOOP number 2
Line <30>NOOP plus
Line <30>NOOP number 5
Line <30>NOOP parac
Line <30>NOOP newline Line <30>NOOP newline
Line <31>NOOP tab
Line <31>NOOP label label
Line <31>NOOP newline Line <31>NOOP newline
Line <32>NOOP tab 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 equal
Line <33>NOOP string Hello
Line <33>NOOP newline Line <33>NOOP newline
Line <34>NOOP tab 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 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 newline Line <34>NOOP newline
Line <35>NOOP tab Line <35>NOOP tab
Line <35>CHOI control Line <35>NOOP name a
Line <35>NOOP string Pick one: Line <35>NOOP equal
Line <35>NOOP name 100
Line <35>NOOP number
Line <35>NOOP plus
Line <35>NOOP name func
Line <35>NOOP parao
Line <35>NOOP number 1
Line <35>NOOP seperator
Line <35>NOOP string string
Line <35>NOOP seperator
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 <35>NOOP newline
Line <36>NOOP tab Line <36>NOOP tab
Line <36>NOOP tab
Line <36>NOOP string first
Line <36>NOOP name func Line <36>NOOP name func
Line <36>NOOP parao Line <36>NOOP parao
Line <36>NOOP number 1
Line <36>NOOP seperator
Line <36>NOOP string string
Line <36>NOOP seperator
Line <36>NOOP number 2
Line <36>NOOP plus
Line <36>NOOP number 5
Line <36>NOOP parac Line <36>NOOP parac
Line <36>NOOP newline Line <36>NOOP newline
Line <37>NOOP tab Line <37>NOOP tab
Line <37>NOOP tab Line <37>NOOP label label
Line <37>NOOP string second
Line <37>NOOP name func
Line <37>NOOP parao
Line <37>NOOP parac
Line <37>NOOP newline Line <37>NOOP newline
Line <38>NOOP tab Line <38>NOOP tab
Line <38>NOOP tab
Line <38>NOOP string third
Line <38>NOOP name func
Line <38>NOOP parao
Line <38>NOOP parac
Line <38>NOOP newline
Line <39>NOOP tab
Line <39>NOOP tab
Line <39>NOOP string forth
Line <39>NOOP name func
Line <39>NOOP parao
Line <39>NOOP parac
Line <39>NOOP newline Line <39>NOOP newline
Line <40>NOOP tab
Line <40>NOOP newline Line <40>NOOP newline
Line <41>NOOP tab Line <41>NOOP tab
Line <41>NOOP for Line <41>CHOI control
Line <41>NOOP name x Line <41>NOOP string Pick one:
Line <41>NOOP equal
Line <41>NOOP number 1
Line <41>NOOP seperator
Line <41>NOOP number 10
Line <41>NOOP newline Line <41>NOOP newline
Line <42>NOOP tab Line <42>NOOP tab
Line <42>NOOP tab Line <42>NOOP tab
Line <42>NOOP for Line <42>NOOP string first
Line <42>NOOP name y Line <42>NOOP name func
Line <42>NOOP equal Line <42>NOOP parao
Line <42>NOOP number 1 Line <42>NOOP parac
Line <42>NOOP seperator
Line <42>NOOP number 10
Line <42>NOOP seperator
Line <42>NOOP number 1
Line <42>NOOP newline Line <42>NOOP newline
Line <43>NOOP tab Line <43>NOOP tab
Line <43>NOOP tab Line <43>NOOP tab
Line <43>NOOP tab Line <43>NOOP string second
Line <43>NOOP for Line <43>NOOP name func
Line <43>NOOP name z Line <43>NOOP parao
Line <43>NOOP equal Line <43>NOOP parac
Line <43>NOOP number 1
Line <43>NOOP seperator
Line <43>NOOP number 10
Line <43>NOOP newline Line <43>NOOP newline
Line <44>NOOP tab Line <44>NOOP tab
Line <44>NOOP tab Line <44>NOOP tab
Line <44>NOOP tab Line <44>NOOP string third
Line <44>NOOP tab Line <44>NOOP name func
Line <44>NOOP string test Line <44>NOOP parao
Line <44>NOOP parac
Line <44>NOOP newline Line <44>NOOP newline
Line <45>NOOP tab Line <45>NOOP tab
Line <45>NOOP tab Line <45>NOOP tab
Line <45>NOOP tab Line <45>NOOP string forth
Line <45>NOOP tab Line <45>NOOP name func
Line <45>NOOP string $x$ $y$ $z$ Line <45>NOOP parao
Line <45>NOOP parac
Line <45>NOOP newline Line <45>NOOP newline
Line <46>NOOP tab
Line <46>NOOP name test
Line <46>NOOP equal
Line <46>NOOP name true
Line <46>NOOP newline Line <46>NOOP newline
Line <47>NOOP tab Line <47>NOOP tab
Line <47>NOOP name test2 Line <47>NOOP for
Line <47>NOOP number Line <47>NOOP name x
Line <47>NOOP equal Line <47>NOOP equal
Line <47>NOOP name false Line <47>NOOP number 1
Line <47>NOOP seperator
Line <47>NOOP number 10
Line <47>NOOP newline Line <47>NOOP newline
Line <48>NOOP tab Line <48>NOOP tab
Line <48>NOOP tab
Line <48>NOOP for
Line <48>NOOP name y
Line <48>NOOP equal
Line <48>NOOP number 1
Line <48>NOOP seperator
Line <48>NOOP number 10
Line <48>NOOP seperator
Line <48>NOOP number 1
Line <48>NOOP newline Line <48>NOOP newline
Line <49>NOOP tab Line <49>NOOP tab
Line <49>NOOP name count Line <49>NOOP tab
Line <49>NOOP tab
Line <49>NOOP for
Line <49>NOOP name z
Line <49>NOOP equal Line <49>NOOP equal
Line <49>NOOP number 0 Line <49>NOOP number 1
Line <49>NOOP seperator
Line <49>NOOP number 10
Line <49>NOOP newline Line <49>NOOP newline
Line <50>NOOP tab Line <50>NOOP tab
Line <50>NOOP tab
Line <50>NOOP tab
Line <50>NOOP tab
Line <50>NOOP string test
Line <50>NOOP newline Line <50>NOOP newline
Line <51>NOOP tab Line <51>NOOP tab
Line <51>WHLE control Line <51>NOOP tab
Line <51>NOOP name count Line <51>NOOP tab
Line <51>NOOP not Line <51>NOOP tab
Line <51>NOOP equal Line <51>NOOP string $x$ $y$ $z$
Line <51>NOOP number 100
Line <51>NOOP newline Line <51>NOOP newline
Line <52>NOOP tab Line <52>NOOP tab
Line <52>NOOP tab Line <52>NOOP name test
Line <52>NOOP name count Line <52>NOOP equal
Line <52>NOOP plus Line <52>NOOP name true
Line <52>NOOP plus
Line <52>NOOP newline Line <52>NOOP newline
Line <53>NOOP tab Line <53>NOOP tab
Line <53>NOOP tab Line <53>NOOP name test2
Line <53>NOOP string Count = $count$ Line <53>NOOP number
Line <53>NOOP equal
Line <53>NOOP name false
Line <53>NOOP newline Line <53>NOOP newline
Line <54>NOOP tab Line <54>NOOP tab
Line <54>NOOP newline Line <54>NOOP newline
Line <55>NOOP tab Line <55>NOOP tab
Line <55>IFFF control Line <55>NOOP name count
Line <55>NOOP parao
Line <55>NOOP name func
Line <55>NOOP parao
Line <55>NOOP number 123
Line <55>NOOP parac
Line <55>NOOP not
Line <55>NOOP equal Line <55>NOOP equal
Line <55>NOOP name name Line <55>NOOP number 0
Line <55>NOOP bracketo
Line <55>NOOP number 1
Line <55>NOOP bracketc
Line <55>NOOP or
Line <55>NOOP true
Line <55>NOOP equal
Line <55>NOOP equal
Line <55>NOOP string Bob
Line <55>NOOP parac
Line <55>NOOP and
Line <55>NOOP name foodcount
Line <55>NOOP equal
Line <55>NOOP number 10.34
Line <55>NOOP newline Line <55>NOOP newline
Line <56>NOOP tab Line <56>NOOP tab
Line <56>NOOP tab
Line <56>NOOP string test=true or test2=false!
Line <56>NOOP number
Line <56>NOOP newline Line <56>NOOP newline
Line <57>NOOP tab Line <57>NOOP tab
Line <57>NOOP tab Line <57>WHLE control
Line <57>NOOP string help me Line <57>NOOP name count
Line <57>NOOP not
Line <57>NOOP equal
Line <57>NOOP number 100
Line <57>NOOP newline Line <57>NOOP newline
Line <58>NOOP tab Line <58>NOOP tab
Line <58>NOOP tab Line <58>NOOP tab
Line <58>IFFF control Line <58>NOOP name count
Line <58>NOOP name cool Line <58>NOOP plus
Line <58>NOOP equal Line <58>NOOP plus
Line <58>NOOP equal
Line <58>NOOP name true
Line <58>NOOP newline Line <58>NOOP newline
Line <59>NOOP tab Line <59>NOOP tab
Line <59>NOOP tab Line <59>NOOP tab
Line <59>NOOP tab Line <59>NOOP string Count = $count$
Line <59>NOOP string We are here
Line <59>NOOP newline Line <59>NOOP newline
Line <60>NOOP tab Line <60>NOOP tab
Line <60>NOOP tab
Line <60>NOOP tab
Line <60>NOOP string Nested if
Line <60>NOOP newline Line <60>NOOP newline
Line <61>NOOP tab Line <61>NOOP tab
Line <61>NOOP tab Line <61>IFFF control
Line <61>ELIF control Line <61>NOOP parao
Line <61>NOOP name food Line <61>NOOP name func
Line <61>NOOP parao
Line <61>NOOP number 123
Line <61>NOOP parac
Line <61>NOOP not
Line <61>NOOP equal Line <61>NOOP equal
Line <61>NOOP number 21 Line <61>NOOP name name
Line <61>NOOP bracketo
Line <61>NOOP number 1
Line <61>NOOP bracketc
Line <61>NOOP or
Line <61>NOOP true
Line <61>NOOP equal
Line <61>NOOP equal
Line <61>NOOP string Bob
Line <61>NOOP parac
Line <61>NOOP and
Line <61>NOOP name foodcount
Line <61>NOOP equal
Line <61>NOOP number 10.34
Line <61>NOOP newline Line <61>NOOP newline
Line <62>NOOP tab Line <62>NOOP tab
Line <62>NOOP tab Line <62>NOOP tab
Line <62>NOOP tab Line <62>NOOP string test=true or test2=false!
Line <62>NOOP string This is getting weird Line <62>NOOP number
Line <62>NOOP newline Line <62>NOOP newline
Line <63>NOOP tab Line <63>NOOP tab
Line <63>NOOP tab Line <63>NOOP tab
Line <63>NOOP string Hi Line <63>NOOP string help me
Line <63>NOOP newline Line <63>NOOP newline
Line <64>NOOP tab Line <64>NOOP tab
Line <64>ELIF control Line <64>NOOP tab
Line <64>NOOP parao Line <64>IFFF control
Line <64>NOOP number func2 Line <64>NOOP name cool
Line <64>NOOP parao
Line <64>NOOP number 321
Line <64>NOOP parac
Line <64>NOOP not
Line <64>NOOP equal
Line <64>NOOP number name2
Line <64>NOOP bracketo
Line <64>NOOP number 1
Line <64>NOOP bracketc
Line <64>NOOP or
Line <64>NOOP true
Line <64>NOOP equal Line <64>NOOP equal
Line <64>NOOP equal Line <64>NOOP equal
Line <64>NOOP string Bob2 Line <64>NOOP name true
Line <64>NOOP number
Line <64>NOOP parac
Line <64>NOOP and
Line <64>NOOP name foodcount2
Line <64>NOOP number
Line <64>NOOP equal
Line <64>NOOP number 1.78
Line <64>NOOP newline Line <64>NOOP newline
Line <65>NOOP tab Line <65>NOOP tab
Line <65>NOOP tab Line <65>NOOP tab
Line <65>NOOP string This Block Line <65>NOOP tab
Line <65>NOOP string We are here
Line <65>NOOP newline Line <65>NOOP newline
Line <66>NOOP tab Line <66>NOOP tab
Line <66>NOOP name else Line <66>NOOP tab
Line <66>NOOP tab
Line <66>NOOP string Nested if
Line <66>NOOP newline Line <66>NOOP newline
Line <67>NOOP tab Line <67>NOOP tab
Line <67>NOOP tab Line <67>NOOP tab
Line <67>NOOP string That Block Line <67>ELIF control
Line <67>NOOP name food
Line <67>NOOP equal
Line <67>NOOP number 21
Line <67>NOOP newline Line <67>NOOP newline
Line <68>NOOP tab Line <68>NOOP tab
Line <68>NOOP string ah this is why no pop Line <68>NOOP tab
Line <68>NOOP tab
Line <68>NOOP string This is getting weird
Line <68>NOOP newline Line <68>NOOP newline
Line <69>NOOP tab
Line <69>NOOP tab
Line <69>NOOP string Hi
Line <69>NOOP newline Line <69>NOOP newline
Line <70>NOOP tab
Line <70>ELIF control
Line <70>NOOP parao
Line <70>NOOP number func2
Line <70>NOOP parao
Line <70>NOOP number 321
Line <70>NOOP parac
Line <70>NOOP not
Line <70>NOOP equal
Line <70>NOOP number name2
Line <70>NOOP bracketo Line <70>NOOP bracketo
Line <70>NOOP name Ryan Line <70>NOOP number 1
Line <70>NOOP bracket
Line <70>NOOP name char
Line <70>NOOP bracketc Line <70>NOOP bracketc
Line <70>NOOP or
Line <70>NOOP true
Line <70>NOOP equal
Line <70>NOOP equal
Line <70>NOOP string Bob2
Line <70>NOOP number
Line <70>NOOP parac
Line <70>NOOP and
Line <70>NOOP name foodcount2
Line <70>NOOP number
Line <70>NOOP equal
Line <70>NOOP number 1.78
Line <70>NOOP newline Line <70>NOOP newline
Line <71>NOOP tab Line <71>NOOP tab
Line <71>NOOP name age Line <71>NOOP tab
Line <71>NOOP equal Line <71>NOOP string This Block
Line <71>NOOP number 24
Line <71>NOOP newline Line <71>NOOP newline
Line <72>NOOP tab Line <72>NOOP tab
Line <72>NOOP name money Line <72>NOOP name else
Line <72>NOOP equal
Line <72>NOOP number 100
Line <72>NOOP newline Line <72>NOOP newline
Line <73>NOOP tab Line <73>NOOP tab
Line <73>NOOP tab
Line <73>NOOP string That Block
Line <73>NOOP newline Line <73>NOOP newline
Line <74>NOOP bracketo Line <74>NOOP tab
Line <74>NOOP name test Line <74>NOOP string ah this is why no pop
Line <74>NOOP bracket
Line <74>NOOP name env
Line <74>NOOP bracketc
Line <74>NOOP newline Line <74>NOOP newline
Line <75>NOOP tab
Line <75>NOOP string test
Line <75>NOOP newline Line <75>NOOP newline
Line <76>NOOP bracketo
Line <76>NOOP name Ryan
Line <76>NOOP colon
Line <76>NOOP name char
Line <76>NOOP bracketc
Line <76>NOOP newline Line <76>NOOP newline
Line <77>NOOP bracketo Line <77>NOOP tab
Line <77>NOOP name newblock Line <77>NOOP name age
Line <77>NOOP bracket Line <77>NOOP equal
Line <77>NOOP name function Line <77>NOOP number 24
Line <77>NOOP parao
Line <77>NOOP parac
Line <77>NOOP bracketc
Line <77>NOOP newline Line <77>NOOP newline
Line <78>NOOP tab Line <78>NOOP tab
Line <78>NOOP string Test #2 Line <78>NOOP name money
Line <78>NOOP number Line <78>NOOP equal
Line <78>NOOP number 100
Line <78>NOOP newline Line <78>NOOP newline
Line <79>NOOP tab Line <79>NOOP tab
Line <79>NOOP string Does it parse this part properly?
Line <79>NOOP newline Line <79>NOOP newline
Line <80>NOOP bracketo
Line <80>NOOP name test
Line <80>NOOP colon
Line <80>NOOP name env
Line <80>NOOP bracketc
Line <80>NOOP newline
Line <81>NOOP tab
Line <81>NOOP string test
Line <81>NOOP newline
Line <82>NOOP newline
Line <83>NOOP bracketo
Line <83>NOOP name newblock
Line <83>NOOP colon
Line <83>NOOP name function
Line <83>NOOP parao
Line <83>NOOP parac
Line <83>NOOP bracketc
Line <83>NOOP newline
Line <84>NOOP tab
Line <84>NOOP string Test #2
Line <84>NOOP number
Line <84>NOOP newline
Line <85>NOOP tab
Line <85>NOOP string Does it parse this part properly?
Line <85>NOOP newline
Line <87>NOOP eof

View File

@ -7,10 +7,12 @@ namespace dms::errors {
invalid_arguments, invalid_arguments,
invalie_type, invalie_type,
array_out_of_bounds, array_out_of_bounds,
badtoken
}; };
struct error { struct error {
errortype code=unknown; errortype code=unknown;
std::string err_msg; std::string err_msg;
bool crash = true; // Set if you would like the state to exit bool crash = true; // Set if you would like the state to exit
size_t linenum = 0;
}; };
} }

View File

@ -1,10 +1,15 @@
entry main entry main
enable warnings enable warnings
//enable debugging //enable debugging
loadfile "loadtest.dms" //loadfile "loadtest.dms"
version 1.2 version 1.2
using extendedDefine using extendedDefine
[Ryan:char]{
name = "Ryan"
age = 21
}
[main] [main]
"This works!" "This works!"
"What's up" "What's up"

View File

@ -3,6 +3,7 @@
#include "codes.h" #include "codes.h"
namespace dms::tokens { namespace dms::tokens {
enum tokentype { enum tokentype {
none,
noop, noop,
flag, flag,
name, name,
@ -23,7 +24,7 @@ namespace dms::tokens {
pow, pow,
mod, mod,
equal, equal,
bracket, colon,
control, control,
True, True,
False, False,
@ -33,7 +34,8 @@ namespace dms::tokens {
For, For,
label, label,
newline, newline,
tab tab,
eof
};//stream, t_vec, line, isNum, buffer };//stream, t_vec, line, isNum, buffer
struct token { struct token {
tokentype type = noop; tokentype type = noop;
@ -55,6 +57,7 @@ namespace dms::tokens {
} }
friend std::ostream& operator << (std::ostream& out, const token& c) { friend std::ostream& operator << (std::ostream& out, const token& c) {
const std::string temp1[] = { const std::string temp1[] = {
"none",
"noop", "noop",
"flag", "flag",
"name", "name",
@ -75,7 +78,7 @@ namespace dms::tokens {
"pow", "pow",
"mod", "mod",
"equal", "equal",
"bracket", "colon",
"control", "control",
"true", "true",
"false", "false",
@ -85,7 +88,8 @@ namespace dms::tokens {
"for", "for",
"label", "label",
"newline", "newline",
"tab" "tab",
"eof"
}; };
out << "Line <" << c.line_num << ">" << codes::list[c.raw] << " " << temp1[c.type] << " \t\t " << c.name; out << "Line <" << c.line_num << ">" << codes::list[c.raw] << " " << temp1[c.type] << " \t\t " << c.name;
return out; return out;

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
entry main entry main
enable warnings enable warnings
//enable debugging //enable debugging
loadfile "loadtest.dms" //loadfile "loadtest.dms"
version 1.2 version 1.2
using extendedDefine using extendedDefine