diff --git a/libwccl/parser/ANTLRParserResult.h b/libwccl/parser/ANTLRParserResult.h new file mode 100644 index 0000000000000000000000000000000000000000..c60f43b8a78c3223f2d282828046d37ef296c630 --- /dev/null +++ b/libwccl/parser/ANTLRParserResult.h @@ -0,0 +1,21 @@ +#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 diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index 8f6036ec7f93bb38e36a5ea35121aa4047e515bd..5bcdb235bff2ba06aff77e8d6a5dcb6206085618 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -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); @@ -32,12 +32,12 @@ boost::shared_ptr<Wccl::Function<Wccl::StrSet> > Parser::parseStringOperator( } /** - * @desc Parse string operator. Runs parse_string_operator rule + * @desc Parse string operator. Runs parse_string_operator rule * in the parser grammar. * @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(); } -*/ diff --git a/libwccl/parser/Parser.h b/libwccl/parser/Parser.h index 4b0177bef21a042003531c2b3824a7672c971af9..1cbb11cfa8bbfc25dcb2c2edf8021e9ec93b038b 100644 --- a/libwccl/parser/Parser.h +++ b/libwccl/parser/Parser.h @@ -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,16 +28,25 @@ public: ~Parser(); // --------------------------------------------------------------------------- - // methods for parsing string operator - boost::shared_ptr<Wccl::Function<Wccl::StrSet> > - parseStringOperator(const std::string&) const; - boost::shared_ptr<Wccl::Function<Wccl::StrSet> > - parseStringOperator(std::istream& ) const; - // methods for parsing predicates (returns bool) - boost::shared_ptr<Wccl::Function<Wccl::Bool> > - parsePredicate(const std::string&) const; - boost::shared_ptr<Wccl::Function<Wccl::Bool> > - parsePredicate(std::istream& ) const; + // methods for parsing string operators + boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > + parseStringOperator(const std::string&) const; + boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > + parseStringOperator(std::istream&) const; + + // --------------------------------------------------------------------------- + // methods for parsing bool operators + boost::shared_ptr<ANTLRParserResult<Wccl::Bool> > + parsePredicate(const std::string&) const; + 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; diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index 7818058d8e709b046b5ed79b25e816c5a61dedfe..82a38771772f56d53403fa53bfb1d124a40f401f 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -21,15 +21,24 @@ header { #include <libwccl/ops/nor.h> #include <libwccl/ops/and.h> #include <libwccl/ops/affix.h> + #include <libwccl/ops/regex.h> + #include <libwccl/ops/equals.h> #include <libwccl/ops/toupper.h> #include <libwccl/ops/tolower.h> #include <libwccl/ops/constant.h> #include <libwccl/ops/functions.h> + #include <libwccl/ops/vargetter.h> + #include <libwccl/ops/varsetter.h> + // #include <libwccl/ops/intersects.h> + // #include <libwccl/ops/issubsetof.h> #include <libwccl/ops/logicalpredicate.h> // Unicode String #include <unicode/uniset.h> #include <unicode/unistr.h> + + // + #include "ANTLRParserResult.h" } options { @@ -60,78 +69,75 @@ private: int token_ref_to_int(antlr::RefToken& rstr) { return atoi(((antlr::Token*)rstr)->getText().c_str()); } +} - // hepls function for processing - boost::shared_ptr<Wccl::Function<Wccl::StrSet> > get_str_set_expr( - boost::shared_ptr<Wccl::StrSet> ret_str_set) - { - boost::shared_ptr<Wccl::Function<Wccl::StrSet> > strset_expr( - new Wccl::Constant<Wccl::StrSet>(*ret_str_set.get()) - ); +// TODO +// - nie mozna utworzyc in/inter/equal z operatorem? +// - jak utworzyc TSet (dodac element do TSet) +// - nie mozna utworzy Const::Value i na tym robic specjalizowany reset? +// - base, orth - return strset_expr; - } +// Bylo boolean_v TRUE_VALUE. FALSE_VALE, a jest "True", "False" - bylo z +// regula lexera, a teraz jest wstawione na "sztywno" do gramatyki - Wccl::SentenceContext get_tmp_context() { - boost::shared_ptr<Corpus2::Sentence> sentence; - Wccl::SentenceContext sc(sentence); - - return sc; - } -} /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -// ---------------------------------------------------------------------------------- -// Start all rules -/* -start_rules -{ - std::string name = ""; -} - : values_ref [name] { fprintf(stderr, "%s\n", name.c_str()); } - | position_op [name] { fprintf(stderr, "%s\n", name.c_str()); } - | filters_op [name] { fprintf(stderr, "%s\n", name.c_str()); } - | setvar_op [name] { fprintf(stderr, "%s\n", name.c_str()); } - | boolean_op [name] { fprintf(stderr, "%s\n", name.c_str()); } - ; -*/ - +// "GLOBAL" RULES /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -// "GLOBAL" RULES // ---------------------------------------------------------------------------- // Rules for parsing string operators in scope (variables). // Returns boost::shared_ptr<Wccl::Function<Wccl::StrSet> > -parse_string_operator - returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > res] +parse_string_operator + returns [boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > res] { - Wccl::Variables vars; + res.reset(new ANTLRParserResult<Wccl::StrSet>()); + boost::shared_ptr<Wccl::Function<Wccl::StrSet> > op; } - : res = string_operators [vars] + : op = string_operators [*res->variables.get()] { + res->op = op; + } ; + // ---------------------------------------------------------------------------- // Rules for parsing predicates in scope (variables). // Returns boost::shared_ptr<Wccl::Function<Wccl::Bool> > parse_predicates - returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > res] + returns [boost::shared_ptr<ANTLRParserResult<Wccl::Bool> > res] { - Wccl::Variables vars; + res.reset(new ANTLRParserResult<Wccl::Bool>()); + boost::shared_ptr<Wccl::Function<Wccl::Bool> > op; } - : res = predicates [vars] + : op = predicates [*res->variables.get()] { + res->op = op; + } ; + // ---------------------------------------------------------------------------- // Rules for parsing values in scope (variables). -// Returns boost::shared_ptr<Wccl::Value> +// Returns boost::shared_ptr<Wccl::Function<Wccl::Value> > /* parse_values - returns [boost::shared_ptr<Wccl::Value> ret] + returns [boost::shared_ptr<Wccl::Function<Wccl::Value> > res] { Wccl::Variables vars; } - : ret = values [vars] + : res = values [vars] ; */ - +// ---------------------------------------------------------------------------- +// Rules for parsing tagset (symbol set) operators +// Returns boost::shared_ptr<Wccl::Function<Wccl::TSet> > +parse_sym_set_operator + returns [boost::shared_ptr<ANTLRParserResult<Wccl::TSet> > res] +{ + res.reset(new ANTLRParserResult<Wccl::TSet>()); + boost::shared_ptr<Wccl::Function<Wccl::TSet> > op; +} + : op = sym_set_operators [*res->variables.get()] { + res->op = op; + } +; /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // All values: @@ -140,146 +146,220 @@ parse_values /* values [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::Constant<Wccl::Value> > res] - : res = position [vars] - | res = str_set [vars] - | res = sym_set [vars] - | res = boolean [vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Value> > res] +{ + boost::shared_ptr<Wccl::Constant<Wccl::StrSet> > r_StrSet; + boost::shared_ptr<Wccl::Constant<Wccl::TSet> > r_TSet; + boost::shared_ptr<Wccl::Constant<Wccl::Bool> > r_Bool; + boost::shared_ptr<Wccl::Constant<Wccl::Position> > r_Pos; +} + : r_Pos = position [vars] // TODO { res = r_Pos; } + | r_TSet = sym_set [vars] + | r_Bool = boolean [vars] ; */ +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// VALUES +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // ---------------------------------------------------------------------------- -// Values reference => values + position_ref -// !! Cannot use for setvar(...,...) !! -/* -values_ref [std::string& name]: - values [name] - | position_ref [name] - | boolean_ref [name] - ; -*/ +// Single or muliple values in string set +str_set_v_in + [boost::shared_ptr<Wccl::StrSet>& s_set] + : v1: STRING { + s_set->insert(token_ref_to_ustring(v1)); + } + | v2: STRING COMMA str_set_v_in [s_set] { + s_set->insert(token_ref_to_ustring(v2)); + } +; +// string set, called as unnamed (temporary) StrSet: +// calls: [] ['a'] ['a', 'b'] ["a"] ["a", "b"] ['a', "b"] or variable $A +str_set_v + returns [boost::shared_ptr<Wccl::Constant<Wccl::StrSet> > val] +{ + boost::shared_ptr<Wccl::StrSet> set(new Wccl::StrSet); +} + : LBRACKET RBRACKET { + val.reset(new Wccl::Constant<Wccl::StrSet>(*set.get())); + } + | LBRACKET str_set_v_in [set] RBRACKET { + val.reset(new Wccl::Constant<Wccl::StrSet>(*set.get())); + } +; +// ---------------------------------------------------------------------------- +// element of sym set +sym_set_elem + [boost::shared_ptr<Wccl::TSet> &t_set] + : s1: SYMBOL { +// t_set->insert(token_ref_to_ustring(s1)); + } + | G_MARK s2: SYMBOL G_MARK { +// t_set->insert(token_ref_to_ustring(s2)); + } + + | s3: SYMBOL COMMA sym_set_elem [t_set] { +// t_set->insert(token_ref_to_ustring(s3)); + } + | G_MARK s4: SYMBOL G_MARK COMMA sym_set_elem [t_set] { +// t_set->insert(token_ref_to_ustring(s3)); + } +; + +// sym set in +sym_set_in + [boost::shared_ptr<Wccl::TSet> &set] + : sym_set_elem [set] +; +// sym set {} {a} {a, b} +sym_set_v + returns [boost::shared_ptr<Wccl::Constant<Wccl::TSet> > val] +{ + boost::shared_ptr<Wccl::TSet> set(new Wccl::TSet); +} + : LCURLY RCURLY { + val.reset(new Wccl::Constant<Wccl::TSet>(*set.get())); + } + | LCURLY sym_set_in [set] RCURLY { + val.reset(new Wccl::Constant<Wccl::TSet>(*set.get())); + } +; +// ---------------------------------------------------------------------------- +// boolean value: +boolean_v + returns [boost::shared_ptr<Wccl::Constant<Wccl::Bool> > val] + : TRUE_VALUE { val.reset(new Wccl::Constant<Wccl::Bool>(Wccl::Bool(true ))); } + | FALSE_VALUE { val.reset(new Wccl::Constant<Wccl::Bool>(Wccl::Bool(false))); } +; +// ---------------------------------------------------------------------------- +// position value: +position_v + returns [boost::shared_ptr<Wccl::Constant<Wccl::Position> > val] + : i: INT { + val.reset( + new Wccl::Constant<Wccl::Position>(Wccl::Position(token_ref_to_int(i))) + ); + } + | "begin" { + val.reset( + new Wccl::Constant<Wccl::Position>( + Wccl::Position(Wccl::Position::Begin) + ) + ); + } + | "end" { + val.reset( + new Wccl::Constant<Wccl::Position>( + Wccl::Position(Wccl::Position::End) + ) + ); + } + | "nowhere" { + val.reset( + new Wccl::Constant<Wccl::Position>( + Wccl::Position(Wccl::Position::Nowhere) + ) + ); + } +; + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// VARIABLES /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -// Position: $0name +// Position: $name // ---------------------------------------------------------------------------- -// TODO Cos nie lapie dobrze implementacja!!! Moze jakas dodatkowa -// TODO regula do lexera? position [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::Constant<Wccl::Position> > op] -{ - boost::shared_ptr<Wccl::Position> val; -} - : DOLLAR "0" n: SYMBOL { - val = vars.get_put<Wccl::Position>(token_ref_to_std_string(n)); - op.reset(new Wccl::Constant<Wccl::Position>(*val.get())); + returns [boost::shared_ptr<Wccl::VarGetter<Wccl::Position> > op] + : DOLLAR n: VAR_NAME { + vars.get_put<Wccl::Position>(token_ref_to_std_string(n)); + + Wccl::VariableAccesor<Wccl::Position> acc = + vars.create_accesor<Wccl::Position>(token_ref_to_std_string(n)); + + op.reset(new Wccl::VarGetter<Wccl::Position>(acc)); } ; // ---------------------------------------------------------------------------- // Position reference: $(0-9)+name // !! Cannot use for setvar(...,...) !! -/* position_ref [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::PositionRef> val] - : DOLLAR p_ref: INT n: SYMBOL { - val.reset( - new Wccl::PositionRef( - vars.get_put<Wccl::Position>(token_ref_to_std_string(n)), - token_ref_to_int(p_ref) - ) - ); + : DOLLAR p_ref: INT n: VAR_NAME { + // TODO } ; -*/ // ---------------------------------------------------------------------------- -// String set, call examples: $name, $Name, $_name, $_Name etc. +// String set, call examples: $name, $sName, $s_name, $s_Name etc. // This expression gets variable of tyme StrSet from string-named variable -// Returns Wccl::Function<Wccl::StrSet> from Set-variables +// Returns Wccl::VarGetter<Wccl::StrSet> from Set-variables str_set [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::Constant<Wccl::StrSet> > op] -{ - boost::shared_ptr<Wccl::StrSet> val; -} - : DOLLAR n: SYMBOL { - val = vars.get_put<Wccl::StrSet>(token_ref_to_std_string(n)); - op.reset(new Wccl::Constant<Wccl::StrSet>(*val.get())); + returns [boost::shared_ptr<Wccl::VarGetter<Wccl::StrSet> > op] + : DOLLAR STR_PREFIX n: VAR_NAME { + // get/put variable to variables + vars.get_put<Wccl::StrSet>(token_ref_to_std_string(n)); + + // makes accesor for value + Wccl::VariableAccesor<Wccl::StrSet> acc = + vars.create_accesor<Wccl::StrSet>(token_ref_to_std_string(n)); + + op.reset(new Wccl::VarGetter<Wccl::StrSet>(acc)); } ; // ---------------------------------------------------------------------------- -// Symbol set: $$name +// Symbol set: $tName sym_set [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::Constant<Wccl::TSet> > op] -{ - boost::shared_ptr<Wccl::TSet> val; -} - : DOLLAR DOLLAR n: SYMBOL { - val = vars.get_put<Wccl::TSet>(token_ref_to_std_string(n)); - op.reset(new Wccl::Constant<Wccl::TSet>(*val.get())); + returns [boost::shared_ptr<Wccl::VarGetter<Wccl::TSet> > op] + : DOLLAR TST_PREFIX n: VAR_NAME { + vars.get_put<Wccl::TSet>(token_ref_to_std_string(n)); + + Wccl::VariableAccesor<Wccl::TSet> acc = + vars.create_accesor<Wccl::TSet>(token_ref_to_std_string(n)); + + op.reset(new Wccl::VarGetter<Wccl::TSet>(acc)); } ; // ---------------------------------------------------------------------------- -// Bool: $?name +// Bool: $bName boolean [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::Constant<Wccl::Bool> > op] -{ - boost::shared_ptr<Wccl::Bool> val; -} - : DOLLAR Q_MARK n: SYMBOL { - val = vars.get_put<Wccl::Bool>(token_ref_to_std_string(n)); - op.reset(new Wccl::Constant<Wccl::Bool>(*val.get())); + returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] + : DOLLAR BOOL_PREFIX n: VAR_NAME { + vars.get_put<Wccl::Bool>(token_ref_to_std_string(n)); + + Wccl::VariableAccesor<Wccl::Bool> acc = + vars.create_accesor<Wccl::Bool>(token_ref_to_std_string(n)); + + op.reset(new Wccl::VarGetter<Wccl::Bool>(acc)); } ; -// Boolean $!name -/* -boolean_ref [std::string& name]: - DOLLAR E_MARK n1: SYMBOL { name = token_ref_to_std_string(n1); } - ; -*/ -///////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // OPERATORS -///////////////////////////////////////////////////////////////////////////////////// -// ---------------------------------------------------------------------------------- -// Positions operator -// TODO range przyjmuje postion_ref. ?? Zmienic na position ?? -/* -position_op [std::string& name] -{ - std::string r1, r2; -} - : "flex" LBRACKET position_ref [name] RBRACKET - | "range" LPAREN s: SYMBOL COMMA position_ref [r1] COMMA position_ref [r2] RPAREN - { name = ("Range opertator from " + token_ref_to_std_string(s) + " [" + r1 + ":" + r2 + "]!"); } - ; -*/ -// ---------------------------------------------------------------------------------- -// Filtering operator -/* -filters_op [std::string& name] -{ - std::string p, p2, e1, e2; -} - : "catflt" LPAREN position_ref [p] COMMA es_any [e1] COMMA es_any [e2] RPAREN - { name = ( "Catflt operator in position " + p + " for sets " + e1 + " " + e2); } - | "agrflt" LPAREN position_ref [p] COMMA position_ref [p2] COMMA es_any [e1] COMMA i: INT RPAREN - { name = ( "Agrflt operator p1 " + p + " p2 " + p2 + " for set " + e1 + " aggr_attrs " + token_ref_to_std_string(i)); } - ; -*/ - -// ---------------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // Setvar operator +// ---------------------------------------------------------------------------- /* -setvar_op [std::string& value] +setvar_op + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > ret] : setvar_pos [value] | setvar_bool [value] - | setvar_sset [value] + : ret = setvar_sset [vars] | setvar_tset [value] - ; +; */ - +// Implementations of setvar: +// ---------------------------------------------------------------------------- // setvar dla position przyjmuje position_ref -> TODO sprawdzic dlaczego // gramatyka nie pokrywa "setvar" LPAREN position COMMA position_v RPAREN /* @@ -293,10 +373,22 @@ setvar_bool [std::string& value] : "setvar" LPAREN boolean [value] COMMA boolean_v [value] RPAREN ; */ + /* -setvar_sset [std::string& value] - : "setvar" LPAREN str_set [value] COMMA str_set_v [value] RPAREN - ; +setvar_sset + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::VarSetter<Wccl::Bool> > op] +{ + boost::shared_ptr<Wccl::VarGetter<Wccl::StrSet> > ret_str_var; + boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret_str_op; +} + : "setvar" LPAREN ret_str_var = str_set [vars] COMMA + ret_str_op = string_operators [vars] RPAREN { +// VariableAccesor<Bool> acc_t = cx.variables()->create_accesor<Bool>("True_bool"); +// VarSetter<Bool> var_setter(acc_t, false_constant); +// Wccl::VariableAccesor<Wccl::StrSet> acc_t = vars->create_accesor<Wccl::StrSet>("True_bool"); + } +; */ /* setvar_tset [std::string& value] @@ -304,247 +396,86 @@ setvar_tset [std::string& value] ; */ -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// VALUES -/////////////////////////////////////////////////////////////////////////////// // ---------------------------------------------------------------------------- -// Single or muliple values in string set -str_set_v_in - [boost::shared_ptr<Wccl::StrSet>& s_set] - : v1: STRING { s_set->insert(token_ref_to_ustring(v1)); } - | v2: STRING COMMA str_set_v_in [s_set] { - s_set->insert(token_ref_to_ustring(v2)); - } +// ---------------------------------------------------------------------------- +// Symbol set (tagset) operators +// Returns boost::shared_ptr<Wccl::Function<Wccl::TSet> > +// ---------------------------------------------------------------------------- +sym_set_operators + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::TSet> > ret] + : ret = op_sym_set [vars] ; -// string set, called as unnamed (temporary) StrSet: -// calls: [] ['a'] ['a', 'b'] ["a"] ["a", "b"] ['a', "b"] or variable $A -str_set_v +// Implementations of symbol set operators: +// ---------------------------------------------------------------------------- +op_sym_set [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::Constant<Wccl::StrSet> > val] -{ - boost::shared_ptr<Wccl::StrSet> set(new Wccl::StrSet); -} - : LBRACKET RBRACKET { - val.reset(new Wccl::Constant<Wccl::StrSet>(*set.get())); - } - | LBRACKET str_set_v_in [set] RBRACKET { - val.reset(new Wccl::Constant<Wccl::StrSet>(*set.get())); - } - | val = str_set [vars] - ; + returns [boost::shared_ptr<Wccl::Function<Wccl::TSet> > op] + : op = sym_set [vars] + | op = sym_set_v +; + // ---------------------------------------------------------------------------- -// element of sym set -/* -sym_set_elem_s [std::string& value] - : s1: SYMBOL { value += token_ref_to_std_string(s1); } - | s2: SYMBOL COMMA sym_set_elem_s [value] { value += token_ref_to_std_string(s2); } - | s3: SYMBOL COMMA sym_set_elem_g [value] { value += token_ref_to_std_string(s3); } - ; -*/ -// element of sym set -/* -sym_set_elem_g [std::string& value] - : G_MARK s1: SYMBOL G_MARK { value += token_ref_to_std_string(s1); } - | G_MARK s2: SYMBOL G_MARK COMMA sym_set_elem_g [value] { value += token_ref_to_std_string(s2); } - | G_MARK s3: SYMBOL G_MARK COMMA sym_set_elem_s [value] { value += token_ref_to_std_string(s3); } - ; -*/ -// sym set in -/* -sym_set_in [std::string& value] - : sym_set_elem_s [value] - | sym_set_elem_g [value] - ; -*/ -// sym set {} {a} {a, b} -/* -sym_set_v [std::string& value] - : LCURLY RCURLY - | LCURLY sym_set_in [value] RCURLY - ; -*/ // ---------------------------------------------------------------------------- -// boolean: -boolean_v - [Wccl::Variables& vars] - returns [boost::shared_ptr<Wccl::Constant<Wccl::Bool> > val] - : "True" { val.reset(new Wccl::Constant<Wccl::Bool>(Wccl::Bool(true ))); } - | "False" { val.reset(new Wccl::Constant<Wccl::Bool>(Wccl::Bool(false))); } - | val = boolean [vars] -; +// Position operators +// Returns boost::shared_ptr<Wccl::Function<Wccl::Position> > // ---------------------------------------------------------------------------- -// position value: -/* -position_v [std::string& value] - : i: INT { value = token_ref_to_std_string(i); } - | "begin" { value = "begin"; } - | "end" { value = "end"; } - | "nowhere" { value = "nowhere"; } - | position [value] - ; -*/ +position_operators + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Position> > ret] + : ret = op_position [vars] +; +// Implementations of symbol set operators: // ---------------------------------------------------------------------------- -// internal values: -/* -v_literal [std::string& value] - : s1: STRING { value = token_ref_to_std_string(s1); } - | s2: SYMBOL { value = token_ref_to_std_string(s2); } - ; -*/ -///////////////////////////////////////////////////////////////////////////////////// -// constants -// set of values -/* -st::shared_ptr<Wccl::StrSet> ret]s_literal [std::string& v] - : LBRACKET ((v_literal[v]) (COMMA v_literal [v])*)? RBRACKET - ; -*/ - -// comma-separated predicates -/* -seq_et [std::string& v]: - et_any [v] (COMMA et_any [v])* - ; -*/ -/* -es_any [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::StrSet> ret] - s_literal [v] - | es_op [v] - ; -*/ -/* -et_bool [std::string& v]: - boolean [v] - | boolean_op [v] - ; -*/ - -// set relations -/* -et_set [std::string& v] -{ - std::string v1, v2; -} - : "in" LPAREN es_any [v1] COMMA es_any [v2] RPAREN { v = ("name " + v1 + " " + v2); } - | "inter" LPAREN es_any [v1] COMMA es_any [v2] RPAREN { v = ("inter " + v1 + " " + v2); } - | "equal" LPAREN es_any [v1] COMMA es_any [v2] RPAREN { v = ("equal " + v1 + " " + v2); } - ; -*/ -/* -et_string [std::string& v] - : "isbig" LPAREN es_any [v] RPAREN - | "hasnum" LPAREN es_any [v] RPAREN - ; -*/ -/* -et_action [std::string& v] -{ - std::string v1, v2; -} - : "delete" LPAREN et_any [v] RPAREN - | "select" LPAREN et_any [v] RPAREN - | "relabel" LPAREN es_any [v1] COMMA et_any [v2] RPAREN { v = ("relabel " + v1 + " " + v2); } - | "unify" LPAREN es_any [v1] COMMA i: INT RPAREN { v = ("relabel " + v1 + " on position " + token_ref_to_std_string(i)); } - | "mark" LPAREN s1: SYMBOL RPAREN { v = ("mark " + token_ref_to_std_string(s1)); } - | "unmark" LPAREN s2: SYMBOL RPAREN { v = ("unmark " + token_ref_to_std_string(s2)); } - | "startnew" LPAREN s3: SYMBOL RPAREN { v = ("startnew " + token_ref_to_std_string(s3)); } - | "lextend" LPAREN s4: SYMBOL RPAREN { v = ("lextend " + token_ref_to_std_string(s4)); } - | "rextend" LPAREN s5: SYMBOL RPAREN { v = ("rextend " + token_ref_to_std_string(s5)); } - ; -*/ -/* -et_iter [std::string& v] -{ - std::string v1, v2, v3, v4; -} - : "only" LPAREN position_ref [v1] COMMA position_ref [v2] COMMA position_ref [v3] COMMA et_any [v4] RPAREN - | "atleast" LPAREN position_ref [v1] COMMA position_ref [v2] COMMA position_ref [v3] COMMA et_any [v4] COMMA i:INT RPAREN - | "llook" LPAREN position_ref [v1] COMMA position_ref [v2] COMMA position_ref [v3] COMMA et_any [v4] RPAREN - | "rlook" LPAREN position_ref [v1] COMMA position_ref [v2] COMMA position_ref [v3] COMMA et_any [v4] RPAREN - | "setvar" LPAREN position_ref [v1] COMMA position_ref [v2] RPAREN - | "lskip" LPAREN position_ref [v1] COMMA SYMBOL COMMA position_ref [v2] COMMA et_any [v3] RPAREN - | "lphrase" LPAREN position_ref [v1] COMMA SYMBOL COMMA position_ref [v2] RPAREN - | "rphrase" LPAREN position_ref [v1] COMMA SYMBOL COMMA position_ref [v2] RPAREN - | "accept" LPAREN seq_et [v1] RPAREN - ; -*/ - -// predicates checking agreement -/* -et_agr [std::string& name] -{ - std::string p1, p2, v; -} - : "agr" LPAREN position_ref [p1] COMMA position_ref [p2] COMMA es_any [v] COMMA i1: INT RPAREN - | "agrpp" LPAREN position_ref [p1] COMMA position_ref [p2] COMMA es_any [v] COMMA i2: INT RPAREN - | "wagr" LPAREN position_ref [p1] COMMA position_ref [p2] COMMA es_any [v] COMMA i3: INT RPAREN - ; -*/ -/* -// annotation checking predicates -et_annot [std::string& v] - : "phrase" LPAREN position_ref [v] COMMA s: SYMBOL RPAREN - ; -*/ -/* -// constraints -et_any [std::string& v] - : et_bool [v] - | et_set [v] - | et_string [v] - | et_action [v] - | et_iter [v] - | et_agr [v] - | et_annot [v] - ; -*/ +op_position + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Position> > op] + : op = position [vars] + | op = position_v +; -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// Stiring operators returns boost::shared_ptr<Wccl::Function<Wccl::StrSet> > -/////////////////////////////////////////////////////////////////////////////// +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// Stiring operators +// Returns boost::shared_ptr<Wccl::Function<Wccl::StrSet> > // ---------------------------------------------------------------------------- string_operators [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret] - /* - : ret = op_orth [vars] - | ret = op_base [vars] - */ - : ret = op_lower [vars] - | ret = op_upper [vars] - | ret = op_affix [vars] - | ret = str_set_v [vars] + : ret = op_orth [vars] + | ret = op_base [vars] + | ret = op_lower [vars] + | ret = op_upper [vars] + | ret = op_affix [vars] + | ret = op_str_set [vars] ; // Implementations of string operators: // ---------------------------------------------------------------------------- -/* -op_orth [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::StrSet> ret] +op_orth + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret] { - boost::shared_ptr<Wccl::PositionRef> tmpPosRef; + // TODO } - : "orth" LBRACKET tmpPosRef = position_ref [vars] RBRACKET { - // TODO + : "orth" LBRACKET position_ref [vars] RBRACKET { + // ret = TODO } ; -*/ // ---------------------------------------------------------------------------- -/* -op_base [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::StrSet> ret] +op_base + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret] { - boost::shared_ptr<Wccl::PositionRef> tmpPosRef; + // TODO } - : "base" LBRACKET tmpPosRef = position_ref [vars] RBRACKET { - // TODO + : "base" LBRACKET position_ref [vars] RBRACKET { + // ret = TODO } ; -*/ // ---------------------------------------------------------------------------- -// returns boost::shared_ptr<Wccl::Function<Wccl::StrSet> > op_lower - [Wccl::Variables& vars] returns - [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret] + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret] { boost::shared_ptr<Wccl::Function<Wccl::StrSet> > o_ret; } @@ -574,11 +505,19 @@ op_affix ret.reset(new Wccl::Affix(o_ret, token_ref_to_int(offset))); } ; -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// Predicates returns boost::shared_ptr<Wccl::Function<Wccl::Bool> > -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// +// ---------------------------------------------------------------------------- +op_str_set + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > op] + : op = str_set [vars] + | op = str_set_v +; + +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// Logical predicates +// Returns boost::shared_ptr<Wccl::Function<Wccl::Bool> > +// ---------------------------------------------------------------------------- predicates [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > ret] @@ -589,18 +528,28 @@ predicates logical_predicates [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > ret] - : ret = lpred_and [vars] - | ret = lpred_or [vars] - | ret = lpred_nor [vars] - | ret = boolean_v [vars] + : ret = lpred_and [vars] + | ret = lpred_or [vars] + | ret = lpred_nor [vars] + | ret = lpred_bool [vars] + | ret = lpred_in [vars] + | ret = lpred_inter [vars] + | ret = lpred_eq [vars] + | ret = lpred_regex [vars] +// | ret = setvar_op [vars] ; +// ---------------------------------------------------------------------------- // comma-separated predicates logical_predicates_comma_sep [Wccl::Variables& vars] - returns [boost::shared_ptr<std::vector<boost::shared_ptr<Wccl::Function<Wccl::Bool> > > > ret_v] + returns [boost::shared_ptr< + std::vector<boost::shared_ptr<Wccl::Function<Wccl::Bool> > > + > ret_v] { boost::shared_ptr<Wccl::Function<Wccl::Bool> > pred; - ret_v.reset(new std::vector<boost::shared_ptr<Wccl::Function<Wccl::Bool> > >); + ret_v.reset( + new std::vector<boost::shared_ptr<Wccl::Function<Wccl::Bool> > > + ); } : pred = logical_predicates [vars] { ret_v->push_back(pred); @@ -622,6 +571,7 @@ lpred_and op.reset(new Wccl::And(ret_v)); } ; +// ---------------------------------------------------------------------------- lpred_or [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] @@ -634,6 +584,7 @@ lpred_or op.reset(new Wccl::Or(ret_v)); } ; +// ---------------------------------------------------------------------------- lpred_nor [Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] @@ -646,180 +597,298 @@ lpred_nor op.reset(new Wccl::Nor(ret_v)); } ; +// ---------------------------------------------------------------------------- +lpred_bool + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] + : op = boolean [vars] + | op = boolean_v +; +// ---------------------------------------------------------------------------- +lpred_in + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] +{ + boost::shared_ptr<Wccl::Function<Wccl::TSet> > ts1, ts2; + boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ss1, ss2; + boost::shared_ptr<Wccl::Function<Wccl::Position> > p1, p2; + boost::shared_ptr<Wccl::Function<Wccl::StrSet> > expr; +} + : "in" LPAREN ss1 = string_operators [vars] COMMA + ss2 = string_operators [vars] RPAREN { + op.reset( +// new Wccl::IsSubsetOf(*ss1.get(), *ss2.get()) + ); + } + | "in" LPAREN ts1 = sym_set_operators [vars] COMMA + ts2 = sym_set_operators [vars] RPAREN { + // op.reset(new Wccl::IsSubsetOf(*ts1.get(), *ts2.get())); + } + | "in" LPAREN p1 = position_operators [vars] COMMA + p2 = position_operators [vars] RPAREN { + // op.reset(new Wccl::IsSubsetOf(*p1.get(), *p2.get())); + } +; +// ---------------------------------------------------------------------------- +lpred_inter + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] +{ + boost::shared_ptr<Wccl::Function<Wccl::TSet> > ts1, ts2; + boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ss1, ss2; + boost::shared_ptr<Wccl::Function<Wccl::Position> > p1, p2; -// ---------------------------------------------------------------------------------- +} + : "inter" LPAREN ss1 = string_operators [vars] COMMA + ss2 = string_operators [vars] RPAREN { + // op.reset(new Wccl::Intersects(*ss1.get(), *ss2.get())); + } + | "inter" LPAREN ts1 = sym_set_operators [vars] COMMA + ts2 = sym_set_operators [vars] RPAREN { + // op.reset(new Wccl::Intersects(*ts1.get(), *ts2.get())); + } + | "inter" LPAREN p1 = position_operators [vars] COMMA + p2 = position_operators [vars] RPAREN { + // op.reset(new Wccl::Intersects(*p1.get(), *p2.get())); + } +; +// ---------------------------------------------------------------------------- +lpred_eq + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] +{ + boost::shared_ptr<Wccl::Function<Wccl::TSet> > ts1, ts2; + boost::shared_ptr<Wccl::Function<Wccl::Position> > p1, p2; + boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ss1, ss2; +} + : "equal" LPAREN ss1 = string_operators [vars] COMMA + ss2 = string_operators [vars] RPAREN { + op.reset(new Wccl::Equals<Wccl::StrSet>(ss1, ss2)); + } + | "equal" LPAREN ts1 = sym_set_operators [vars] COMMA + ts2 = sym_set_operators [vars] RPAREN { + op.reset(new Wccl::Equals<Wccl::TSet>(ts1, ts2)); + } + | "equal" LPAREN p1 = position_operators [vars] COMMA + p2 = position_operators [vars] RPAREN { + op.reset(new Wccl::Equals<Wccl::Position>(p1, p2)); + } +; + +// ---------------------------------------------------------------------------- +lpred_regex + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op] +{ + boost::shared_ptr<Wccl::Function<Wccl::StrSet> > expr; +} + : "regex" LPAREN expr = string_operators [vars] COMMA reg: STRING RPAREN { + op.reset(new Wccl::Regex(expr, token_ref_to_ustring(reg))); + } +; + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // ANTLR LEXER -// ---------------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// class ANTLRLexer extends Lexer; options { - k = 2; exportVocab = ANTLRExpr; charVocabulary = '\3'..'\377'; testLiterals = false; + k = 2; } STRING options { paraphrase = "a string"; } - : '"' (~'"')* '"' - | '\'' (~'\'')* '\'' - ; - -// STRING_APOS -// options { -// paraphrase = "a string without apostrophe"; -// } -// : (~'"')* -// ; - -// STRING_QUOT -// options { -// paraphrase = "a string without quotation"; -// } -// : (~'\'')* -// ; - + : '"' (~'"')* '"' + | '\'' (~'\'')* '\'' +; INT options { paraphrase = "Integer"; } - : ('-'|'+')?('0'..'9')+ - ; + : ('-'|'+')? ('0'..'9')+ +; QUOT_MARK options { paraphrase = "Quota mark"; -} - : '\'' - ; +} + : '\'' +; APOS_MARK options { paraphrase = "Aposptrophe mark"; } - : '"' - ; - + : '"' +; Q_MARK options { paraphrase = "Query mark"; } : '?' - ; +; E_MARK options { paraphrase = "Exclamanation mark"; } : '!' - ; +; G_MARK options { paraphrase = "Gravis mark"; } : '`' - ; +; + +STR_PREFIX +options { + paraphrase = "String prefix"; +} + : "s:" +; + +TST_PREFIX +options { + paraphrase = "Tag set (symbol) prefix"; +} + : "t:" +; + +BOOL_PREFIX +options { + paraphrase = "Bool prefix"; +} + : "b:" +; LBRACKET options { paraphrase = "'['"; } : '[' - ; +; RBRACKET options { paraphrase = "']'"; } : ']' - ; +; LPAREN options { paraphrase = "'('"; } : '(' - ; +; RPAREN options { paraphrase = "')'"; } : ')' - ; +; LCURLY options { paraphrase = "'{'"; } : '{' - ; +; RCURLY options { paraphrase = "'}'"; } : '}' - ; +; DOLLAR options { paraphrase = "'$'"; } : '$' - ; +; AT_MARK options { paraphrase = "'@'"; } : '@' - ; +; COMMA options { paraphrase = "','"; } : ',' - ; +; SYMBOL options { - paraphrase = "symbol"; + paraphrase = "Symbol"; testLiterals = true; } - : ( 'a'..'z' | 'A'..'Z' | '_' ) ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' )* - ; +// : ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')* + : ('a'..'z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')* +; + +VAR_NAME +options { + paraphrase = "Variable name"; +} + : ('A'..'Z') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')* +; + +TRUE_VALUE +options { + paraphrase = "True value"; +} + : "True" +; + +FALSE_VALUE +options { + paraphrase = "False value"; +} + : "False" +; WS - : - ( ' ' - | '\t' - | '\r' '\n' {newline(); } - | '\n' {newline(); } ) { $setType(antlr::Token::SKIP); } - ; + : ( ' ' + | '\t' + | '\r' '\n' { newline(); } + | '\n' { newline(); } + ) { $setType(antlr::Token::SKIP); } +; COMMENT options { paraphrase = "Comment"; } : "//" (~'\n')* '\n'{ $setType(antlr::Token::SKIP); newline(); } - ; +; HASH options { paraphrase = "'#'"; } : '#' - ; +; DSEPARATOR options { paraphrase = "':-'"; } : ":-" - ; +; diff --git a/wcclparser/bool_main.cpp b/wcclparser/bool_main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d41f0f1f9cb6389be23e4a1dcf54afbf0928e958 --- /dev/null +++ b/wcclparser/bool_main.cpp @@ -0,0 +1,77 @@ +#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; +} + diff --git a/wcclparser/strop_main.cpp b/wcclparser/strop_main.cpp index 4f4d48564eb98a588acc7c53eaaf1b8f2c19fba9..255e81d7639ef11e0b96ac2eda5353b107470bfd 100644 --- a/wcclparser/strop_main.cpp +++ b/wcclparser/strop_main.cpp @@ -1,67 +1,77 @@ #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); - while (1) { - std::cerr << "Enter a string operator expression: "; + if (system("clear")) { + // + } + + std::cerr << "Simple command line tester for testing string operators" + << std::endl; - getline(std::cin, str_in); + while (1) { + std::cerr << "Enter a string operator expression: "; - if (str_in == "clear" || str_in == "cls") { - if (system("clear")) { - // - } - } + 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 { + else { try { - retOp = parser.parseStringOperator(str_in); + 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; } - } - } + } + } return 0; } diff --git a/wcclparser/tagset_main.cpp b/wcclparser/tagset_main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1dd25c63b9b17485a80aabe6f11144f2a3ee0b2c --- /dev/null +++ b/wcclparser/tagset_main.cpp @@ -0,0 +1,78 @@ +#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; +} +