summaryrefslogtreecommitdiff
path: root/myfind/ast_evaluation/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'myfind/ast_evaluation/main.c')
-rw-r--r--myfind/ast_evaluation/main.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/myfind/ast_evaluation/main.c b/myfind/ast_evaluation/main.c
new file mode 100644
index 0000000..2794cd9
--- /dev/null
+++ b/myfind/ast_evaluation/main.c
@@ -0,0 +1,24 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "expression.h"
+#include "parser.h"
+
+int eval_expr(struct my_expr *expr);
+
+int main(int argc, char **argv)
+{
+ static struct my_expr *expr = NULL;
+
+ if (argc < 2)
+ errx(1, "Usage: %s <token> ([token] ...)", argv[0]);
+
+ unsigned args_length = argc - 1;
+ expr = parse_expr(argv + 1, args_length);
+
+ printf("%d\n", eval_expr(expr));
+
+ free_expr(expr);
+ return 0;
+}