finiteAutomata
Class CNFRule

java.lang.Object
  extended by finiteAutomata.CNFRule

public class CNFRule
extends java.lang.Object

Rules for the CNF class.

There are three types of rules allowed in a CNF grammar. Type 0 rules transform a variable to a pair of variables; type 1 rules transform a variable to a terminal symbol; and type 2 rules transform the start variable to the empty string (epsilon). The CNFRule class is used to represent rules of types 0 and 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.

Version:
Fall 2007
Author:
Barbara Wahl

Field Summary
protected  char term
          right-hand-side terminal symbol (for type 1)
protected  int type
          indicates type 0 or type 1
protected  int var1
          left-hand-side variable
protected  int var2
          first right-hand-side variable (for type 0)
protected  int var3
          second right-hand-side variable (for type 0)
 
Constructor Summary
CNFRule(CNFRule current)
          Copy constructor.
CNFRule(int n, char t)
          2-parameter constructor for type 1 rule, "vn -> t".
CNFRule(int n, int i, int j)
          3-parameter constructor for type 0 rule, "vn -> vi vj".
 
Method Summary
 boolean equals(java.lang.Object other)
          Tests whether this CNFRule and the given CNFRule are logically equal.
static void main(java.lang.String[] args)
           
 char term()
          Returns term, the terminal symbol on RHS (or '-' if type 0).
 java.lang.String toString()
          Returns a pretty String representation of this rule.
 int type()
          Returns the type.
 int var1()
          Returns var1, the LHS variable.
 int var2()
          Returns var2, the first RHS variable (or '-' if type 1).
 int var3()
          Returns var3, the second RHS variable (or '-' if type 1).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected int type
indicates type 0 or type 1


var1

protected int var1
left-hand-side variable


var2

protected int var2
first right-hand-side variable (for type 0)


var3

protected int var3
second right-hand-side variable (for type 0)


term

protected char term
right-hand-side terminal symbol (for type 1)

Constructor Detail

CNFRule

public CNFRule(int n,
               int i,
               int j)
3-parameter constructor for type 0 rule, "vn -> vi vj".

Parameters:
n - LHS variable
i - first RHS variable
j - second RHS variable
Precondition:
n >= 0, i > 0, j > 0
Postcondition:
creates the type 0 CNFRule for "vn -> vi vj" (term = '-')

CNFRule

public CNFRule(int n,
               char t)
2-parameter constructor for type 1 rule, "vn -> t".

Parameters:
n - LHS variable
t - terminal symbol
Precondition:
n >= 0
Postcondition:
creates the type 1 CNFRule for "vn -> t" (var2 = var3 = '-')

CNFRule

public CNFRule(CNFRule current)
Copy constructor.

Parameters:
current - CNFRule to be copied
Precondition:
current is not null
Postcondition:
constructs a new CNFRule with same attributes as current
Method Detail

type

public int type()
Returns the type.

Returns:
int type

var1

public int var1()
Returns var1, the LHS variable.

Returns:
int var1

var2

public int var2()
Returns var2, the first RHS variable (or '-' if type 1).

Returns:
int var2

var3

public int var3()
Returns var3, the second RHS variable (or '-' if type 1).

Returns:
int var3

term

public char term()
Returns term, the terminal symbol on RHS (or '-' if type 0).

Returns:
char term

toString

public java.lang.String toString()
Returns a pretty String representation of this rule.

Overrides:
toString in class java.lang.Object
Returns:
String for pretty-printing the rule

equals

public boolean equals(java.lang.Object other)
Tests whether this CNFRule and the given CNFRule are logically equal.

Overrides:
equals in class java.lang.Object
Parameters:
other - CNFRule to compare with this
Returns:
true iff the two rules are logically equivalent
Precondition:
other is a non-null CNFRule object

main

public static void main(java.lang.String[] args)