Class CNFRule
java.lang.Object
CNFRule
public class CNFRule
- extends java.lang.Object
- Version:
- Fall 2007
There are three types of rules allowed in a CNF grammar, which we will
refer to as "type 0", "type 1", and "type 2". Type 0 transforms a
variable to a pair of variables, type 1 transforms a variable to a
terminal symbol, and type 2 transforms the start variable to the empty
string. The CNFRule class is used to represent instances of rules of
type 0 or 1.
Data Fields: A CNFRule has a "type" (integer code 0 or 1), three integer
variables "var1", "var2", "var3", and a char variable "term" (terminal
symbol).
Type 0 rules are form vn -> vi vj where i and j are non-zero.
In this case, type = 0, var1 = n, var2 = i, var3 = j, and "term" is
irrelevant.
Type 1 rules are form vn -> t. In this case, type = 1, var1 = n, term = t,
and "var2", "var3" are irrelevant.
Methods: CNFRule class has the usual accessor methods plus an "equals"
method.
- Author:
- Barbara Wahl
Constructor Summary |
CNFRule(CNFRule current)
|
CNFRule(int n,
char t)
|
CNFRule(int n,
int i,
int j)
3-arg constructor for type 0 rule, "vn -> vi vj" |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
CNFRule
public CNFRule(int n,
int i,
int j)
- 3-arg constructor for type 0 rule, "vn -> vi vj"
- Precondition:
- 0<=n, 0
- Postcondition:
- type = 0, var1 = n, var2 = i, var3 = j, term = '-'
CNFRule
public CNFRule(int n,
char t)
CNFRule
public CNFRule(CNFRule current)
type
public int type()
var1
public int var1()
var2
public int var2()
var3
public int var3()
term
public char term()
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in class java.lang.Object
main
public static void main(java.lang.String[] args)