From 344f26b05f9a04253a6aff18470d068f7521e2ff Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Mon, 7 Sep 2020 18:50:09 +0200 Subject: [PATCH] added 2 code files; added enl instruction; completed main to do the right thing --- code/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt | 4 +++ code/ninaf-zvabe-fjn-pcc1.txt | 31 +++++++++++++++++++++++ code/start.txt | 3 ++- interpreter.cpp | 9 +++++++ interpreter.hpp | 1 + main.cpp | 2 +- 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 code/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt create mode 100644 code/ninaf-zvabe-fjn-pcc1.txt diff --git a/code/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt b/code/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt new file mode 100644 index 0000000..fdf08f3 --- /dev/null +++ b/code/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt @@ -0,0 +1,4 @@ +\avans-minor-swa-cpp1 +rot +\.txt +cat diff --git a/code/ninaf-zvabe-fjn-pcc1.txt b/code/ninaf-zvabe-fjn-pcc1.txt new file mode 100644 index 0000000..6f57e50 --- /dev/null +++ b/code/ninaf-zvabe-fjn-pcc1.txt @@ -0,0 +1,31 @@ +\Erny fghcvqvgl orngf negvsvpvny vagryyvtrapr rirel gvzr. +rot +enl +=quote +\ ! +0 +1 +slc +=space +$space +=white +37 +=cnt +:loop +$space +$white +cat +=space +$cnt +dec +=cnt +$cnt +0 +>loop +gne +$quote +$space +cat +\-- Terry Pratchett +cat +end diff --git a/code/start.txt b/code/start.txt index ab7b36c..50005a2 100644 --- a/code/start.txt +++ b/code/start.txt @@ -15,4 +15,5 @@ $ctr >loop gne $result -end +\.txt +cat diff --git a/interpreter.cpp b/interpreter.cpp index e57f83f..dd37bff 100644 --- a/interpreter.cpp +++ b/interpreter.cpp @@ -119,6 +119,7 @@ void interpreter::exec_instruction(const std::string& code, bool& done) { else if (code == "gge") gge(); else if (code == "fun") fun(); else if (code == "ret") ret(); + else if (code == "enl") enl(); else throw syntax_error {code}; } @@ -271,6 +272,14 @@ void interpreter::rot() { _pc++; } +void interpreter::enl() { + std::string val {_stack.back()}; + _stack.pop_back(); + val += '\n'; + _stack.push_back(val); + _pc++; +} + // tests & jumps ---------------------------------------------------------- void interpreter::gto() { diff --git a/interpreter.hpp b/interpreter.hpp index 3b0ff19..091a1a5 100644 --- a/interpreter.hpp +++ b/interpreter.hpp @@ -57,6 +57,7 @@ class interpreter { void cat(); void len(); void rot(); + void enl(); // tests & jumps void gto(); diff --git a/main.cpp b/main.cpp index 30a24fa..ce21990 100644 --- a/main.cpp +++ b/main.cpp @@ -74,7 +74,7 @@ int main(int argc, const char * argv[]) { interpreter proc; while (!done) { code = req.get(base_url + next_url); - std::cerr << code << '\n'; + // std::cerr << code << '\n'; std::istringstream in {code}; next_url = proc.eval(in, done); std::cerr << next_url << '\n';