#include <iostream>
#include "ast.h"
#include "environment.h"
#include "error.h"
#include "prelude.h"

using namespace std;


int main(){
	Environment env;
	env.load(prelude);
	// cerr<<"Global env = "<<&env<<endl;

	string line;
	cout<<"> ";
	while(getline(cin,line)){
		try {
			AST parsed(line);
			cerr<<"Parsed: "<<parsed<<endl;
			const AST &res=env.run(parsed);
			cout<<res<<endl;
		} catch(runtime_error e){
			cerr<<"\x1B[1mError: "<<e.what()<<"\x1B[0m"<<endl;
		}
		cout<<"> ";
	}
	return 0;
}