diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-07 08:10:47 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-07 08:10:47 +0100 |
commit | 8a7d756c01d63761226725288caba0a1563389b0 (patch) | |
tree | 8c62cf1fab4e1c6ee7f9080769838b6e798756c9 /expressions.h | |
parent | 2ed38e4d01d73d62b29a28d7540ca515f9ff3b09 (diff) | |
download | sciteco-8a7d756c01d63761226725288caba0a1563389b0.tar.gz |
expression stack fixes and some arithmetic commands
Diffstat (limited to 'expressions.h')
-rw-r--r-- | expressions.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/expressions.h b/expressions.h index 2ff9c1a..4a33632 100644 --- a/expressions.h +++ b/expressions.h @@ -26,7 +26,7 @@ public: inline int items(void) { - return (top - stack)/sizeof(Type); + return top - stack; } inline Type & @@ -97,6 +97,7 @@ public: * Arithmetic expression stacks */ extern class Expressions { +public: /* reflects also operator precedence */ enum Operator { OP_NIL = 0, @@ -114,20 +115,26 @@ extern class Expressions { OP_NUMBER }; +private: ValueStack<gint64> numbers; ValueStack<Operator> operators; - gint num_sign; - gint radix; - public: Expressions() : num_sign(1), radix(10) {} + gint num_sign; void set_num_sign(gint sign); + + gint radix; void set_radix(gint r); gint64 push(gint64 number); + inline gint64 + peek_num(int index = 1) + { + return numbers.peek(index); + } gint64 pop_num(int index = 1); gint64 pop_num_calc(int index, gint64 imply); inline gint64 @@ -151,7 +158,8 @@ public: inline int first_op(void) { - return args() + 1; + int n = args() + 1; + return n > operators.items() ? 0 : n; } void discard_args(void); |