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

Several operators has been implemented (and fixed), but still is many "non...

Several operators has been implemented (and fixed), but still is many "non deterministics" parser warnings.
parent d1763769
Branches
No related merge requests found
......@@ -69,6 +69,18 @@ private:
return UnicodeString::fromUTF8(((antlr::Token*)rstr)->getText()).unescape();
}
//
const UnicodeString str_token_ref_to_ustring(antlr::RefToken& rstr) const {
UnicodeString ret_ustr, ustr = token_ref_to_ustring(rstr);
if (ustr.length() < 3) {
return "";
}
ustr.extract(1, ustr.length() - 2, ret_ustr);
return ret_ustr;
}
//
const std::string token_ref_to_std_string(antlr::RefToken& rstr) const {
return (((antlr::Token*)rstr)->getText());
}
......@@ -80,7 +92,6 @@ private:
// TODO
// - base, orth
// - po dodaniu reguly condit_sym jest niejednoznacznosc w in/inter/equal!!
// - equal do bool
///////////////////////////////////////////////////////////////////////////////
......@@ -140,10 +151,10 @@ parse_sym_set_operator
str_set_value_in
[boost::shared_ptr<Wccl::StrSet>& s_set]
: v1: STRING {
s_set->insert(token_ref_to_ustring(v1));
s_set->insert(str_token_ref_to_ustring(v1));
}
| v2: STRING COMMA str_set_value_in [s_set] {
s_set->insert(token_ref_to_ustring(v2));
s_set->insert(str_token_ref_to_ustring(v2));
}
;
// string set, called as unnamed (temporary) StrSet:
......@@ -247,6 +258,7 @@ position_value
position_variable_acc
[Wccl::Variables& vars]
returns [boost::shared_ptr<Wccl::VariableAccessor<Wccl::Position> > pos_acc]
// : DOLLAR POS_PREFIX n: SYMBOL {
: DOLLAR n: SYMBOL {
vars.get_put<Wccl::Position>(token_ref_to_std_string(n));
......@@ -274,6 +286,7 @@ position_ref_variable
[Wccl::Variables& vars]
: DOLLAR p_ref: INT n: SYMBOL {
// TODO
vars.get_put<Wccl::Position>(token_ref_to_std_string(n));
}
;
// ----------------------------------------------------------------------------
......@@ -377,8 +390,6 @@ setvar_op
;
// Implementations of setvar:
// ----------------------------------------------------------------------------
// setvar dla position przyjmuje position_ref_variable -> TODO sprawdzic dlaczego
// gramatyka nie pokrywa "setvar" LPAREN position COMMA position_value RPAREN
setvar_pos
[Wccl::Variables& vars]
returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op]
......@@ -465,16 +476,20 @@ condit_sym
boost::shared_ptr<Wccl::Function<Wccl::TSet> > p_true, p_false;
}
: "if" LPAREN test = logical_predicates [vars] COMMA
p_true = sym_set_operators [vars] COMMA
p_false = sym_set_operators [vars] {
op.reset(new Wccl::Conditional<Wccl::TSet>(test, p_true, p_false));
}
/*
p_true = sym_set_operators [vars]
(COMMA p_false = sym_set_operators [vars])?
{
if (p_false) {
op.reset(new Wccl::Conditional<Wccl::TSet>(test, p_true, p_false));
}
else {
op.reset(new Wccl::Conditional<Wccl::TSet>(test, p_true));
}
}
| Q_MARK p_true = sym_set_operators [vars]
Q_MARK test = logical_predicates [vars] {
op.reset(new Wccl::Conditional<Wccl::TSet>(test, p_true));
}
*/
;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
......@@ -585,16 +600,20 @@ condit_str
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > p_true, p_false;
}
: "if" LPAREN test = logical_predicates [vars] COMMA
p_true = string_operators [vars] COMMA
p_false = string_operators [vars] {
op.reset(new Wccl::Conditional<Wccl::StrSet>(test, p_true, p_false));
p_true = string_operators [vars]
(COMMA p_false = string_operators [vars])?
{
if (p_false) {
op.reset(new Wccl::Conditional<Wccl::StrSet>(test, p_true, p_false));
}
else {
op.reset(new Wccl::Conditional<Wccl::StrSet>(test, p_true));
}
}
/*
| Q_MARK p_true = string_operators [vars]
Q_MARK test = logical_predicates [vars] {
op.reset(new Wccl::Conditional<Wccl::StrSet>(test, p_true));
}
*/
;
// ----------------------------------------------------------------------------
......@@ -688,24 +707,17 @@ 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::TSet> > t1, t2;
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > s1, s2;
}
: "in" LPAREN ss1 = string_operators [vars] COMMA
ss2 = string_operators [vars] RPAREN {
op.reset(new Wccl::IsSubsetOf<Wccl::StrSet>(ss1, ss2));
: "in" LPAREN t1 = sym_set_operators [vars] COMMA
t2 = sym_set_operators [vars] RPAREN {
op.reset(new Wccl::IsSubsetOf<Wccl::TSet>(t1, t2));
}
/*
| "in" LPAREN ts1 = sym_set_operators [vars] COMMA
ts2 = sym_set_operators [vars] RPAREN {
op.reset(new Wccl::IsSubsetOf<Wccl::TSet>(ts1, ts2));
}
| "in" LPAREN p1 = position_operators [vars] COMMA
p2 = position_operators [vars] RPAREN {
// op.reset(new Wccl::IsSubsetOf(*p1.get(), *p2.get()));
| "in" LPAREN s1 = string_operators [vars] COMMA
s2 = string_operators [vars] RPAREN {
op.reset(new Wccl::IsSubsetOf<Wccl::StrSet>(s1, s2));
}
*/
;
// ----------------------------------------------------------------------------
......@@ -713,22 +725,16 @@ lpred_inter
[Wccl::Variables& vars]
returns [boost::shared_ptr<Wccl::Function<Wccl::Bool> > op]
{
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ss1, ss2;
boost::shared_ptr<Wccl::Function<Wccl::TSet> > ts1, ts2;
}
: "inter" LPAREN (
(ss1 = string_operators [vars] COMMA ss2 = string_operators [vars] RPAREN)
(ts1 = sym_set_operators [vars] COMMA ts2 = sym_set_operators [vars] RPAREN) |
) {
if (ss1) {
op.reset(new Wccl::Intersects<Wccl::StrSet>(ss1, ss2));
}
else if (ts1) {
op.reset(new Wccl::Intersects<Wccl::TSet>(ts1, ts2));
}
else {
assert(false);
}
boost::shared_ptr<Wccl::Function<Wccl::TSet> > t1, t2;
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > s1, s2;
}
: "inter" LPAREN s1 = string_operators [vars] COMMA
s2 = string_operators [vars] RPAREN {
op.reset(new Wccl::Intersects<Wccl::StrSet>(s1, s2));
}
| "inter" LPAREN t1 = sym_set_operators [vars] COMMA
t2 = sym_set_operators [vars] RPAREN {
op.reset(new Wccl::Intersects<Wccl::TSet>(t1, t2));
}
;
......@@ -737,24 +743,27 @@ 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::TSet> > t1, t2;
boost::shared_ptr<Wccl::Function<Wccl::Bool> > b1, b2;
boost::shared_ptr<Wccl::Function<Wccl::StrSet> > s1, s2;
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 s1 = string_operators [vars] COMMA
s2 = string_operators [vars] RPAREN {
op.reset(new Wccl::Equals<Wccl::StrSet>(s1, s2));
}
/*
| "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 t1 = sym_set_operators [vars] COMMA
t2 = sym_set_operators [vars] RPAREN {
op.reset(new Wccl::Equals<Wccl::TSet>(t1, t2));
}
| "equal" LPAREN p1 = position_operators [vars] COMMA
p2 = position_operators [vars] RPAREN {
op.reset(new Wccl::Equals<Wccl::Position>(p1, p2));
}
*/
| "equal" LPAREN b1 = logical_predicates [vars] COMMA
b2 = logical_predicates [vars] RPAREN {
op.reset(new Wccl::Equals<Wccl::Bool>(b1, b2));
}
;
// ----------------------------------------------------------------------------
......@@ -794,9 +803,15 @@ condit_bool
boost::shared_ptr<Wccl::Function<Wccl::Bool> > test, p_true, p_false;
}
: "if" LPAREN test = logical_predicates [vars] COMMA
p_true = logical_predicates [vars] COMMA
p_false = logical_predicates [vars] {
op.reset(new Wccl::Conditional<Wccl::Bool>(test, p_true, p_false));
p_true = logical_predicates [vars]
(COMMA p_false = logical_predicates [vars])?
{
if (p_false) {
op.reset(new Wccl::Conditional<Wccl::Bool>(test, p_true, p_false));
}
else {
op.reset(new Wccl::Conditional<Wccl::Bool>(test, p_true));
}
}
| Q_MARK p_true = logical_predicates [vars]
Q_MARK test = logical_predicates [vars] {
......@@ -888,12 +903,14 @@ options {
: "b:"
;
/*
POS_PREFIX
options {
paraphrase = "Bool prefix";
paraphrase = "Position prefix";
}
: "p:"
;
*/
LBRACKET
options {
......@@ -964,34 +981,8 @@ options {
testLiterals = true;
}
: ('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'
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment