added 2 code files; added enl instruction; completed main to do the right thing
This commit is contained in:
parent
b0a3637b1d
commit
344f26b05f
4
code/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt
Normal file
4
code/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt
Normal file
@ -0,0 +1,4 @@
|
||||
\avans-minor-swa-cpp1
|
||||
rot
|
||||
\.txt
|
||||
cat
|
31
code/ninaf-zvabe-fjn-pcc1.txt
Normal file
31
code/ninaf-zvabe-fjn-pcc1.txt
Normal 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
|
@ -15,4 +15,5 @@ $ctr
|
||||
>loop
|
||||
gne
|
||||
$result
|
||||
end
|
||||
\.txt
|
||||
cat
|
||||
|
@ -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() {
|
||||
|
@ -57,6 +57,7 @@ class interpreter {
|
||||
void cat();
|
||||
void len();
|
||||
void rot();
|
||||
void enl();
|
||||
|
||||
// tests & jumps
|
||||
void gto();
|
||||
|
2
main.cpp
2
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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user