aboutsummaryrefslogtreecommitdiff
path: root/driver.c
blob: d89c41220a722f2b3bd25e9941770de433e8f7bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
}