diff --git a/misc/addinput.rf b/misc/addinput.rf new file mode 100644 index 0000000..3e2854c --- /dev/null +++ b/misc/addinput.rf @@ -0,0 +1,6 @@ +> 0 2 5 * v +v "Please enter two integers: " < +> : v v "sum: " < +^ , _ & & + 0 ^ + > : v + ^ , _ $ . 2 5 * , @ diff --git a/misc/cat.rf b/misc/cat.rf new file mode 100644 index 0000000..3be2ab8 --- /dev/null +++ b/misc/cat.rf @@ -0,0 +1,2 @@ +>#v v#!< this program outputs the lines it reads +@,_,>~:^ in a bash console you can send an EOF with ctrl+D diff --git a/misc/reverseln.rf b/misc/reverseln.rf new file mode 100644 index 0000000..683edca --- /dev/null +++ b/misc/reverseln.rf @@ -0,0 +1,3 @@ +> 0 2 5 * > ~ : 5 v + | - * 2 < +@ _ #! #, #:< diff --git a/src/operators.cpp b/src/operators.cpp index 189cece..1c040d9 100644 --- a/src/operators.cpp +++ b/src/operators.cpp @@ -398,6 +398,29 @@ public: } }; +class ReadCharSR : public Subroutine +{ +public: + virtual void run(VM *vm, Thread *th) + { + char ch; + std::cin >> std::noskipws >> ch; + th->push(ch); + th->move(); + } +}; + +class ReadNumSR : public Subroutine +{ +public: + virtual void run(VM *vm, Thread *th) + { + int i; + std::cin >> i; + th->push(i); + th->move(); + } +}; class TemplateSR : public Subroutine { @@ -440,6 +463,8 @@ void assignStandardSR(Thread *th) th->setOperator('[', 22); th->setOperator('R', 23); th->setOperator('P', 24); + th->setOperator('~', 25); + th->setOperator('&', 26); // TODO: & ~ M L } @@ -469,4 +494,6 @@ void loadSubroutines(VM *vm) { vm->loadSubroutine(new BridgeSR); vm->loadSubroutine(new RtnSR); vm->loadSubroutine(new LoadSR); + vm->loadSubroutine(new ReadCharSR); + vm->loadSubroutine(new ReadNumSR); }