2019-08-25 01:10:55 -07:00
|
|
|
#include "ast.hpp"
|
|
|
|
#include "parser.hpp"
|
|
|
|
#include "type.hpp"
|
|
|
|
|
|
|
|
void yy::parser::error(const std::string& msg) {
|
|
|
|
std::cout << "An error occured: " << msg << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern std::vector<definition_ptr> program;
|
|
|
|
|
2019-08-26 00:13:10 -07:00
|
|
|
void typecheck_program(const std::vector<definition_ptr>& prog) {
|
|
|
|
type_mgr mgr;
|
|
|
|
type_env env;
|
|
|
|
|
|
|
|
type_ptr int_type = type_ptr(new type_base("Int"));
|
|
|
|
type_ptr binop_type = type_ptr(new type_arr(
|
|
|
|
int_type,
|
|
|
|
type_ptr(new type_arr(int_type, int_type))));
|
|
|
|
|
|
|
|
env.bind("+", binop_type);
|
|
|
|
env.bind("-", binop_type);
|
|
|
|
env.bind("*", binop_type);
|
|
|
|
env.bind("/", binop_type);
|
|
|
|
|
|
|
|
for(auto& def : prog) {
|
|
|
|
def->typecheck_first(mgr, env);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto& def : prog) {
|
|
|
|
def->typecheck_second(mgr, env);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 01:10:55 -07:00
|
|
|
int main() {
|
|
|
|
yy::parser parser;
|
|
|
|
parser.parse();
|
2019-08-26 00:13:10 -07:00
|
|
|
typecheck_program(program);
|
2019-08-25 01:10:55 -07:00
|
|
|
std::cout << program.size() << std::endl;
|
|
|
|
}
|