diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-07 19:08:15 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-07 19:08:15 +0100 |
commit | 99c8e92238986d00557ded56adc8495086d3c631 (patch) | |
tree | d85adc60f1880fc9ef9f231407a78414039698a5 /expressions.cpp | |
parent | 408f8311dd071924d62ae10d0078e595e9137a9e (diff) | |
download | sciteco-99c8e92238986d00557ded56adc8495086d3c631.tar.gz |
fixed "," operator
instead of pushing a special number (which wasn't that special...), use a dedicated "new" operator which does not count as an argument operator, nor does it count as an ordinary operator and it is popped before any number (and "number" operator) is pushed
Diffstat (limited to 'expressions.cpp')
-rw-r--r-- | expressions.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/expressions.cpp b/expressions.cpp index 8c8fb0c..38af2fc 100644 --- a/expressions.cpp +++ b/expressions.cpp @@ -23,8 +23,8 @@ Expressions::set_radix(gint r) gint64 Expressions::push(gint64 number) { - while (numbers.items() > 0 && numbers.peek() == G_MAXINT64) - pop_num(); + while (operators.items() && operators.peek() == OP_NEW) + pop_op(); push(OP_NUMBER); @@ -35,7 +35,7 @@ Expressions::push(gint64 number) gint64 Expressions::pop_num(int index) { - gint64 n = G_MAXINT64; + gint64 n = 0; pop_op(); if (numbers.items() > 0) { @@ -49,30 +49,17 @@ Expressions::pop_num(int index) gint64 Expressions::pop_num_calc(int index, gint64 imply) { - gint64 n = G_MAXINT64; - eval(); - if (args() > 0) - n = pop_num(index); - if (n == G_MAXINT64) - n = imply; - if (num_sign < 0) set_num_sign(1); - return n; + return args() > 0 ? pop_num(index) : imply; } gint64 Expressions::add_digit(gchar digit) { - gint64 n = 0; - - if (args() > 0) { - n = pop_num(); - if (n == G_MAXINT64) - n = 0; - } + gint64 n = args() > 0 ? pop_num() : 0; return push(n*radix + num_sign*(digit - '0')); } @@ -177,6 +164,24 @@ Expressions::args(void) return n; } +int +Expressions::first_op(void) +{ + int items = operators.items(); + + for (int i = 1; i <= items; i++) { + switch (operators.peek(i)) { + case OP_NUMBER: + case OP_NEW: + break; + default: + return i; + } + } + + return 0; +} + void Expressions::discard_args(void) { |