summaryrefslogtreecommitdiffstats
path: root/vespalib/src/apps/eval_expr/eval_expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/apps/eval_expr/eval_expr.cpp')
-rw-r--r--vespalib/src/apps/eval_expr/eval_expr.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/vespalib/src/apps/eval_expr/eval_expr.cpp b/vespalib/src/apps/eval_expr/eval_expr.cpp
new file mode 100644
index 00000000000..9d3f0992867
--- /dev/null
+++ b/vespalib/src/apps/eval_expr/eval_expr.cpp
@@ -0,0 +1,27 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/fastos/fastos.h>
+#include <vespa/vespalib/eval/function.h>
+#include <vespa/vespalib/eval/interpreted_function.h>
+
+using namespace vespalib::eval;
+
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <expr>\n", argv[0]);
+ fprintf(stderr, " the expression must be self-contained (no arguments)\n");
+ fprintf(stderr, " quote the expression to make it a single parameter\n");
+ fprintf(stderr, " use let to simulate parameters: let(x, 1, x + 3)\n");
+ return 1;
+ }
+ Function function = Function::parse({}, argv[1]);
+ if (function.has_error()) {
+ fprintf(stderr, "expression error: %s\n", function.get_error().c_str());
+ return 1;
+ }
+ InterpretedFunction::Context ctx;
+ InterpretedFunction interpreted(SimpleTensorEngine::ref(), function);
+ double result = interpreted.eval(ctx).as_double();
+ fprintf(stdout, "%.32g\n", result);
+ return 0;
+}