aboutsummaryrefslogtreecommitdiff
path: root/driver.c
blob: 6b0909e82471417016a00b46e961292bc6e75235 (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
31
#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;
  }
  
  Env *env = NULL;
  exec_stmt(&env, ast_root);
  env_print(env);
  free_ast(ast_root);
  
  return EXIT_SUCCESS;
}