Скачиваний:
20
Добавлен:
01.05.2014
Размер:
1.32 Кб
Скачать
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <string>
#include <iterator>

#include "Parser.hpp"

using namespace std;

void printUsage()
{
	cerr << "Wrong parameters!" << endl << "Usage: interpreter.exe <file_with_script>" 
		<< endl;
	exit(1);
}


int tol(int ch)
{
	return tolower(ch);
}

int main(int argc, char **argv) 
{		
	
	string file;
	int i = 1;
	
	if (argc == 1 || argc >3)
		printUsage();
	
	if (argc == 3){
		
		string debug(argv[1]);		
		transform (debug.begin(), debug.end(), debug.begin(), tol );
		
		if (debug != "-debug")
			printUsage();
		Parser::debug = true;
		i =2;				
	}
	
	file = argv[i];
	
	try{
						
		std::ifstream fistream(file.c_str());
		if (!fistream) {
			std::cerr << "Can't open file '" << file << "'"  << std::endl;
			std::exit(1);
		}
				
		Parser::SyntaticParser syntaticParser;
		
		Parser::PolizProgram* p = syntaticParser.parse(fistream);
		
		Parser::PolizInterpreter interp(p);		
		int ret =  interp.run();				
		
		delete p;
	
		return ret;
	
	} catch (Parser::ParserException& e){
		std::cerr << e.what() << std::endl;
		std::exit(1);
			
	} catch(...) {
		std::cerr << "Unnown exception caught!";
		std::exit(1);
	}
	
	return 0;
}
Соседние файлы в папке MyLanguage