From c70537dd0788451c4d581fd69454ac5b4bb78503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl> Date: Mon, 29 Nov 2010 12:33:37 +0100 Subject: [PATCH] Base oeprator has been added. --- libwccl/parser/grammar.g | 65 +++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index e0af47a..c20554e 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -25,6 +25,7 @@ header { #include <libwccl/ops/functions/bool/varsetter.h> #include <libwccl/ops/functions/strset/affix.h> + #include <libwccl/ops/functions/strset/getorth.h> #include <libwccl/ops/functions/strset/toupper.h> #include <libwccl/ops/functions/strset/tolower.h> @@ -37,6 +38,8 @@ header { #include <libwccl/ops/functions/bool/predicates/isinside.h> #include <libwccl/ops/functions/bool/predicates/isoutside.h> + #include <libwccl/ops/functions/position/relativeposition.h> + #include <libwccl/ops/functions/conditional.h> // Unicode String @@ -50,6 +53,8 @@ header { options { language = "Cpp"; genHashLines = false; +// namespace = "Wccl"; +// genHashLines = true; } // ---------------------------------------------------------------------------- @@ -252,7 +257,7 @@ boolean_value // returns boost::shared_ptr<Wccl::Position> position_literal returns [boost::shared_ptr<Wccl::Position> val] - : i: INT { + : i: UNSIGNED_INT { val.reset(new Wccl::Position(Wccl::Position(token_ref_to_int(i)))); } | "begin" { @@ -277,6 +282,16 @@ position_value } ; +// ---------------------------------------------------------------------------- +// Number may be unsigned or signed +number returns [int ret] +{ + ret = 0; +} + : s: SIGNED_INT { ret = token_ref_to_int(s); } + | u: UNSIGNED_INT { ret = token_ref_to_int(u); } +; + /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // VARIABLES @@ -310,6 +325,25 @@ position_variable } ; +// realtive position +relpos + [Wccl::Variables& vars] + returns [boost::shared_ptr<Wccl::Function<Wccl::Position> > ret] +{ + boost::shared_ptr<Wccl::Function<Wccl::Position> > pos; +} + : "relpos" + LPAREN + pos = op_position [vars] ("+" | "-") ofst: UNSIGNED_INT + RPAREN { + ret.reset(new Wccl::RelativePosition( + pos, + token_ref_to_int(ofst) + ) + ); + } +; + // ---------------------------------------------------------------------------- // String set, $s:name // This expression gets variable of the type StrSet from string-named variable @@ -537,6 +571,7 @@ position_operators returns [boost::shared_ptr<Wccl::Function<Wccl::Position> > ret] : ret = op_position [vars] ; + // Implementations of symbol set operators: // ---------------------------------------------------------------------------- op_position @@ -544,6 +579,7 @@ op_position returns [boost::shared_ptr<Wccl::Function<Wccl::Position> > op] : op = position_variable [vars] | op = position_value + | op = relpos [vars] ; // ---------------------------------------------------------------------------- @@ -568,10 +604,10 @@ op_orth [const Corpus2::Tagset& tagset, Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret] { - boost::shared_ptr<Wccl::VarGetter<Wccl::Position> > pos; + boost::shared_ptr<Wccl::Function<Wccl::Position> > pos; } - : "orth" LBRACKET pos = position_variable [vars] RBRACKET { - // ret = TODO + : "orth" LBRACKET pos = op_position [vars] RBRACKET { + ret.reset(new Wccl::GetOrth(pos)); } ; // ---------------------------------------------------------------------------- @@ -612,12 +648,13 @@ op_affix [const Corpus2::Tagset& tagset, Wccl::Variables& vars] returns [boost::shared_ptr<Wccl::Function<Wccl::StrSet> > ret] { + int offset = 0; boost::shared_ptr<Wccl::Function<Wccl::StrSet> > o_ret; } : "affix" LPAREN - o_ret = string_operators[tagset, vars] COMMA - offset: INT RPAREN { - ret.reset(new Wccl::Affix(o_ret, token_ref_to_int(offset))); + o_ret = string_operators[tagset, vars] COMMA offset = number + RPAREN { + ret.reset(new Wccl::Affix(o_ret, offset)); } ; // ---------------------------------------------------------------------------- @@ -922,13 +959,21 @@ options { | '\'' (~'\'')* '\'' ; -INT +SIGNED_INT options { - paraphrase = "Integer"; + paraphrase = "Signed integer"; } - : ('-'|'+')? ('0'..'9')+ + : ('-'|'+') ('0'..'9')+ ; +UNSIGNED_INT +options { + paraphrase = "Unsigned integer"; +} + : ('0'..'9')+ +; + + QUOT_MARK options { paraphrase = "Quota mark"; -- GitLab