Subversion Repositories lexicon

Compare Revisions

Ignore whitespace Rev 63 → Rev 64

/trunk/parser/fragtable.cc
52,11 → 52,6
 
void fragtable::apply(const grammar& rules)
{
for (size_t i=0;i!=_capacity;++i)
{
tags(i,1)|=rules.find(tags(i,1));
}
 
// Loop 1: begin constructing fragments of length 2,
// end with one that fills the whole buffer.
for (size_t i=2;i!=_capacity+1;++i)
69,13 → 64,67
// end with a RHS of length 1.
for (size_t k=1;k!=i;++k)
{
tags(j,i)|=rules.find(tags(j,k),tags(j+k,i-k));
tags(j,i)|=rules.find(tags(j,i));
tagset lhs=rules.find(tags(j,k));
tagset rhs=rules.find(tags(j+k,i-k));
tags(j,i)|=rules.find(lhs,rhs);
}
}
}
}
 
void fragtable::restrict(const grammar& rules)
{
// Loop 1: begin examining fragments of length _capacity-1,
// end with fragments of length 1.
for (size_t i=_capacity-1;i!=0;--i)
{
// Loop 2: begin examining the fragment at the
// far left of the buffer, end at the far right.
for (size_t j=0;j!=_capacity-i+1;++j)
{
// Loop 3: iterate over the existing tags for this fragment.
tagset new_tags;
tagset old_tags=tags(j,i);
 
for (tagset::const_iterator t=old_tags.begin(),t_end=old_tags.end();t!=t_end;++t)
{
tagset test_tags;
test_tags|=*t;
test_tags|=rules.find(test_tags);
 
// Loop 4a: try fragment as the right-hand side of a rule.
// (k is the start of the left-hand fragment.)
for (size_t k=0;k!=j;++k)
{
tagset lhs=rules.find(tags(k,j-k));
tagset produced_tags=rules.find(lhs,test_tags);
produced_tags|=rules.find(produced_tags);
if (!(produced_tags&tags(k,j+i-k)).empty())
{
new_tags|=*t;
break;
}
}
 
// Loop 4b: try fragment as the left-hand side of a rule.
// (k is one past the end of the right-hand fragment.)
for (size_t k=j+i+1;k!=_capacity+1;++k)
{
tagset rhs=rules.find(tags(j+i,k-j-i));
tagset produced_tags=rules.find(test_tags,rhs);
produced_tags|=rules.find(produced_tags);
if (!(produced_tags&tags(j,k-j)).empty())
{
new_tags|=*t;
break;
}
}
}
tags(j,i)=new_tags;
}
}
}
 
void fragtable::write(std::ostream& out) const
{
for (size_t i=0;i!=_capacity;++i)
/trunk/parser/fragtable.h
97,6 → 97,11
*/
void apply(const grammar& rules);
 
/** Restrict tags to those which form part of a full solution.
* @param rules the grammar to be used
*/
void restrict(const grammar& rules);
 
/** Write table to stream.
* @param out the stream
*/