args
variable allows access to command line args
This commit is contained in:
1
examples/args.io
Normal file
1
examples/args.io
Normal file
@@ -0,0 +1 @@
|
|||||||
|
printlist args;
|
@@ -78,25 +78,17 @@ void Interpreter::interpret(vector<Token> tokenList) {
|
|||||||
|
|
||||||
if (varIt != variables.end()) {
|
if (varIt != variables.end()) {
|
||||||
// This is pretty crappy code but it exists for now. Lists are gonna break this so much it's not even gonna be funny
|
// This is pretty crappy code but it exists for now. Lists are gonna break this so much it's not even gonna be funny
|
||||||
if (varIt->second.type == valtype::LIST) {
|
//if (varIt->second.type == valtype::LIST) {
|
||||||
if (peek()->keyword == keywords::OSQUA) {
|
|
||||||
if (peek(2)->keyword == keywords::VALUE && peek(2)->type == valtype::INT && peek(2)->type == valtype::INT && peek(3)->keyword == keywords::CSQUA) {
|
//} else {
|
||||||
Token newToken;
|
|
||||||
Value tokenVal = get<List>(varIt->second.value).value[get<int>(peek(2)->value.value)];
|
|
||||||
newToken.keyword = keywords::VALUE;
|
|
||||||
newToken.type = tokenVal.type;
|
|
||||||
newToken.value.value = tokenVal.value;
|
|
||||||
// Do this later
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Replace the token with the variable's value
|
// Replace the token with the variable's value
|
||||||
Token newToken;
|
Token newToken;
|
||||||
newToken.keyword = keywords::VALUE;
|
newToken.keyword = keywords::VALUE;
|
||||||
|
if (varIt->second.type == valtype::LIST) newToken.keyword = keywords::LISTOBJ;
|
||||||
newToken.type = varIt->second.type;
|
newToken.type = varIt->second.type;
|
||||||
newToken.value = varIt->second;
|
newToken.value = varIt->second;
|
||||||
currentInstruction[i] = newToken;
|
currentInstruction[i] = newToken;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
} else if (currentInstruction[i].keyword == keywords::INPUT) {
|
} else if (currentInstruction[i].keyword == keywords::INPUT) {
|
||||||
Token newToken;
|
Token newToken;
|
||||||
@@ -273,7 +265,7 @@ void Interpreter::interpret(vector<Token> tokenList) {
|
|||||||
newToken.type = valtype::LIST;
|
newToken.type = valtype::LIST;
|
||||||
newToken.value.type = valtype::LIST;
|
newToken.value.type = valtype::LIST;
|
||||||
newToken.value.value = buf;
|
newToken.value.value = buf;
|
||||||
newToken.keyword = keywords::LIST;
|
newToken.keyword = keywords::LISTOBJ;
|
||||||
currentInstruction.insert(currentInstruction.begin() + startIndex, newToken);
|
currentInstruction.insert(currentInstruction.begin() + startIndex, newToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +360,7 @@ void Interpreter::executeCode(vector<Token> tokens) {
|
|||||||
if (tokens.size() <= i) syntaxError.fnNotSufficientArgs("printlist", 1, 1, 0);
|
if (tokens.size() <= i) syntaxError.fnNotSufficientArgs("printlist", 1, 1, 0);
|
||||||
Token nextToken = tokens[i];
|
Token nextToken = tokens[i];
|
||||||
log.debug("Printing a list. Type of next token is " + log.getTypeString(nextToken.value.type));
|
log.debug("Printing a list. Type of next token is " + log.getTypeString(nextToken.value.type));
|
||||||
if (nextToken.keyword == keywords::LIST && nextToken.type == valtype::LIST) {
|
if (nextToken.keyword == keywords::LISTOBJ && nextToken.type == valtype::LIST) {
|
||||||
List list = get<List>(nextToken.value.value);
|
List list = get<List>(nextToken.value.value);
|
||||||
log.debug("List obtained");
|
log.debug("List obtained");
|
||||||
if (list.value[0].type == valtype::INT) {
|
if (list.value[0].type == valtype::INT) {
|
||||||
|
@@ -39,7 +39,7 @@ enum class keywords {
|
|||||||
EQUAL, INEQUAL, LESS, GREATER, EQLESS, EQGREATER,
|
EQUAL, INEQUAL, LESS, GREATER, EQLESS, EQGREATER,
|
||||||
INCREMENT, DECREMENT,
|
INCREMENT, DECREMENT,
|
||||||
PRINT, PRINTLN, PRINTLIST, LET, INPUT, EXIT,
|
PRINT, PRINTLN, PRINTLIST, LET, INPUT, EXIT,
|
||||||
VALUE, LIST, SEMICOLON, VARIABLE,
|
VALUE, LISTOBJ, SEMICOLON, VARIABLE,
|
||||||
COMMENT
|
COMMENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user