Select Git revision
LibFindMacros.cmake
bool_main.cpp 2.07 KiB
#include <cstdlib>
#include <libwccl/values/bool.h>
#include <libwccl/parser/Parser.h>
#include <libwccl/parser/ANTLRParserResult.h>
#include <antlr/NoViableAltException.hpp>
#include <antlr/MismatchedTokenException.hpp>
// ----------------------------------------------------------------------------
/**
* @desc It's simple command line tester for testing predicates
*/
int main()
{
std::string str_in;
Corpus2::Tagset tagset;
Wccl::Parser parser(tagset);
boost::shared_ptr<const Wccl::Bool> retVal;
boost::shared_ptr<ANTLRParserResult<Wccl::Bool> > retOp;
boost::shared_ptr<Corpus2::Sentence> sentence;
Wccl::SentenceContext sc(sentence);
if (system("clear")) {
//
}
std::cerr << "Simple command line tester for testing bool operators"
<< std::endl;
while (1) {
std::cerr << "Enter a bool operator expression: ";
getline(std::cin, str_in);
if (str_in == "clear" || str_in == "cls") {
if (system("clear")) {
//
}
}
else if (str_in == "exit" || str_in == "quit") {
break;
}
else {
try {
retOp = parser.parsePredicate(str_in);
if (retOp.get()) {
Wccl::FunExecContext cx(sc, retOp->variables);
if ((retVal = retOp->op->apply(cx)).get()) {
std::cerr << "Parsed expression: " << retVal->to_raw_string()
<< std::endl;
}
else {
std::cerr << "Problem while parsing -- Bool is NULL!" << std::endl;
}
}
else {
std::cerr << "Problem while parsing -- "
<< "Function<Wccl::Bool> is NULL!" << std::endl;
}
}
catch (antlr::MismatchedTokenException &e) {
std::cerr << e.getFileLineColumnString()
<< " " << e.getMessage() << std::endl;
} catch(antlr::NoViableAltException &e) {
std::cerr << e.getFileLineColumnString()
<< " " << e.getMessage() << std::endl;
} catch (Wccl::InvalidVariableName &e) {
std::cerr << "Wccl::InvalidVariableName" << std::endl;
} catch (Wccl::VariableTypeMismatch &e) {
std::cerr << "Wccl::VariableTypeMismatch" << std::endl;
} catch (...) {
std::cerr << "[N] Syntax error!" << std::endl;
}
}
}
return 0;
}