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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> ArgParser::getAllArgs() {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
@@ -26,4 +26,5 @@ private:
|
|||||||
public:
|
public:
|
||||||
ArgParser(int argc, char* argv[]);
|
ArgParser(int argc, char* argv[]);
|
||||||
string getArg(int index);
|
string getArg(int index);
|
||||||
|
vector<string> getAllArgs();
|
||||||
};
|
};
|
||||||
|
@@ -31,7 +31,21 @@ optional<Token> Interpreter::peek(int offset) {
|
|||||||
return {};
|
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();
|
if (debugMode) log.toggleDebugPrint();
|
||||||
tokens = tokenList;
|
tokens = tokenList;
|
||||||
log.debug("Alright we got " + to_string(tokens.size()) + " tokens");
|
log.debug("Alright we got " + to_string(tokens.size()) + " tokens");
|
||||||
|
@@ -36,8 +36,9 @@ private:
|
|||||||
int tokenIndex = -1;
|
int tokenIndex = -1;
|
||||||
optional<Token> consume();
|
optional<Token> consume();
|
||||||
optional<Token> peek(int offset = 1);
|
optional<Token> peek(int offset = 1);
|
||||||
|
void executeCode(vector<Token> tokens);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void convertToTokens(vector<Token> tokenList);
|
void initInterpreter(vector<string> args);
|
||||||
void executeCode(vector<Token> tokens);
|
void interpret(vector<Token> tokenList);
|
||||||
};
|
};
|
||||||
|
@@ -50,6 +50,7 @@ int main(int argc, char* argv[]) {
|
|||||||
// Initialise the interpreter
|
// Initialise the interpreter
|
||||||
Interpreter interpreter;
|
Interpreter interpreter;
|
||||||
// Convert to tokens and run the code
|
// Convert to tokens and run the code
|
||||||
interpreter.convertToTokens(parser.getTokens());
|
interpreter.initInterpreter(args.getAllArgs());
|
||||||
|
interpreter.interpret(parser.getTokens());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user