diff --git a/examples/arithmetic.modal b/examples/arithmetic.modal new file mode 100644 index 0000000..374274f --- /dev/null +++ b/examples/arithmetic.modal @@ -0,0 +1,23 @@ +<> (add (s ?x) (s ?y)) ((s add ?x (s ?y))) +<> (add (s ?y) (0)) ((s ?y)) +<> (add (0) (s ?y)) ((s ?y)) +<> (add (0) (0)) (0) + +<> (subtract (s ?x) (s ?y)) (subtract ?x ?y) +<> (subtract (s ?x) (0)) (s ?x) +<> (subtract (0) (s ?y)) (s ?y) +<> (subtract (0) (0)) (0) + +<> (multiply (s ?x) (s ?y)) (add (s ?x) (multiply (s ?x) (subtract (s ?y) (s (0)))) +<> (multiply (s ?x) (s (0)) (s ?x) +<> (multiply (s (0)) (s ?y) (s ?y) +<> (multiply (s ?x) (0)) (0) +<> (multiply (0) (s ?x)) (0) + +<> (?x + ?y) (add ?x ?y) +<> (?x - ?y) (subtract ?x ?y) +<> (?x * ?y) (multiply ?x ?y) +<> (factorial (s (0))) ((s (0))) +<> (factorial (s ?x)) ((s ?x) * factorial ((s ?x) - (s (0)))) + +(s (0)) * (s (s (0))) \ No newline at end of file diff --git a/examples/test.modal b/examples/test.modal index 310551e..374274f 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,3 +1,23 @@ -<> ((?x -> ?y)) (<> ?x ?y) +<> (add (s ?x) (s ?y)) ((s add ?x (s ?y))) +<> (add (s ?y) (0)) ((s ?y)) +<> (add (0) (s ?y)) ((s ?y)) +<> (add (0) (0)) (0) -(foo -> bar) foo \ No newline at end of file +<> (subtract (s ?x) (s ?y)) (subtract ?x ?y) +<> (subtract (s ?x) (0)) (s ?x) +<> (subtract (0) (s ?y)) (s ?y) +<> (subtract (0) (0)) (0) + +<> (multiply (s ?x) (s ?y)) (add (s ?x) (multiply (s ?x) (subtract (s ?y) (s (0)))) +<> (multiply (s ?x) (s (0)) (s ?x) +<> (multiply (s (0)) (s ?y) (s ?y) +<> (multiply (s ?x) (0)) (0) +<> (multiply (0) (s ?x)) (0) + +<> (?x + ?y) (add ?x ?y) +<> (?x - ?y) (subtract ?x ?y) +<> (?x * ?y) (multiply ?x ?y) +<> (factorial (s (0))) ((s (0))) +<> (factorial (s ?x)) ((s ?x) * factorial ((s ?x) - (s (0)))) + +(s (0)) * (s (s (0))) \ No newline at end of file diff --git a/src/modal.c b/src/modal.c index 5e17697..a9f1b15 100644 --- a/src/modal.c +++ b/src/modal.c @@ -71,6 +71,10 @@ writereg(char r) { int depth = 0; char c, *s = regs[(int)r]; + if(!s) { + printf("!! Reading from invalid register: ?%c\n", r); + return; + } if(s[0] == '(') { while((c = *s++)) { if(c == '(') depth++;