finiteAutomata
Class CNFMenu

java.lang.Object
  extended by finiteAutomata.CNFMenu

public class CNFMenu
extends java.lang.Object

Menu and query methods for the CNF class.

Version:
Fall 2007
Author:
Barbara Wahl

Constructor Summary
CNFMenu()
           
 
Method Summary
protected static void addTypeOneDialog(CNF cnf)
          Queries user for n and t in the rule "vn -> t" and adds the correpsonding rule.
protected static void addTypeZeroDialog(CNF cnf)
          Queries user for n, i, and j in the rule "vn -> vi vj" and adds the correpsonding rule.
protected static int constructorMenu()
          Repeatedly displays constructor menu options until user makes a valid choice.
protected static void menuHandler(CNF cnf, int choice)
          Takes the appropriate action based on menu options.
protected static void predefinedDialog(CNF cnf)
          Queries user regarding which pre-defined CNF they will use.
protected static void printLanguageDialog(CNF cnf)
          Queries user for max string length and prints this CNF's language.
protected static java.lang.String queryAlphabet()
          Queries user for alphabet of terminal symbols.
protected static boolean queryAmbiguous()
          Asks user if they want to have strings with ambiguous derivations be repeated.
protected static int queryNumVars()
          Prints constructor menu header and queries user regarding number of variables.
protected static boolean queryPredefined()
          Asks user if they want to use a pre-defined CNF.
protected static void removeTypeOneDialog(CNF cnf)
          Queries user for n and t, and removes rule "vn -> t".
protected static void removeTypeZeroDialog(CNF cnf)
          Queries user for n, i, and j, and removes rule "vn -> vi vj".
protected static void ruleChangeDialog(CNF cnf)
          Asks user which type of rule change they want to make and carries out that request.
static void runMenu(CNF cnf)
          Repeatedly obtains user's action choice and carries out that action.
protected static void testStringDialog(CNF cnf)
          Determines whether a user-specified String is generated by the given grammar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CNFMenu

public CNFMenu()
Method Detail

runMenu

public static void runMenu(CNF cnf)
Repeatedly obtains user's action choice and carries out that action.

Parameters:
cnf - the CNF being operated on

constructorMenu

protected static int constructorMenu()
Repeatedly displays constructor menu options until user makes a valid choice.

Returns:
int choice number from 1 to 6

menuHandler

protected static void menuHandler(CNF cnf,
                                  int choice)
Takes the appropriate action based on menu options.

Parameters:
cnf - the CNF being operated on
choice - integer code for user's desired action
Precondition:
1 <= choice <= 5

queryPredefined

protected static boolean queryPredefined()
Asks user if they want to use a pre-defined CNF.

Parameters:
cnf - the CNF being operated on
Returns:
true iff user's response begins with 'Y' or 'y'

predefinedDialog

protected static void predefinedDialog(CNF cnf)
Queries user regarding which pre-defined CNF they will use.

Parameters:
cnf - the CNF being operated on
Postcondition:
initializes cnf to have the same data fields as the pre-defined grammar chosen by the user

queryAlphabet

protected static java.lang.String queryAlphabet()
Queries user for alphabet of terminal symbols.

Returns:
String of terminal symbols as specified by user

queryNumVars

protected static int queryNumVars()
Prints constructor menu header and queries user regarding number of variables.

Returns:
positive integer number of variables as specified by user

queryAmbiguous

protected static boolean queryAmbiguous()
Asks user if they want to have strings with ambiguous derivations be repeated.

Returns:
true iff user response begins with 'Y' or 'y'

ruleChangeDialog

protected static void ruleChangeDialog(CNF cnf)
Asks user which type of rule change they want to make and carries out that request.

Parameters:
cnf - the CNF being operated on
Postcondition:
cnf.rule array is altered to reflect addition/deletion of a rule, or value of cnf.startToEpsilon is possibly changed

addTypeZeroDialog

protected static void addTypeZeroDialog(CNF cnf)
Queries user for n, i, and j in the rule "vn -> vi vj" and adds the correpsonding rule.

Parameters:
cnf - the CNF being operated on
Postcondition:
cnf.rule array is updated

addTypeOneDialog

protected static void addTypeOneDialog(CNF cnf)
Queries user for n and t in the rule "vn -> t" and adds the correpsonding rule.

Parameters:
cnf - the CNF being operated on
Postcondition:
cnf.rule array is updated

removeTypeZeroDialog

protected static void removeTypeZeroDialog(CNF cnf)
Queries user for n, i, and j, and removes rule "vn -> vi vj".

Parameters:
cnf - the CNF being operated on
Postcondition:
cnf.rule array is updated

removeTypeOneDialog

protected static void removeTypeOneDialog(CNF cnf)
Queries user for n and t, and removes rule "vn -> t".

Parameters:
cnf - the CNF being operated on
Postcondition:
cnf.rule array is updated

printLanguageDialog

protected static void printLanguageDialog(CNF cnf)
Queries user for max string length and prints this CNF's language.

Parameters:
cnf - the CNF being operated on
Postcondition:
all terminal strings generated by cnf, up to the user-specified max length, are printed; according to user input, derivations may also be printed and strings with ambiguous derivations may appear multiple times

testStringDialog

protected static void testStringDialog(CNF cnf)
Determines whether a user-specified String is generated by the given grammar.

Parameters:
cnf - the CNF being operated on
Postcondition:
reports the result of the test and, if accepted, a derivation of the string