Changeset 20936 for trunk/Ohana/src/opihi/dvo/dbRPN.c
- Timestamp:
- Dec 7, 2008, 3:31:01 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/dbRPN.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/dbRPN.c
r13479 r20936 21 21 22 22 /* decide on priority of object */ 23 type = 0;23 type = DB_STACK_NONE; 24 24 /* unary operations */ 25 if (!strcmp (argv[i], "abs")) { type = 9; goto gotit; } 26 if (!strcmp (argv[i], "int")) { type = 9; goto gotit; } 27 if (!strcmp (argv[i], "exp")) { type = 9; goto gotit; } 28 if (!strcmp (argv[i], "ten")) { type = 9; goto gotit; } 29 if (!strcmp (argv[i], "log")) { type = 9; goto gotit; } 30 if (!strcmp (argv[i], "ln")) { type = 9; goto gotit; } 31 if (!strcmp (argv[i], "sqrt")) { type = 9; goto gotit; } 32 if (!strcmp (argv[i], "erf")) { type = 9; goto gotit; } 33 34 if (!strcmp (argv[i], "sinh")) { type = 9; goto gotit; } 35 if (!strcmp (argv[i], "cosh")) { type = 9; goto gotit; } 36 if (!strcmp (argv[i], "asinh")) { type = 9; goto gotit; } 37 if (!strcmp (argv[i], "acosh")) { type = 9; goto gotit; } 38 39 if (!strcmp (argv[i], "sin")) { type = 9; goto gotit; } 40 if (!strcmp (argv[i], "cos")) { type = 9; goto gotit; } 41 if (!strcmp (argv[i], "tan")) { type = 9; goto gotit; } 42 if (!strcmp (argv[i], "dsin")) { type = 9; goto gotit; } 43 if (!strcmp (argv[i], "dcos")) { type = 9; goto gotit; } 44 if (!strcmp (argv[i], "dtan")) { type = 9; goto gotit; } 45 if (!strcmp (argv[i], "asin")) { type = 9; goto gotit; } 46 if (!strcmp (argv[i], "acos")) { type = 9; goto gotit; } 47 if (!strcmp (argv[i], "atan")) { type = 9; goto gotit; } 48 if (!strcmp (argv[i], "dasin")) { type = 9; goto gotit; } 49 if (!strcmp (argv[i], "dacos")) { type = 9; goto gotit; } 50 if (!strcmp (argv[i], "datan")) { type = 9; goto gotit; } 51 52 if (!strcmp (argv[i], "lgamma")) { type = 9; goto gotit; } 53 54 if (!strcmp (argv[i], "rnd")) { type = 9; goto gotit; } 55 if (!strcmp (argv[i], "xramp")) { type = 9; goto gotit; } 56 if (!strcmp (argv[i], "yramp")) { type = 9; goto gotit; } 57 if (!strcmp (argv[i], "ramp")) { type = 9; goto gotit; } 58 if (!strcmp (argv[i], "zero")) { type = 9; goto gotit; } 59 if (!strcmp (argv[i], "--")) { type = 9; goto gotit; } 60 if (!strcmp (argv[i], "not")) { type = 9; goto gotit; } 61 if (!strcmp (argv[i], "isinf")) { type = 9; goto gotit; } 62 if (!strcmp (argv[i], "isnan")) { type = 9; goto gotit; } 25 if (!strcmp (argv[i], "abs")) { type = DB_STACK_UNARY; goto gotit; } 26 if (!strcmp (argv[i], "int")) { type = DB_STACK_UNARY; goto gotit; } 27 if (!strcmp (argv[i], "exp")) { type = DB_STACK_UNARY; goto gotit; } 28 if (!strcmp (argv[i], "ten")) { type = DB_STACK_UNARY; goto gotit; } 29 if (!strcmp (argv[i], "log")) { type = DB_STACK_UNARY; goto gotit; } 30 if (!strcmp (argv[i], "ln")) { type = DB_STACK_UNARY; goto gotit; } 31 if (!strcmp (argv[i], "sqrt")) { type = DB_STACK_UNARY; goto gotit; } 32 if (!strcmp (argv[i], "erf")) { type = DB_STACK_UNARY; goto gotit; } 33 if (!strcmp (argv[i], "sinh")) { type = DB_STACK_UNARY; goto gotit; } 34 if (!strcmp (argv[i], "cosh")) { type = DB_STACK_UNARY; goto gotit; } 35 if (!strcmp (argv[i], "asinh")) { type = DB_STACK_UNARY; goto gotit; } 36 if (!strcmp (argv[i], "acosh")) { type = DB_STACK_UNARY; goto gotit; } 37 if (!strcmp (argv[i], "sin")) { type = DB_STACK_UNARY; goto gotit; } 38 if (!strcmp (argv[i], "cos")) { type = DB_STACK_UNARY; goto gotit; } 39 if (!strcmp (argv[i], "tan")) { type = DB_STACK_UNARY; goto gotit; } 40 if (!strcmp (argv[i], "dsin")) { type = DB_STACK_UNARY; goto gotit; } 41 if (!strcmp (argv[i], "dcos")) { type = DB_STACK_UNARY; goto gotit; } 42 if (!strcmp (argv[i], "dtan")) { type = DB_STACK_UNARY; goto gotit; } 43 if (!strcmp (argv[i], "asin")) { type = DB_STACK_UNARY; goto gotit; } 44 if (!strcmp (argv[i], "acos")) { type = DB_STACK_UNARY; goto gotit; } 45 if (!strcmp (argv[i], "atan")) { type = DB_STACK_UNARY; goto gotit; } 46 if (!strcmp (argv[i], "dasin")) { type = DB_STACK_UNARY; goto gotit; } 47 if (!strcmp (argv[i], "dacos")) { type = DB_STACK_UNARY; goto gotit; } 48 if (!strcmp (argv[i], "datan")) { type = DB_STACK_UNARY; goto gotit; } 49 if (!strcmp (argv[i], "lgamma")) { type = DB_STACK_UNARY; goto gotit; } 50 if (!strcmp (argv[i], "rnd")) { type = DB_STACK_UNARY; goto gotit; } 51 if (!strcmp (argv[i], "xramp")) { type = DB_STACK_UNARY; goto gotit; } 52 if (!strcmp (argv[i], "yramp")) { type = DB_STACK_UNARY; goto gotit; } 53 if (!strcmp (argv[i], "ramp")) { type = DB_STACK_UNARY; goto gotit; } 54 if (!strcmp (argv[i], "zero")) { type = DB_STACK_UNARY; goto gotit; } 55 if (!strcmp (argv[i], "--")) { type = DB_STACK_UNARY; goto gotit; } 56 if (!strcmp (argv[i], "not")) { type = DB_STACK_UNARY; goto gotit; } 57 if (!strcmp (argv[i], "isinf")) { type = DB_STACK_UNARY; goto gotit; } 58 if (!strcmp (argv[i], "isnan")) { type = DB_STACK_UNARY; goto gotit; } 63 59 64 60 /* binary operations */ 65 if (!strcmp (argv[i], "^")) { type = 8; goto gotit; }66 67 if (!strcmp (argv[i], "@")) { type = 7; goto gotit; }68 if (!strcmp (argv[i], "/")) { type = 7; goto gotit; }69 if (!strcmp (argv[i], "*")) { type = 7; goto gotit; }70 if (!strcmp (argv[i], "%")) { type = 7; goto gotit; }71 72 if (!strcmp (argv[i], "+")) { type = 6; goto gotit; }73 if (!strcmp (argv[i], "-")) { type = 6; goto gotit; }61 if (!strcmp (argv[i], "^")) { type = DB_STACK_POWER; goto gotit; } 62 63 if (!strcmp (argv[i], "@")) { type = DB_STACK_MULTIPLY; goto gotit; } 64 if (!strcmp (argv[i], "/")) { type = DB_STACK_MULTIPLY; goto gotit; } 65 if (!strcmp (argv[i], "*")) { type = DB_STACK_MULTIPLY; goto gotit; } 66 if (!strcmp (argv[i], "%")) { type = DB_STACK_MULTIPLY; goto gotit; } 67 68 if (!strcmp (argv[i], "+")) { type = DB_STACK_SUM; goto gotit; } 69 if (!strcmp (argv[i], "-")) { type = DB_STACK_SUM; goto gotit; } 74 70 75 if (!strcmp (argv[i], "&")) { type = 5; goto gotit; }76 if (!strcmp (argv[i], "|")) { type = 5; goto gotit; }77 78 if (!strcmp (argv[i], "<")) { type = 4; goto gotit; }79 if (!strcmp (argv[i], ">")) { type = 4; goto gotit; }80 if (!strcmp (argv[i], "==")) { type = 4; strcpy (argv[i], "E"); goto gotit; }81 if (!strcmp (argv[i], "!=")) { type = 4; strcpy (argv[i], "N"); goto gotit; }82 if (!strcmp (argv[i], "<=")) { type = 4; strcpy (argv[i], "L"); goto gotit; }83 if (!strcmp (argv[i], ">=")) { type = 4; strcpy (argv[i], "G"); goto gotit; }84 if (!strcmp (argv[i], ">>")) { type = 4; strcpy (argv[i], "U"); goto gotit; }85 if (!strcmp (argv[i], "<<")) { type = 4; strcpy (argv[i], "D"); goto gotit; }86 87 if (!strcmp (argv[i], "&&")) { type = 3; strcpy (argv[i], "A"); goto gotit; }88 if (!strcmp (argv[i], "||")) { type = 3; strcpy (argv[i], "O"); goto gotit; }89 90 if (!strcmp (argv[i], "(")) { type = 2; goto gotit; }91 if (!strcmp (argv[i], ")")) { type = 1; goto gotit; }71 if (!strcmp (argv[i], "&")) { type = DB_STACK_BITWISE; goto gotit; } 72 if (!strcmp (argv[i], "|")) { type = DB_STACK_BITWISE; goto gotit; } 73 74 if (!strcmp (argv[i], "<")) { type = DB_STACK_COMPARE; goto gotit; } 75 if (!strcmp (argv[i], ">")) { type = DB_STACK_COMPARE; goto gotit; } 76 if (!strcmp (argv[i], "==")) { type = DB_STACK_COMPARE; strcpy (argv[i], "E"); goto gotit; } 77 if (!strcmp (argv[i], "!=")) { type = DB_STACK_COMPARE; strcpy (argv[i], "N"); goto gotit; } 78 if (!strcmp (argv[i], "<=")) { type = DB_STACK_COMPARE; strcpy (argv[i], "L"); goto gotit; } 79 if (!strcmp (argv[i], ">=")) { type = DB_STACK_COMPARE; strcpy (argv[i], "G"); goto gotit; } 80 if (!strcmp (argv[i], ">>")) { type = DB_STACK_COMPARE; strcpy (argv[i], "U"); goto gotit; } 81 if (!strcmp (argv[i], "<<")) { type = DB_STACK_COMPARE; strcpy (argv[i], "D"); goto gotit; } 82 83 if (!strcmp (argv[i], "&&")) { type = DB_STACK_LOGIC; strcpy (argv[i], "A"); goto gotit; } 84 if (!strcmp (argv[i], "||")) { type = DB_STACK_LOGIC; strcpy (argv[i], "O"); goto gotit; } 85 86 if (!strcmp (argv[i], "(")) { type = DB_STACK_OPEN_PAR; goto gotit; } 87 if (!strcmp (argv[i], ")")) { type = DB_STACK_CLOSE_PAR; goto gotit; } 92 88 93 89 gotit: 94 90 /* choose how to deal with object */ 95 91 switch (type) { 96 case 8: /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */92 case DB_STACK_POWER: /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */ 97 93 /* pop previous, higher operators from OP stack to stack */ 98 94 for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) { … … 107 103 Nop_stack ++; 108 104 break; 109 case 9: /* unary OPs */110 case 7: /* binary OPs */111 case 6:112 case 5:113 case 4:114 case 3:105 case DB_STACK_UNARY: /* unary OPs */ 106 case DB_STACK_MULTIPLY: /* binary OPs */ 107 case DB_STACK_SUM: 108 case DB_STACK_BITWISE: 109 case DB_STACK_COMPARE: 110 case DB_STACK_LOGIC: 115 111 /* pop previous, higher or equal operators from OP stack to stack */ 116 112 for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) { … … 125 121 Nop_stack ++; 126 122 break; 127 case 2:123 case DB_STACK_OPEN_PAR: 128 124 /* push operator on OP stack */ 129 125 op_stack[Nop_stack].name = strcreate (argv[i]); … … 131 127 Nop_stack ++; 132 128 break; 133 case 1:129 case DB_STACK_CLOSE_PAR: 134 130 /* pop rest of operators from OP stack to stack, looking for '(' */ 135 for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) {131 for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != DB_STACK_OPEN_PAR); j--) { 136 132 stack[Nstack] = op_stack[j]; 137 133 op_stack[j].name = NULL; … … 139 135 Nop_stack --; 140 136 } 141 if ((j == -1) || (op_stack[j].type != 2)) {137 if ((j == -1) || (op_stack[j].type != DB_STACK_OPEN_PAR)) { 142 138 push_error ("syntax error: mismatched parenthesis"); 143 139 Nstack = 0; … … 150 146 /* value of 'X' is used as sentinel until we sort out values */ 151 147 stack[Nstack].name = strcreate (argv[i]); 152 stack[Nstack].type = 'X';148 stack[Nstack].type = DB_STACK_VALUE; 153 149 Nstack ++; 154 150 break; … … 156 152 } 157 153 158 /* dump remaining operators on stack, checking for ' )' */154 /* dump remaining operators on stack, checking for '(' */ 159 155 for (j = Nop_stack - 1; j >= 0; j--) { 160 if (op_stack[j].type == 2) {156 if (op_stack[j].type == DB_STACK_OPEN_PAR) { 161 157 push_error ("syntax error: mismatched parenthesis"); 162 158 Nstack = 0;
Note:
See TracChangeset
for help on using the changeset viewer.
