diff --git a/DMS/LineParserMatchProcess.cpp b/DMS/LineParserMatchProcess.cpp index fbeff3a..1e871df 100644 --- a/DMS/LineParserMatchProcess.cpp +++ b/DMS/LineParserMatchProcess.cpp @@ -4,7 +4,7 @@ using namespace dms::utils; // TODO: process if elseif else statements, for loops and while loops namespace dms { bool LineParser::match_process_standard(tokenstream* stream, value* v) { - if (match_process_expression(stream,v)) { + if (match_process_expression(stream, v)) { return true; } else if (match_process_function(stream, v)) { @@ -13,6 +13,9 @@ namespace dms { else if (match_process_list(stream, v)) { return true; } + else if (match_process_index(stream, v)) { + return true; + } else if (stream->match(tokens::True)) { v->set(buildBool(true)); stream->next(); @@ -470,50 +473,7 @@ namespace dms { tempstream.next(); // Consume it cleanup(tempval); // We don't need it } - else if (match_process_list(&tempstream, tempval)) { - c->args.push(tempval); - } - else if (match_process_expression(&tempstream, tempval)) { - c->args.push(tempval); - } - else if (tempstream.match(tokens::string)) { - cleanup(tempval); - tempval = buildValue(tempstream.next().name); // Get the string - c->args.push(tempval); // add this argument to the function opcodes - } - else if (tempstream.match(tokens::number)) { - cleanup(tempval); - std::string str = tempstream.next().name; - tempval = buildValue(std::stod(str)); // Get the number and convert it to a double then build a value - c->args.push(tempval); // add this argument to the function opcodes - } - else if (tempstream.match(tokens::True)) { - cleanup(tempval); - tempval = buildValue(true); - c->args.push(tempval); - tempstream.next(); - } - else if (tempstream.match(tokens::False)) { - cleanup(tempval); - tempval = buildValue(false); - c->args.push(tempval); - tempstream.next(); - } else if (tempstream.match(tokens::nil)){ - cleanup(tempval); - tempval = buildValue(); - c->args.push(tempval); - tempstream.next(); - } - // Final match this could be a function it might also be an expression - else if (match_process_function(&tempstream, tempval)) { - if (!nested) { - state->push_error(errors::error{ errors::nested_function,"Nested functions are not allowed in this context!",true, tempstream.peek().line_num }); - } - c->args.push(tempval); - } - else if (tempstream.match(tokens::name)) { - cleanup(tempval); - tempval = buildVariable(tempstream.next().name); + else if (match_process_standard(&tempstream, tempval)) { c->args.push(tempval); } else if (tempstream.match(tokens::newline)) { @@ -549,7 +509,30 @@ namespace dms { } bool LineParser::match_process_index(tokenstream* stream, value* v) { if (stream->match(tokens::name,tokens::bracketo)) { - // Todo implement this + std::string name = stream->next().name; + std::vector tok = stream->next(tokens::bracketo, tokens::bracketc); + tok.pop_back(); // Remove the last element since its a ']' + tok.push_back(token{ tokens::newline,codes::NOOP,"",tok[0].line_num }); + tokenstream tempstream; // As usual the tokens are balanced match to [...] where the contents of tok = ... + tempstream.init(&tok); + value* tempval = buildVariable(); + cmd* c = new cmd; + c->opcode = codes::INDX; + while (tempstream.peek().type != tokens::none) { // Keep going until we hit the end + if (match_process_standard(&tempstream, tempval)) { + c->args.push(v); + c->args.push(buildBlock(name)); + c->args.push(tempval); + } + else if (tempstream.match(tokens::newline)) { + tempstream.next(); + //badSymbol(stream); + //return false; + } + } + + current_chunk->addCmd(c); + return true; } return false; } @@ -617,7 +600,7 @@ namespace dms { stream->store(current_chunk); cmd* lastcmd = nullptr; // It has to start with one of these 3 to even be considered an expression - if (stream->match(tokens::number) || stream->match(tokens::name) || stream->match(tokens::parao)) { + if ((stream->match(tokens::number) || stream->match(tokens::name) || stream->match(tokens::parao)) && stream->tokens.size()>=3) { // What do we know, math expressions can only be on a single line. We know where to stop looking if we have to cmd* c = new cmd; value* wv = nullptr; diff --git a/DMS/LineParserParse.cpp b/DMS/LineParserParse.cpp index 9dda2e5..97d94c0 100644 --- a/DMS/LineParserParse.cpp +++ b/DMS/LineParserParse.cpp @@ -105,6 +105,9 @@ namespace dms { else if (isStr) { buffer.push_back(data); } + else if (data == '_') { // Can't believe I missed that haha + buffer.push_back(data); + } else if (isdigit(data)) { isNum = true; buffer.push_back(data); diff --git a/DMS/LineParserUtils.cpp b/DMS/LineParserUtils.cpp index 82cbc97..e2c8a5f 100644 --- a/DMS/LineParserUtils.cpp +++ b/DMS/LineParserUtils.cpp @@ -9,7 +9,7 @@ namespace dms { return this->tokens[pos-1]; } token tokenstream::next() { - if (pos > this->tokens.size()) + if (pos > this->tokens.size()-1) return token{ tokentype::none,codes::NOOP,"EOS",0 }; return this->tokens[pos++]; } @@ -66,7 +66,7 @@ namespace dms { return tok; } token tokenstream::peek() { - if (pos > this->tokens.size()) + if (pos > this->tokens.size()-1) return token{ tokentype::none,codes::NOOP,"EOS",0 }; return this->tokens[pos]; } diff --git a/DMS/dump.bin b/DMS/dump.bin index 622d965..c9421b3 100644 Binary files a/DMS/dump.bin and b/DMS/dump.bin differ diff --git a/DMS/dump.txt b/DMS/dump.txt index e3df3cc..893c2d4 100644 --- a/DMS/dump.txt +++ b/DMS/dump.txt @@ -67,6 +67,25 @@ Line <19> newline Line <19> newline Line <20> newline Line <20> newline +Line <21> name test +Line <21> equal = +Line <21> name Bob +Line <21> bracketo [ +Line <21> name a_test +Line <21> parao ( +Line <21> cbracketo { +Line <21> number 4 +Line <21> seperator , +Line <21> name hi +Line <21> bracketo [ +Line <21> string testing +Line <21> bracketc ] +Line <21> seperator , +Line <21> number 6 +Line <21> cbracketc } +Line <21> parac ) +Line <21> bracketc ] +Line <21> newline Line <21> newline Line <22> newline Line <22> newline diff --git a/DMS/test.dms b/DMS/test.dms index d436642..05b31f7 100644 --- a/DMS/test.dms +++ b/DMS/test.dms @@ -18,7 +18,7 @@ using extendedDefine "how are `inv:slot2` you doing?" } - //test = Bob[here] + test = Bob[a_test({4,hi["testing"],6})] //Ryan:setNickname(Bob,"Bobby") // Not yet implemeted! diff --git a/DMS/value.cpp b/DMS/value.cpp index 42aef5e..d783b60 100644 --- a/DMS/value.cpp +++ b/DMS/value.cpp @@ -189,7 +189,9 @@ namespace dms { size_t count = 0; value* buildVariable() { count++; - std::string val = "$"+count; + std::stringstream str; + str << "$" << count; + std::string val = str.str(); return buildVariable(val); } value* buildBlock(std::string str) {