Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Интерпретатор / _sources / MyLanguage / Errors
.hpp#ifndef ERRORS_HPP_
#define ERRORS_HPP_
#include <exception>
#include <string>
#include <sstream>
namespace Parser_impl {
extern char* tokenName[];
class ParserException : public std::exception {
protected:
std::string whatStr;
public:
ParserException(const std::string& str = "") : whatStr(str) {}
virtual const char* what() const throw()
{
return whatStr.c_str();
}
virtual ~ParserException() throw () {}
};
class TokenParserException : public ParserException {
public:
TokenParserException(int line)
{
std::ostringstream os;
os << "Token parser exception: Bad char, line: " << line+1 << '!';
whatStr = os.str() ;
}
TokenParserException(int line, char bad )
{
std::ostringstream os;
os << "Token parser exception: Bad char: '" << bad << "', line: " << line+1 << '!';
whatStr = os.str() ;
}
TokenParserException(int line, char bad, char expect )
{
std::ostringstream os;
os << "Token parser exception: Bad char: '" << bad << "', expected: '"
<< expect << "', line: " << line+1 << '!';
whatStr = os.str() ;
}
TokenParserException(const std::string& str)
{
whatStr = "Token parser exception: ";
whatStr += str;
}
};
class SyntacticParserException : public ParserException {
public:
SyntacticParserException(const std::string& str)
{
whatStr = "Parser exception: ";
whatStr += str;
}
SyntacticParserException(const std::string& str, int line)
{
std::ostringstream os;
os << "Parser exception: " << str << ", line: " << line+1 << '!';
whatStr = os.str() ;
}
SyntacticParserException(int tok, int line)
{
std::ostringstream os;
os << "Parser exception: Expected '" << tokenName[tok] << "', line: " << line+1 << '!';
whatStr = os.str() ;
}
};
class RuntimeException : public ParserException {
public:
RuntimeException(const std::string& str)
{
whatStr = "Runtime exception: ";
whatStr += str;
}
};
}
#endif /*ERRORS_HPP_*/
Соседние файлы в папке MyLanguage