Archived
1
0
Fork 0
This repository has been archived on 2023-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
SLOTH/src/main.cpp
Brandon Rozek 8dd2e789c0 struct->classes
Environment now has destructor
2018-09-28 21:54:24 -04:00

42 lines
No EOL
879 B
C++

#include <iostream>
#include <stdlib.h>
#include "sloth.hpp"
#include "shell.hpp"
void interpret_file(char* fileName);
/* the result variable */
Node* result;
int main(int argc, char* argv[]) {
if (argc == 1) {
start_shell();
} else if (argc == 2) {
interpret_file(argv[1]);
} else {
std::cout << "Incorrect number of arguments passed. Expected " << 0 << " or " << 1 << ", got " << argc - 1 << std::endl;
std::cout << "Usage: sloth [program_name]" << std::endl;
exit(-1);
}
}
void interpret_file(char* fileName) {
/* save stdin */
FILE* orig_stdin = stdin;
stdin = fopen(fileName, "r");
yyparse( );
/* restore stdin */
fclose(stdin);
stdin = orig_stdin;
// Interpret the AST
// print_tree(result, 0); // For debugging
Environment* env = new Environment();
eval_statement(result, env);
delete env;
delete result;
}