91 void toString(std::ostringstream& os)
const;
95 static void*
operator new(size_t);
96 static void operator delete(
void*);
110 REG::Exp::operator
new(
size_t s) {
114 REG::Exp::operator
delete(
void*) {
119 REG::Exp::dispose(
void) {
122 while (!todo.empty()) {
145 if ((e != NULL) && (--e->
use_cnt == 0))
152 return (e != NULL) ? e->
_n_pos : 0;
159 os <<
"[" << data.symbol <<
"]";
163 bool par = ((data.kids[0] != NULL) &&
164 ((data.kids[0]->type == ET_CONC) ||
165 (data.kids[0]->type == ET_OR)));
166 os << (par ?
"*(" :
"*");
167 if (data.kids[0]==NULL) {
170 data.kids[0]->toString(os);
172 os << (par ?
")" :
"");
177 bool par0 = ((data.kids[0] != NULL) &&
178 (data.kids[0]->type == ET_OR));
179 os << (par0 ?
"(" :
"");
180 if (data.kids[0]==NULL) {
183 data.kids[0]->toString(os);
185 os << (par0 ?
")+" :
"+");
186 bool par1 = ((data.kids[1] != NULL) &&
187 (data.kids[1]->type == ET_OR));
188 os << (par1 ?
"(" :
"");
189 if (data.kids[1]==NULL) {
192 data.kids[1]->toString(os);
194 os << (par1 ?
")" :
"");
198 if (data.kids[0]==NULL) {
201 data.kids[0]->toString(os);
204 if (data.kids[1]==NULL) {
207 data.kids[1]->toString(os);
218 std::ostringstream os;
265 for (
int i=
n;
i--; ) {
270 a[
i]->data.symbol =
x[
i];
273 for (
int m=
n; m>1; ) {
282 a[0]->data.kids[0] = e1;
283 a[0]->data.kids[1] = e2;
286 for (
int i=0;
i<m;
i++) {
293 a[
i]->data.kids[0] = e1;
294 a[
i]->data.kids[1] = e2;
332 if (e == NULL)
return r2;
333 if (r2.e == NULL)
return *
this;
378 if ((
n>m) || (m == 0))
391 unsigned int i = m-
n;
428 REG::toString(
void)
const {
435 namespace MiniModel {
478 for (
const PosSet* ps =
this; ps != NULL; ps = ps->
next)
481 }
else if (ps->pos <
p) {
489 while ((ps1 != NULL) && (ps2 != NULL)) {
507 while ((ps1 != NULL) && (ps2 != NULL)) {
512 *
p =
n;
p = &
n->next;
513 if (ps1->
pos == ps2->
pos) {
516 }
else if (ps1->
pos > ps2->
pos) {
522 *
p = (ps1 != NULL) ? ps1 : ps2;
556 : nullable(
n), firstpos(fp), lastpos(lp) {}
560 :
exp(e), open(true) {}
577 todo.
push(ExpInfo(
this));
580 if (todo.
top().exp == NULL) {
582 done.
push(NodeInfo(
true,NULL,NULL));
584 switch (todo.
top().exp->type) {
587 pi[
p].symbol = todo.
pop().exp->data.symbol;
588 PosSet* ps =
new (psm) PosSet(
p++);
589 done.
push(NodeInfo(
false,ps,ps));
593 if (todo.
top().open) {
595 todo.
top().open =
false;
596 todo.
push(todo.
top().exp->data.kids[0]);
599 NodeInfo ni = done.
pop();
600 for (PosSet* ps = ni.lastpos; ps != NULL; ps = ps->next)
601 pi[ps->pos].followpos =
602 PosSet::cup(psm,
pi[ps->pos].followpos,ni.firstpos);
603 done.
push(NodeInfo(
true,ni.firstpos,ni.lastpos));
607 if (todo.
top().open) {
609 todo.
top().open =
false;
615 NodeInfo ni1 = done.
pop();
616 NodeInfo ni0 = done.
pop();
617 for (PosSet* ps = ni0.lastpos; ps != NULL; ps = ps->next)
618 pi[ps->pos].followpos =
619 PosSet::cup(psm,
pi[ps->pos].followpos,ni1.firstpos);
620 done.
push(NodeInfo(ni0.nullable & ni1.nullable,
622 PosSet::cup(psm,ni0.firstpos,ni1.firstpos) : ni0.firstpos,
624 PosSet::cup(psm,ni0.lastpos,ni1.lastpos) : ni1.lastpos));
628 if (todo.
top().open) {
630 todo.
top().open =
false;
636 NodeInfo ni1 = done.
pop();
637 NodeInfo ni0 = done.
pop();
638 done.
push(NodeInfo(ni0.nullable | ni1.nullable,
639 PosSet::cup(psm,ni0.firstpos,ni1.firstpos),
640 PosSet::cup(psm,ni0.lastpos,ni1.lastpos)));
646 }
while (!todo.
empty());
647 return done.
top().firstpos;
651 namespace MiniModel {
685 bool empty(
void)
const;
703 StatePool::pop(
void) {
712 StatePool::empty(
void)
const {
722 switch (PosSet::cmp(ps,
n->pos)) {
732 n->state = n_states++;
752 Support::quicksort<int,SymbolsInc>(s,
n,o);
767 void add(
int,
int,
int);
773 TransitionBag::TransitionBag(
void) :
t(
heap),
n(0) {}
777 t[n].i_state = i_state;
778 t[n].symbol = symbol;
779 t[n].o_state = o_state;
850 for (
int i=n_pos;
i--; )
851 pi[
i].followpos = NULL;
853 PosSet* firstpos =
r.e->followpos(psm,&
pi[0]);
857 for (
int i=n_pos;
i--; )
858 symbols[
i] =
pi[
i].symbol;
862 for (
int i = 1;
i<n_pos-1;
i++)
863 if (symbols[
i-1] != symbols[
i])
864 symbols[n_symbols++] = symbols[
i];
868 StatePool sp(firstpos);
869 while (!sp.empty()) {
870 StateNode* sn = sp.pop();
871 for (
int i = n_symbols;
i--; ) {
873 for (PosSet* ps = sn->pos; ps != NULL; ps = ps->next)
874 if (
pi[ps->pos].symbol == symbols[
i])
875 u = PosSet::cup(psm,
u,
pi[ps->pos].followpos);
877 tb.add(sn->state,symbols[
i],sp.state(spm,
u));
884 for (StateNode*
n = sp.all;
n != NULL;
n =
n->next)
885 if (
n->pos->in(n_pos-1))
891 return DFA(0,tb.transitions(),fb.finals(),
true);
Information on positions collected during traversal.
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
PosSetCmp
Order on position sets.
static PosSet * cup(PosSetAllocator &, PosSet *, PosSet *)
ExpInfo(REG::Exp *e=NULL)
static PosSetCmp cmp(PosSet *, PosSet *)
void rfree(void *p)
Free memory block starting at p.
Regular expressions over integer values.
Exception: Too few arguments available in argument array
Support::BlockAllocator< StateNode, Heap > StatePoolAllocator
Allocator for state nodes.
bool pos(const View &x)
Test whether x is postive.
REG & operator|=(const REG &r)
This expression or r.
Exp * kids[2]
Subexpressions.
void * ralloc(size_t s)
Allocate s bytes from heap.
Support::BlockAllocator< PosSet, Heap > PosSetAllocator
Allocator for position sets.
Array with arbitrary number of elements.
const int max
Largest allowed integer value.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
std::string toString(void) const
Print expression.
Manage memory organized into block lists (allocator)
void sort(TaskViewArray< TaskView > &t)
Sort task view array t according to sto and inc (increasing or decreasing)
Deterministic finite automaton (DFA)
int p
Number of positive literals for node type.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
const REG & operator=(const REG &r)
Assign to regular expression r.
static void dec(Exp *e)
Decrement use counter of e.
REG & operator+=(const REG &r)
This expression is followed by r.
static int n_pos(Exp *e)
Return number of positions of e.
REG(void)
Initialize as empty sequence (epsilon)
State pool combines a tree of states together with yet unprocessed states
T pop(void)
Pop topmost element from stack and return it.
ExpType type
Type of regular expression.
REG operator|(const REG &r)
Return expression for: this expression or r.
Specification of a DFA transition.
static void inc(Exp *e)
Increment use counter of e.
unsigned int use_cnt
Reference counter.
Passing integer arguments.
Post propagator for SetVar SetOpType SetVar SetRelType r
union Gecode::REG::Exp::@66 data
Symbol or subexpressions.
MiniModel::PosSet * followpos(MiniModel::PosSetAllocator &, MiniModel::PosInfo *)
Compute the follow positions.
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
ExpType
Type of regular expression.
Post propagator for SetVar SetOpType SetVar y
T & top(void) const
Return element on top of stack.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
DFA::Transition * transitions(void)
Client for block allocator of type T.
REG operator *(void)
Return expression for: this expression arbitrarily often (Kleene star)
Heap heap
The single global heap.
Stack with arbitrary number of elements.
Post propagator for SetVar x
Implementation of the actual expression tree.
For collecting transitions while constructing a DFA.
Node information computed during traversal of the expressions.
REG operator+(void)
Return expression for: this expression at least once.
void toString(std::ostringstream &os) const
Print expression to os.
Gecode toplevel namespace
REG operator()(unsigned int n, unsigned int m)
Return expression for: this expression at least n and at most m times.
void exp(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
NodeInfo(bool n=false, PosSet *fp=NULL, PosSet *lp=NULL)
bool empty(void) const
Test whether stack is empty.
#define GECODE_NEVER
Assert that this command is never executed.
static void sort(int s[], int n)
int _n_pos
Number of positions.
Node together with state information
void push(const T &x)
Push element x on top of stack.
For collecting final states while constructing a DFA.