aboutsummaryrefslogtreecommitdiff
path: root/driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver.c')
-rw-r--r--driver.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/driver.c b/driver.c
new file mode 100644
index 0000000..d89c412
--- /dev/null
+++ b/driver.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "ast.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;
+ }
+
+ exec_stmt(ast_root);
+ env_print();
+ free_ast(ast_root);
+
+ return EXIT_SUCCESS;
+}