Skip to content
Snippets Groups Projects
Commit 7992925b authored by Paweł Kędzia's avatar Paweł Kędzia
Browse files

Fixed grammar. New operator (equals)

parent 44e76307
No related branches found
No related tags found
No related merge requests found
#ifndef LIBWCCL_ANTLRPARSERRESULT_H
#define LIBWCCL_ANTLRPARSERRESULT_H
#include <boost/shared_ptr.hpp>
#include <libwccl/variables.h>
#include <libwccl/ops/functions.h>
template<class T>
class ANTLRParserResult
{
public:
ANTLRParserResult() {
this->variables.reset(new Wccl::Variables());
}
boost::shared_ptr<Wccl::Variables> variables;
boost::shared_ptr<Wccl::Function<T> > op;
};
#endif // ANTLRPARSERRESULT_H
......@@ -22,7 +22,7 @@ Parser::~Parser()
* @arg str writed operator
* @retrun boost::shared_ptr<Wccl::StrSet>
*/
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > Parser::parseStringOperator(
boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > Parser::parseStringOperator(
const std::string& str) const
{
std::stringstream ss (std::stringstream::in | std::stringstream::out);
......@@ -37,7 +37,7 @@ boost::shared_ptr<Wccl::Function<Wccl::StrSet> > Parser::parseStringOperator(
* @arg istr input stream with writed operator
* @return boost::shared_ptr<Wccl::Function<Wccl::StrSet> > to created operator
*/
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > Parser::parseStringOperator(
boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > Parser::parseStringOperator(
std::istream& istr) const
{
ANTLRLexer lexer(istr);
......@@ -53,7 +53,7 @@ boost::shared_ptr<Wccl::Function<Wccl::StrSet> > Parser::parseStringOperator(
* @arg str writed predicate(s)
* @return boost::shared_ptr<Wccl::Function<Wccl::Bool> > to created predicate
*/
boost::shared_ptr<Wccl::Function<Wccl::Bool> > Parser::parsePredicate(
boost::shared_ptr<ANTLRParserResult<Wccl::Bool> > Parser::parsePredicate(
const std::string& str) const
{
std::stringstream ss (std::stringstream::in | std::stringstream::out);
......@@ -67,7 +67,7 @@ boost::shared_ptr<Wccl::Function<Wccl::Bool> > Parser::parsePredicate(
* @arg istr input stream with writed predicate
* @return boost::shared_ptr<Wccl::Function<Wccl::Bool> > to created predicate
*/
boost::shared_ptr<Wccl::Function<Wccl::Bool> > Parser::parsePredicate(
boost::shared_ptr<ANTLRParserResult<Wccl::Bool> > Parser::parsePredicate(
std::istream& istr) const
{
ANTLRLexer lexer(istr);
......@@ -77,33 +77,32 @@ boost::shared_ptr<Wccl::Function<Wccl::Bool> > Parser::parsePredicate(
}
// ----------------------------------------------------------------------------
/**
* @desc Parse values writed in std::string. Converts writed values
* to istream and calling parseValue with istream
* @arg str writed value(s)
* @retrun boost::shared_ptr<Wccl::Value>
* @desc Parse sym set operator writed in std::string. Converts writed operator
* to istream and calling parseSymSetOperator with istream
* @arg str writed operator
* @retrun boost::shared_ptr<Wccl::Function<Wccl::TSet> >
*/
/*
boost::shared_ptr<Wccl::Value> Parser::parseValue(const std::string& str) const
boost::shared_ptr<ANTLRParserResult<Wccl::TSet> > Parser::parseSymSetOperator(
const std::string& str) const
{
std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str;
return this->parseValue(ss);
return this->parseSymSetOperator(ss);
}
*/
/**
* @desc Parse values. Runs parse_values rule in the parser grammar.
* @arg istr input stream with writed values
* @return boost::shared_ptr<Wccl::Value> to created value
* @desc Parse sym set operator. Runs parse_sym_set_operator rule
* in the parser grammar.
* @arg istr input stream with writed operator
* @return boost::shared_ptr<Wccl::Function<Wccl::TSet> > to created operator
*/
/*
boost::shared_ptr<Wccl::Value> Parser::parseValue(std::istream& istr) const
boost::shared_ptr<ANTLRParserResult<Wccl::TSet> > Parser::parseSymSetOperator(
std::istream& istr) const
{
ANTLRLexer lexer(istr);
ANTLRParser parser(lexer);
return parser.parse_values();
return parser.parse_sym_set_operator();
}
*/
......@@ -4,6 +4,8 @@
#include "ANTLRLexer.hpp"
#include "ANTLRParser.hpp"
#include <iostream>
// ----------------------------------------------------------------------------
#include <sstream>
......@@ -16,6 +18,7 @@
// exceptions
#include <libwccl/parser/ParserException.h>
#include <libwccl/parser/ANTLRParserResult.h>
// ----------------------------------------------------------------------------
......@@ -25,17 +28,26 @@ public:
~Parser();
// ---------------------------------------------------------------------------
// methods for parsing string operator
boost::shared_ptr<Wccl::Function<Wccl::StrSet> >
// methods for parsing string operators
boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> >
parseStringOperator(const std::string&) const;
boost::shared_ptr<Wccl::Function<Wccl::StrSet> >
boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> >
parseStringOperator(std::istream&) const;
// methods for parsing predicates (returns bool)
boost::shared_ptr<Wccl::Function<Wccl::Bool> >
// ---------------------------------------------------------------------------
// methods for parsing bool operators
boost::shared_ptr<ANTLRParserResult<Wccl::Bool> >
parsePredicate(const std::string&) const;
boost::shared_ptr<Wccl::Function<Wccl::Bool> >
boost::shared_ptr<ANTLRParserResult<Wccl::Bool> >
parsePredicate(std::istream&) const;
// ---------------------------------------------------------------------------
// methods for parsing bool operators
boost::shared_ptr<ANTLRParserResult<Wccl::TSet> >
parseSymSetOperator(const std::string&) const;
boost::shared_ptr<ANTLRParserResult<Wccl::TSet> >
parseSymSetOperator(std::istream&) const;
private:
const Corpus2::Tagset &tagset;
};
......
This diff is collapsed.
#include <cstdlib>
#include <libwccl/values/strset.h>
#include <libwccl/parser/Parser.h>
// ----------------------------------------------------------------------------
/**
* @desc It's simple command line tester for testing predicates
*/
int main()
{
std::string str_in;
Corpus2::Tagset tagset;
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 -- "
<< "haven't got StrSet object in boost::shared_ptr!"
<< std::endl;
}
}
else {
std::cerr << "Problem while parsing -- "
<< "haven't got Function<Wccl::StrSet> object in "
<< "boost::shared_ptr!" << std::endl;
}
}
catch (antlr::MismatchedTokenException &e) {
std::cerr << e.getMessage() << std::endl;
}
catch (...) {
std::cerr << "[N] Syntax error!" << std::endl;
}
}
}
return 0;
}
#include <cstdlib>
#include <boost/shared_ptr.hpp>
#include <libwccl/values/strset.h>
#include <libwccl/parser/Parser.h>
#include <libwccl/parser/ANTLRParserResult.h>
// ----------------------------------------------------------------------------
/**
* @desc It's simple command line tester for testing string operators
*/
int main()
{
std::string str_in;
Corpus2::Tagset tagset;
Parser parser(tagset);
boost::shared_ptr<Wccl::StrSet> retStr;
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > retOp;
boost::shared_ptr<const Wccl::StrSet> retVal;
boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > retOp;
boost::shared_ptr<Corpus2::Sentence> sentence;
Wccl::SentenceContext sc(sentence);
if (system("clear")) {
//
}
std::cerr << "Simple command line tester for testing string operators"
<< std::endl;
while (1) {
std::cerr << "Enter a string operator expression: ";
......@@ -38,25 +46,27 @@ int main()
retOp = parser.parseStringOperator(str_in);
if (retOp.get()) {
if ((retStr = retOp->apply(sc)).get()) {
std::cerr << "Parsed expression: " << retStr->to_raw_string() << std::endl;
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 -- haven't got StrSet object in boost::shared_ptr!" << std::endl;
std::cerr << "Problem while parsing -- "
<< "haven't got StrSet object in boost::shared_ptr!"
<< std::endl;
}
}
else {
std::cerr << "Problem while parsing -- haven't got Function<Wccl::StrSet> object in boost::shared_ptr!" << std::endl;
std::cerr << "Problem while parsing -- "
<< "haven't got Function<Wccl::StrSet> object in "
<< "boost::shared_ptr!" << std::endl;
}
}
catch (antlr::MismatchedTokenException &e) {
std::cerr << "Mismatch token exception!" << std::endl;
std::cerr << e.getMessage() << std::endl;
}
/*
catch (antlr::TokenStreamRecognitionException &e) {
std::cerr << "[2] Syntax error!" << std::endl;
}
*/
catch (...) {
std::cerr << "[N] Syntax error!" << std::endl;
}
......
#include <cstdlib>
#include <libwccl/values/tset.h>
#include <libwccl/parser/Parser.h>
#include <libwccl/parser/ANTLRParserResult.h>
// ----------------------------------------------------------------------------
/**
* @desc It's simple command line tester for testing tagset operators
*/
int main()
{
std::string str_in;
Corpus2::Tagset tagset;
Parser parser(tagset);
boost::shared_ptr<const Wccl::TSet> retVal;
boost::shared_ptr<ANTLRParserResult<Wccl::TSet> > 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.parseSymSetOperator(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 -- "
<< "haven't got StrSet object in boost::shared_ptr!"
<< std::endl;
}
}
else {
std::cerr << "Problem while parsing -- "
<< "haven't got Function<Wccl::StrSet> object in "
<< "boost::shared_ptr!" << std::endl;
}
}
catch (antlr::MismatchedTokenException &e) {
std::cerr << e.getMessage() << std::endl;
}
catch (...) {
std::cerr << "[N] Syntax error!" << std::endl;
}
}
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment