summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cc55
-rw-r--r--op.cc9
-rw-r--r--op.h7
-rw-r--r--report.h2
4 files changed, 49 insertions, 24 deletions
diff --git a/main.cc b/main.cc
index 8d9f64dd..7356a958 100644
--- a/main.cc
+++ b/main.cc
@@ -170,30 +170,51 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[],
if (verb == "parse") {
expr_t expr(*arg);
- IF_INFO() {
- std::cout << "Value expression tree:" << std::endl;
- expr.dump(std::cout);
- std::cout << std::endl;
+ *out << "Value expression as input: " << *arg << std::endl;
+
+ *out << "Value expression as parsed: ";
+ expr.print(*out, report);
+ *out << std::endl;
- std::cout << "Value expression parsed was:" << std::endl;
- expr.print(std::cout, report);
- std::cout << std::endl << std::endl;
+ *out << std::endl;
+ *out << "--- Parsed tree ---" << std::endl;
+ expr.dump(*out);
- expr.compile(report);
+ *out << std::endl;
+ *out << "--- Calculated value ---" << std::endl;
+ expr.calc(report).print(*out);
+ *out << std::endl;
- std::cout << "Value expression after compiling:" << std::endl;
- expr.dump(std::cout);
- std::cout << std::endl;
+ return 0;
+ }
+ else if (verb == "compile") {
+ expr_t expr(*arg);
- std::cout << "Value expression is now:" << std::endl;
- expr.print(std::cout, report);
- std::cout << std::endl << std::endl;
+ *out << "Value expression as input: " << *arg << std::endl;
+ *out << "Value expression as parsed: ";
+ expr.print(*out, report);
+ *out << std::endl;
- std::cout << "Result of calculation: ";
- }
+ *out << std::endl;
+ *out << "--- Parsed tree ---" << std::endl;
+ expr.dump(*out);
- std::cout << expr.calc(report).strip_annotations() << std::endl;
+ expr.compile(report);
+ *out << std::endl;
+ *out << "--- Compiled tree ---" << std::endl;
+ expr.dump(*out);
+
+ *out << std::endl;
+ *out << "--- Calculated value ---" << std::endl;
+ expr.calc(report).print(*out);
+ *out << std::endl;
+
+ return 0;
+ }
+ else if (verb == "eval") {
+ expr_t expr(*arg);
+ *out << expr.calc(report).strip_annotations() << std::endl;
return 0;
}
diff --git a/op.cc b/op.cc
index 5a8c0ea9..0eaf386c 100644
--- a/op.cc
+++ b/op.cc
@@ -754,9 +754,12 @@ value_t expr_t::op_t::calc(scope_t& scope)
return ! left()->calc(scope);
case O_AND:
- return left()->calc(scope) && right()->calc(scope);
+ return ! left()->calc(scope) ? value_t(false) : right()->calc(scope);
case O_OR:
- return left()->calc(scope) || right()->calc(scope);
+ if (value_t temp = left()->calc(scope))
+ return temp;
+ else
+ return right()->calc(scope);
case O_COMMA: {
value_t result(left()->calc(scope));
@@ -976,7 +979,7 @@ void expr_t::op_t::dump(std::ostream& out, const int depth) const
{
out.setf(std::ios::left);
out.width(10);
- out << this << " ";
+ out << this;
for (int i = 0; i < depth; i++)
out << " ";
diff --git a/op.h b/op.h
index ec5273b0..bb832359 100644
--- a/op.h
+++ b/op.h
@@ -275,11 +275,12 @@ public:
unsigned long * start_pos;
unsigned long * end_pos;
- print_context_t(scope_t& _scope,
- const bool _relaxed = false,
+ // jww (2008-08-01): Is a scope needed here?
+ print_context_t(scope_t& _scope,
+ const bool _relaxed = false,
const ptr_op_t& _op_to_find = ptr_op_t(),
unsigned long * _start_pos = NULL,
- unsigned long * _end_pos = NULL)
+ unsigned long * _end_pos = NULL)
: scope(_scope), relaxed(_relaxed), op_to_find(_op_to_find),
start_pos(_start_pos), end_pos(_end_pos) {}
};
diff --git a/report.h b/report.h
index 619c4bdd..a492a9a4 100644
--- a/report.h
+++ b/report.h
@@ -240,7 +240,7 @@ public:
}
value_t option_bar(call_scope_t& args) {
std::cout << "This is bar: " << args[0] << std::endl;
- return NULL_VALUE;
+ return args[0];
}
//