summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-10-04 13:22:25 -0400
committerJune McEnroe <june@causal.agency>2016-10-04 13:22:25 -0400
commit0daa49981a2f05cc4120b8298c3a826d8dd5b05a (patch)
tree3a6ebf5abee9427a4b3a267f8d4e892ab5b2c1c8
parentAdd ! to rpn (diff)
downloadsrc-0daa49981a2f05cc4120b8298c3a826d8dd5b05a.tar.gz
src-0daa49981a2f05cc4120b8298c3a826d8dd5b05a.zip
Add @ to rpn
-rwxr-xr-x.bin/rpn.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/.bin/rpn.c b/.bin/rpn.c
index b7d3e0a1..a33296cf 100755
--- a/.bin/rpn.c
+++ b/.bin/rpn.c
@@ -49,9 +49,15 @@ static int64_t pop(void) {
 }
 
 static bool stack_op(char op) {
+    if (stack.op == '@') {
+        stack.op = 0;
+        while (stack.len > 1)
+            stack_op(op);
+        return true;
+    }
     if (stack.op == '\'') {
-        push(op);
         stack.op = 0;
+        push(op);
         return true;
     }
     if (stack.op == '"') {
@@ -62,9 +68,14 @@ static bool stack_op(char op) {
 
     int64_t a, b;
     switch (op) {
-        case '$': pop();
-        break; case '\\': a = pop(); b = pop(); push(a); push(b);
+        case '@': case '\'': case '"': stack.op = op;
+        break; case 'b': stack.radix = 2;
+        break; case 'o': stack.radix = 8;
+        break; case 'd': stack.radix = 10;
+        break; case 'x': stack.radix = 16;
+        break; case ';': a = pop();
         break; case ':': a = pop(); push(a); push(a);
+        break; case '\\': a = pop(); b = pop(); push(a); push(b);
         break; case '_': a = pop(); push(-a);
         break; case '+': a = pop(); push(pop() + a);
         break; case '-': a = pop(); push(pop() - a);
@@ -80,11 +91,6 @@ static bool stack_op(char op) {
         break; case '>': a = pop(); push(pop() >> a);
         break; case '.': a = pop(); printf("%s\n", fmt(stack.radix, a));
         break; case ',': a = pop(); printf("%c\n", (char) a);
-        break; case 'b': stack.radix = 2;
-        break; case 'o': stack.radix = 8;
-        break; case 'd': stack.radix = 10;
-        break; case 'x': stack.radix = 16;
-        break; case '\'': case '"': stack.op = op;
         break; default: return false;
     }
     return true;