Implemted the bytecode for indexing, todo add code to interperter
This commit is contained in:
parent
7134755649
commit
6b349615fa
@ -13,6 +13,9 @@ namespace dms {
|
|||||||
else if (match_process_list(stream, v)) {
|
else if (match_process_list(stream, v)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (match_process_index(stream, v)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else if (stream->match(tokens::True)) {
|
else if (stream->match(tokens::True)) {
|
||||||
v->set(buildBool(true));
|
v->set(buildBool(true));
|
||||||
stream->next();
|
stream->next();
|
||||||
@ -470,50 +473,7 @@ namespace dms {
|
|||||||
tempstream.next(); // Consume it
|
tempstream.next(); // Consume it
|
||||||
cleanup(tempval); // We don't need it
|
cleanup(tempval); // We don't need it
|
||||||
}
|
}
|
||||||
else if (match_process_list(&tempstream, tempval)) {
|
else if (match_process_standard(&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);
|
|
||||||
c->args.push(tempval);
|
c->args.push(tempval);
|
||||||
}
|
}
|
||||||
else if (tempstream.match(tokens::newline)) {
|
else if (tempstream.match(tokens::newline)) {
|
||||||
@ -549,7 +509,30 @@ namespace dms {
|
|||||||
}
|
}
|
||||||
bool LineParser::match_process_index(tokenstream* stream, value* v) {
|
bool LineParser::match_process_index(tokenstream* stream, value* v) {
|
||||||
if (stream->match(tokens::name,tokens::bracketo)) {
|
if (stream->match(tokens::name,tokens::bracketo)) {
|
||||||
// Todo implement this
|
std::string name = stream->next().name;
|
||||||
|
std::vector<token> 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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -617,7 +600,7 @@ namespace dms {
|
|||||||
stream->store(current_chunk);
|
stream->store(current_chunk);
|
||||||
cmd* lastcmd = nullptr;
|
cmd* lastcmd = nullptr;
|
||||||
// It has to start with one of these 3 to even be considered an expression
|
// 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
|
// 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;
|
cmd* c = new cmd;
|
||||||
value* wv = nullptr;
|
value* wv = nullptr;
|
||||||
|
|||||||
@ -105,6 +105,9 @@ namespace dms {
|
|||||||
else if (isStr) {
|
else if (isStr) {
|
||||||
buffer.push_back(data);
|
buffer.push_back(data);
|
||||||
}
|
}
|
||||||
|
else if (data == '_') { // Can't believe I missed that haha
|
||||||
|
buffer.push_back(data);
|
||||||
|
}
|
||||||
else if (isdigit(data)) {
|
else if (isdigit(data)) {
|
||||||
isNum = true;
|
isNum = true;
|
||||||
buffer.push_back(data);
|
buffer.push_back(data);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ namespace dms {
|
|||||||
return this->tokens[pos-1];
|
return this->tokens[pos-1];
|
||||||
}
|
}
|
||||||
token tokenstream::next() {
|
token tokenstream::next() {
|
||||||
if (pos > this->tokens.size())
|
if (pos > this->tokens.size()-1)
|
||||||
return token{ tokentype::none,codes::NOOP,"EOS",0 };
|
return token{ tokentype::none,codes::NOOP,"EOS",0 };
|
||||||
return this->tokens[pos++];
|
return this->tokens[pos++];
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ namespace dms {
|
|||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
token tokenstream::peek() {
|
token tokenstream::peek() {
|
||||||
if (pos > this->tokens.size())
|
if (pos > this->tokens.size()-1)
|
||||||
return token{ tokentype::none,codes::NOOP,"EOS",0 };
|
return token{ tokentype::none,codes::NOOP,"EOS",0 };
|
||||||
return this->tokens[pos];
|
return this->tokens[pos];
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
DMS/dump.bin
BIN
DMS/dump.bin
Binary file not shown.
19
DMS/dump.txt
19
DMS/dump.txt
@ -67,6 +67,25 @@ Line <19> newline
|
|||||||
Line <19> newline
|
Line <19> newline
|
||||||
Line <20> newline
|
Line <20> 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 <21> newline
|
||||||
Line <22> newline
|
Line <22> newline
|
||||||
Line <22> newline
|
Line <22> newline
|
||||||
|
|||||||
@ -18,7 +18,7 @@ using extendedDefine
|
|||||||
"how are `inv:slot2` you doing?"
|
"how are `inv:slot2` you doing?"
|
||||||
}
|
}
|
||||||
|
|
||||||
//test = Bob[here]
|
test = Bob[a_test({4,hi["testing"],6})]
|
||||||
|
|
||||||
//Ryan:setNickname(Bob,"Bobby") // Not yet implemeted!
|
//Ryan:setNickname(Bob,"Bobby") // Not yet implemeted!
|
||||||
|
|
||||||
|
|||||||
@ -189,7 +189,9 @@ namespace dms {
|
|||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
value* buildVariable() {
|
value* buildVariable() {
|
||||||
count++;
|
count++;
|
||||||
std::string val = "$"+count;
|
std::stringstream str;
|
||||||
|
str << "$" << count;
|
||||||
|
std::string val = str.str();
|
||||||
return buildVariable(val);
|
return buildVariable(val);
|
||||||
}
|
}
|
||||||
value* buildBlock(std::string str) {
|
value* buildBlock(std::string str) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user