Start work on lists w/ command line args
This commit is contained in:
1
examples/args.io
Normal file
1
examples/args.io
Normal file
@@ -0,0 +1 @@
|
||||
println args;
|
@@ -54,3 +54,7 @@ string ArgParser::getArg(int index) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
vector<string> ArgParser::getAllArgs() {
|
||||
return args;
|
||||
}
|
||||
|
@@ -26,4 +26,5 @@ private:
|
||||
public:
|
||||
ArgParser(int argc, char* argv[]);
|
||||
string getArg(int index);
|
||||
vector<string> getAllArgs();
|
||||
};
|
||||
|
@@ -31,7 +31,21 @@ optional<Token> Interpreter::peek(int offset) {
|
||||
return {};
|
||||
}
|
||||
|
||||
void Interpreter::convertToTokens(vector<Token> tokenList) {
|
||||
void Interpreter::initInterpreter(vector<string> args) {
|
||||
List arguments;
|
||||
for (int i = 0; i < args.size(); i++) {
|
||||
Value buf;
|
||||
buf.type = valtype::STR;
|
||||
buf.value = args[i];
|
||||
arguments.value.push_back(buf);
|
||||
}
|
||||
Value buf;
|
||||
buf.type = valtype::LIST;
|
||||
buf.value = arguments;
|
||||
variables["args"] = buf;
|
||||
}
|
||||
|
||||
void Interpreter::interpret(vector<Token> tokenList) {
|
||||
if (debugMode) log.toggleDebugPrint();
|
||||
tokens = tokenList;
|
||||
log.debug("Alright we got " + to_string(tokens.size()) + " tokens");
|
||||
|
@@ -36,8 +36,9 @@ private:
|
||||
int tokenIndex = -1;
|
||||
optional<Token> consume();
|
||||
optional<Token> peek(int offset = 1);
|
||||
void executeCode(vector<Token> tokens);
|
||||
|
||||
public:
|
||||
void convertToTokens(vector<Token> tokenList);
|
||||
void executeCode(vector<Token> tokens);
|
||||
void initInterpreter(vector<string> args);
|
||||
void interpret(vector<Token> tokenList);
|
||||
};
|
||||
|
@@ -50,6 +50,7 @@ int main(int argc, char* argv[]) {
|
||||
// Initialise the interpreter
|
||||
Interpreter interpreter;
|
||||
// Convert to tokens and run the code
|
||||
interpreter.convertToTokens(parser.getTokens());
|
||||
interpreter.initInterpreter(args.getAllArgs());
|
||||
interpreter.interpret(parser.getTokens());
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user