summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-10-04 12:44:16 -0400
committerJune McEnroe <june@causal.agency>2016-10-04 12:44:46 -0400
commit0a57f186b7ab83e014bded3b582f9d50b0ad3fbc (patch)
treee19c48531a1ef9974ef22957f6025a64d5d54025
parentTry ops first in rpn (diff)
downloadsrc-0a57f186b7ab83e014bded3b582f9d50b0ad3fbc.tar.gz
src-0a57f186b7ab83e014bded3b582f9d50b0ad3fbc.zip
Add quoting to rpn
-rwxr-xr-x.bin/rpn.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/.bin/rpn.c b/.bin/rpn.c
index 0fcf7933..d3fe0667 100755
--- a/.bin/rpn.c
+++ b/.bin/rpn.c
@@ -35,6 +35,7 @@ static struct {
     int64_t data[1024];
     size_t len;
     int radix;
+    char op;
 } stack = { .radix = 10 };
 
 static void push(int64_t val) {
@@ -48,6 +49,19 @@ static int64_t pop(void) {
 }
 
 static bool stack_op(char op) {
+    if (stack.op == '\'') {
+        push(op);
+        stack.op = 0;
+        return true;
+    }
+    if (stack.op == '"') {
+        if (op == '"')
+            stack.op = 0;
+        else
+            push(op);
+        return true;
+    }
+
     int64_t a, b;
     switch (op) {
         case '$': pop();
@@ -71,6 +85,7 @@ static bool stack_op(char op) {
         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;