|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object finiteAutomata.StringVarTerm
public class StringVarTerm
A non-empty string of variables and terminals such as occur in grammar
derivations (supports the CNF class).
Data Fields: Each StringVarTerm has a Vector (code) of Integer
codes to represent the string, a counter (vars) telling how many
variables are in the string, a Vector (derivation) of String objects
showing the sequence of strings used in deriving this string, and an
Alphabet (alpha) of allowable terminal symbols.
Example (encoding/decoding):
Suppose the Alphabet is {a,b,c}. The integers 1, 2, 3 are used to
represent, respectively, the terminal symbols a, b, and c. 0
represents the start variable v0, -1 represents v1, -2 represents v2,
and so on. Thus, the string "c a v1 v2 b a v2" would be encoded by
the integer sequence "3, 1, -1, -2, 2, 1, -2". Note that
terminals are represented by positive codes and variables are
represented by non-positive codes.
Field Summary | |
---|---|
protected Alphabet |
alpha
alphabet of terminal symbols |
protected java.util.Vector |
code
sequence of Integer codes for this StringVarTerm |
protected java.util.Vector |
derivation
sequence of Strings showing how this StringVarTerm is derived from start (v0) |
protected int |
vars
number of variables in this StringVarTerm (vars == 0 if this represents a string of terminal symbols) |
Constructor Summary | |
---|---|
StringVarTerm(Alphabet S)
1-parameter constructor, creates the StringVarTerm representing the start string, "v0" |
Method Summary | |
---|---|
StringVarTerm |
applyRule(CNFRule r)
Returns the result of applying the given CNFRule to the LEFT-MOST variable in this StringVarTerm. |
java.util.Vector |
code()
Returns a deep copy of this.code. |
StringVarTerm |
copy()
Returns a deep copy of this StringVarTerm. |
protected int |
decodeVar(int i)
Returns the decoded value of the given position in this.code, assuming that position is a coded variable. |
java.util.Vector |
derivation()
Returns a deep copy of this.derivation. |
boolean |
equalString(StringVarTerm other)
Tests whether "this" and another StringVarTerm represent the same string. |
boolean |
equalTermString(java.lang.String s)
Tests whether a given String is a non-empty string of terminals and this StringVarTerm represents the same string of terminals. |
int |
leftMostVarIndex()
Returns the index (position) of the left-most variable in this StringVarTerm. |
static void |
main(java.lang.String[] args)
|
boolean |
matches(CNFRule r)
Tests whether a given rule applies to the left-most variable in this StringVarTerm. |
int |
numSteps()
Returns number of steps to derive this StringVarTerm. |
void |
printDerivation()
Pretty-prints the derivation. |
void |
printStringVarTerm()
Pretty-prints a report on this StringVarTerm. |
java.lang.String |
toPrettyString()
Returns a "pretty" representation of the string represented by this StringVarTerm. |
java.lang.String |
toTermString()
Decodes this StringVarTerm (which has no variables); returns a String with no spaces. |
int |
vars()
Returns number of variables. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Vector code
protected int vars
protected Alphabet alpha
protected java.util.Vector derivation
Constructor Detail |
---|
public StringVarTerm(Alphabet S)
S
- Alphabet of terminal symbolsMethod Detail |
---|
public int numSteps()
public int vars()
public StringVarTerm copy()
public java.util.Vector derivation()
public java.util.Vector code()
public void printStringVarTerm()
public void printDerivation()
public java.lang.String toPrettyString()
public java.lang.String toTermString()
public StringVarTerm applyRule(CNFRule r)
r
- the rule to be applied
protected int decodeVar(int i)
i
- position of interest in this code
public int leftMostVarIndex()
public boolean matches(CNFRule r)
r
- the rule to be tested
public boolean equalTermString(java.lang.String s)
s
- the String to be tested
public boolean equalString(StringVarTerm other)
other
- the StringVarTerm with which to compare this
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |