aboutsummaryrefslogtreecommitdiff
path: root/src/driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/driver.c')
-rw-r--r--src/driver.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/driver.c b/src/driver.c
new file mode 100644
index 0000000..90ee892
--- /dev/null
+++ b/src/driver.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "interpreter.h"
+
+extern FILE *yyin;
+extern int yyparse(void);
+extern ASTNode *ast_root;
+
+int main(int argc, char **argv) {
+ if (argc > 1) {
+ yyin = fopen(argv[1], "r");
+ if (!yyin) {
+ perror(argv[1]);
+ return EXIT_FAILURE;
+ }
+ } else {
+ yyin = stdin;
+ }
+
+ if (yyparse() != 0) {
+ fprintf(stderr, "Parsing failed.\n");
+ return EXIT_FAILURE;
+ }
+
+ Env *env = NULL;
+ exec_stmt(&env, ast_root);
+ env_print(env);
+ free_ast(ast_root);
+
+ return EXIT_SUCCESS;
+}