Add output and fix two bugs.

This commit is contained in:
2019-08-26 21:05:44 -07:00
parent 7e40af4830
commit 2dd81cf07a
7 changed files with 116 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
#include "ast.hpp"
#include "parser.hpp"
#include "type.hpp"
#include <iostream>
void yy::parser::error(const std::string& msg) {
std::cout << "An error occured: " << msg << std::endl;
@@ -29,11 +30,27 @@ void typecheck_program(const std::vector<definition_ptr>& prog) {
for(auto& def : prog) {
def->typecheck_second(mgr, env);
}
for(auto& pair : env.names) {
std::cout << pair.first << ": ";
pair.second->print(mgr, std::cout);
std::cout << std::endl;
}
}
int main() {
yy::parser parser;
parser.parse();
for(auto& definition : program) {
definition_defn* def = dynamic_cast<definition_defn*>(definition.get());
if(!def) continue;
std::cout << def->name;
for(auto& param : def->params) std::cout << " " << param;
std::cout << ":" << std::endl;
def->body->print(1, std::cout);
}
typecheck_program(program);
std::cout << program.size() << std::endl;
}