91 template<
class Char,
class Traits>
92 std::basic_ostream<Char,Traits>&
93 print(std::basic_ostream<Char,Traits>& 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;
197 for (
int i=n;
i--; ) {
205 for (
int m=n; m>1; ) {
218 for (
int i=0;
i<m;
i++) {
264 if (e == NULL)
return r2;
265 if (r2.e == NULL)
return *
this;
310 if ((n>m) || (m == 0))
323 unsigned int i = m-
n;
360 namespace MiniModel {
403 for (
const PosSet* ps =
this; ps != NULL; ps = ps->
next)
406 }
else if (ps->pos < p) {
414 while ((ps1 != NULL) && (ps2 != NULL)) {
432 while ((ps1 != NULL) && (ps2 != NULL)) {
437 *p =
n; p = &n->
next;
438 if (ps1->
pos == ps2->
pos) {
441 }
else if (ps1->
pos > ps2->
pos) {
447 *p = (ps1 != NULL) ? ps1 : ps2;
481 : nullable(n), firstpos(fp), lastpos(lp) {}
485 :
exp(e), open(true) {}
502 todo.
push(ExpInfo(
this));
505 if (todo.
top().exp == NULL) {
507 done.
push(NodeInfo(
true,NULL,NULL));
509 switch (todo.
top().exp->type) {
513 PosSet* ps =
new (psm) PosSet(p++);
514 done.
push(NodeInfo(
false,ps,ps));
518 if (todo.
top().open) {
520 todo.
top().open =
false;
521 todo.
push(todo.
top().exp->data.kids[0]);
524 NodeInfo ni = done.
pop();
525 for (PosSet* ps = ni.lastpos; ps != NULL; ps = ps->next)
527 PosSet::cup(psm,pi[ps->pos].
followpos,ni.firstpos);
528 done.
push(NodeInfo(
true,ni.firstpos,ni.lastpos));
532 if (todo.
top().open) {
534 todo.
top().open =
false;
540 NodeInfo ni1 = done.
pop();
541 NodeInfo ni0 = done.
pop();
542 for (PosSet* ps = ni0.lastpos; ps != NULL; ps = ps->next)
544 PosSet::cup(psm,pi[ps->pos].
followpos,ni1.firstpos);
545 done.
push(NodeInfo(ni0.nullable & ni1.nullable,
547 PosSet::cup(psm,ni0.firstpos,ni1.firstpos) : ni0.firstpos,
549 PosSet::cup(psm,ni0.lastpos,ni1.lastpos) : ni1.lastpos));
553 if (todo.
top().open) {
555 todo.
top().open =
false;
561 NodeInfo ni1 = done.
pop();
562 NodeInfo ni0 = done.
pop();
563 done.
push(NodeInfo(ni0.nullable | ni1.nullable,
564 PosSet::cup(psm,ni0.firstpos,ni1.firstpos),
565 PosSet::cup(psm,ni0.lastpos,ni1.lastpos)));
571 }
while (!todo.
empty());
572 return done.
top().firstpos;
576 namespace MiniModel {
610 bool empty(
void)
const;
612 int state(StatePoolAllocator&,
PosSet*);
628 StatePool::pop(
void) {
637 StatePool::empty(
void)
const {
642 StatePool::state(StatePoolAllocator& spm,
PosSet* ps) {
647 switch (PosSet::cmp(ps,n->
pos)) {
657 n->
state = n_states++;
677 Support::quicksort<int,SymbolsInc>(s,
n,o);
692 void add(
int,
int,
int);
698 TransitionBag::TransitionBag(
void) :
t(
heap),
n(0) {}
702 t[n].i_state = i_state;
703 t[n].symbol = symbol;
704 t[n].o_state = o_state;
774 PosInfo* pi =
heap.
alloc<PosInfo>(n_pos);
775 for (
int i=n_pos;
i--; )
776 pi[
i].followpos = NULL;
778 PosSet* firstpos = r.e->
followpos(psm,&pi[0]);
782 for (
int i=n_pos;
i--; )
783 symbols[
i] = pi[
i].symbol;
787 for (
int i = 1;
i<n_pos-1;
i++)
788 if (symbols[
i-1] != symbols[
i])
789 symbols[n_symbols++] = symbols[
i];
793 StatePool sp(firstpos);
794 while (!sp.empty()) {
795 StateNode* sn = sp.pop();
796 for (
int i = n_symbols; i--; ) {
798 for (PosSet* ps = sn->pos; ps != NULL; ps = ps->next)
799 if (pi[ps->pos].symbol == symbols[i])
800 u = PosSet::cup(psm,u,pi[ps->pos].followpos);
802 tb.add(sn->state,symbols[i],sp.state(spm,u));
809 for (StateNode*
n = sp.all;
n != NULL;
n =
n->next)
810 if (
n->pos->in(n_pos-1))
816 return DFA(0,tb.transitions(),fb.finals(),
true);
Information on positions collected during traversal.
union Gecode::REG::Exp::@62 data
Symbol or subexpressions.
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.
int size(void) const
Return size of array (number of elements)
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.
T & top(void) const
Return element on top of stack.
Heap heap
The single global heap.
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.
std::basic_ostream< Char, Traits > & print(std::basic_ostream< Char, Traits > &os) const
Print expression.
Specification of a DFA transition.
static void inc(Exp *e)
Increment use counter of e.
bool empty(void) const
Test whether stack is empty.
unsigned int use_cnt
Reference counter.
Passing integer arguments.
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
MiniModel::PosSet * followpos(MiniModel::PosSetAllocator &, MiniModel::PosInfo *)
Compute the follow positions.
ExpType
Type of regular expression.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Node * x
Pointer to corresponding Boolean expression node.
DFA::Transition * transitions(void)
Client for block allocator of type T.
REG operator*(void)
Return expression for: this expression arbitrarily often (Kleene star)
Stack with arbitrary number of elements.
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.
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)
#define GECODE_NEVER
Assert that this command is never executed.
static void sort(int s[], int n)
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
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.