diff options
author | buraq <buraq@epfl.ch> | 2004-07-14 14:01:14 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-07-14 14:01:14 +0000 |
commit | b0f0428e9ad40d447bcf55c07346fc701ff08433 (patch) | |
tree | 608b37d89b376c162182334df4b82cd0d279d404 | |
parent | 932f642e9ed46ae4c2a88475186699ca6c50c0d6 (diff) | |
download | scala-b0f0428e9ad40d447bcf55c07346fc701ff08433.tar.gz scala-b0f0428e9ad40d447bcf55c07346fc701ff08433.tar.bz2 scala-b0f0428e9ad40d447bcf55c07346fc701ff08433.zip |
matcing
3 files changed, 117 insertions, 0 deletions
diff --git a/sources/scala/util/grammar/ImmutableTreeHedgeGrammar.scala b/sources/scala/util/grammar/ImmutableTreeHedgeGrammar.scala new file mode 100644 index 0000000000..b758631121 --- /dev/null +++ b/sources/scala/util/grammar/ImmutableTreeHedgeGrammar.scala @@ -0,0 +1,27 @@ +package scala.util.grammar; + +import scala.util.alphabet.Alphabet ; +import scala.collection.immutable ; + +/** a mutable representation of hedge grammars. A hedge grammar over an + * alphabet consists of tree and hedge nonterminals (consecutive integers), + * and tree and hedge productions that relate them. Hedge nonterminals that + * can derive the empty hedge are called "nullable". initials tree + * or hedge nonterminals. + */ +abstract class ImmutableTreeHedgeGrammar[ A <: Alphabet ] extends TreeHedgeGrammar { + + /** number of tree nonterminals*/ + val nTreeNT: Int; + /** number of hedge nonterminals*/ + val nHedgeNT: Int; + /** inv: treeInitials.length == nTreeNT */ + val treeInitials: immutable.BitSet; + /** inv: hedgeInitials.length == nHedgeNT */ + val hedgeInitials: immutable.BitSet; + /** inv: isNullable.length == nHedgeNT */ + val isNullable: immutable.BitSet; + var treeTransitions: Array[immutable.Set[TreeRHS]]; + var hedgeTransitions: Array[immutable.Set[HedgeRHS]]; + +} diff --git a/sources/scala/util/grammar/MutableTreeHedgeGrammar.scala b/sources/scala/util/grammar/MutableTreeHedgeGrammar.scala new file mode 100644 index 0000000000..518ee1a6b3 --- /dev/null +++ b/sources/scala/util/grammar/MutableTreeHedgeGrammar.scala @@ -0,0 +1,57 @@ +package scala.util.grammar; + +import scala.util.alphabet.Alphabet ; +import scala.collection.mutable ; + +/** a mutable representation of hedge grammars. A hedge grammar over an + * alphabet consists of tree and hedge nonterminals (consecutive integers), + * and tree and hedge productions that relate them. Hedge nonterminals that + * can derive the empty hedge are called "nullable". initials tree + * or hedge nonterminals. + */ +class MutableTreeHedgeGrammar[ A <: Alphabet ] extends TreeHedgeGrammar[ A ] { + + /** number of tree nonterminals*/ + var nTreeNT: Int = 0; + /** number of hedge nonterminals*/ + var nHedgeNT: Int = 0; + /** inv: treeInitials.length == nTreeNT */ + val treeInitials = new mutable.ResizableBitSet(); + /** inv: hedgeInitials.length == nHedgeNT */ + val hedgeInitials = new mutable.ResizableBitSet(); + /** inv: hedgeIsNullable.length == nHedgeNT */ + val isNullable = new mutable.ResizableBitSet();; + val treeTransitions: mutable.Map[Int, mutable.Set[TreeRHS]] = + new mutable.HashMap[Int, mutable.Set[TreeRHS]]; + val hedgeTransitions: mutable.Map[Int, mutable.Set[HedgeRHS]] = + new mutable.HashMap[Int, mutable.Set[HedgeRHS]]; + + def makeTreeNT = { + val r = nTreeNT; + nTreeNT = nTreeNT + 1; + treeInitials.ensureSize( nTreeNT ); + treeTransitions.update(r, new mutable.HashSet[TreeRHS]()); + r + } + + def makeHedgeNT = { + val r = nTreeNT; + nHedgeNT = nHedgeNT + 1; + hedgeInitials.ensureSize( nHedgeNT ); + hedgeTransitions.update(r, new mutable.HashSet[HedgeRHS]()); + r + } + + def addHedgeRule(hnt1: Int,tnt: Int,hnt2: Int): Unit = + addHedgeRule(hnt1, HedgeRHS(tnt, hnt2)); + + def addHedgeRule(hnt: Int, rhs: HedgeRHS): Unit = + hedgeTransitions( hnt ) += rhs; + + def addTreeRule(tnt: Int, label: A, hnt: Int): Unit = + addTreeRule(tnt, TreeRHS( label, hnt )); + + def addTreeRule(tnt: Int,rhs: TreeRHS): Unit = + treeTransitions( tnt ) += rhs; + +} diff --git a/sources/scala/util/grammar/TreeHedgeGrammar.scala b/sources/scala/util/grammar/TreeHedgeGrammar.scala new file mode 100644 index 0000000000..8837a1ba52 --- /dev/null +++ b/sources/scala/util/grammar/TreeHedgeGrammar.scala @@ -0,0 +1,33 @@ +package scala.util.grammar; + +import scala.util.alphabet.Alphabet ; +import scala.collection.{ BitSet, Set, mutable } ; + +/** a mutable representation of hedge grammars. A hedge grammar over an + * alphabet consists of tree and hedge nonterminals (consecutive integers), + * and tree and hedge productions that relate them. Hedge nonterminals that + * can derive the empty hedge are called "nullable". initials tree + * or hedge nonterminals. + */ +abstract class TreeHedgeGrammar[ A <: Alphabet ] { + + /** right hand side of a tree production */ + case class TreeRHS(label: A, hnt: Int); + /** right hand side of a hedge production */ + case class HedgeRHS(tnt: Int, hnt: Int); + + /** number of tree nonterminals*/ + def nTreeNT: Int; + /** number of hedge nonterminals*/ + def nHedgeNT: Int; + /** inv: treeInitials.size == nTreeNT */ + def treeInitials: BitSet; + /** inv: hedgeInitials.size == nHedgeNT */ + def hedgeInitials: BitSet; + /** inv: isNullable.size == nHedgeNT */ + def isNullable: BitSet; + + def treeTransitions: Function1[Int, Set[TreeRHS]] ; + def hedgeTransitions: Function1[Int, Set[HedgeRHS]] ; + +} |