added 2 code files; added enl instruction; completed main to do the right thing

This commit is contained in:
Bob Polis 2020-09-07 18:50:09 +02:00
parent b0a3637b1d
commit 344f26b05f
6 changed files with 48 additions and 2 deletions

View File

@ -0,0 +1,4 @@
\avans-minor-swa-cpp1
rot
\.txt
cat

View File

@ -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

View File

@ -15,4 +15,5 @@ $ctr
>loop
gne
$result
end
\.txt
cat

View File

@ -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() {

View File

@ -57,6 +57,7 @@ class interpreter {
void cat();
void len();
void rot();
void enl();
// tests & jumps
void gto();

View File

@ -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';