C# Class Microsoft.Automata.Grammars.ContextFreeGrammar

Symbolic Context Free Grammar
ファイルを表示 Open project: AutomataDotNet/Automata Class Usage Examples

Public Methods

Method Description
ContextFreeGrammar ( Nonterminal startSymbol, IEnumerable productions ) : System
Display ( TextWriter tw ) : void

Writes the productions 'E -> alpha_1 | alpha_2 | ... | alpha_n' to tw with the set of productions for each nonterminal E (variable) per line.

GetNonVariableSymbols ( ) : IEnumerable
GetProductions ( ) : IEnumerable
GetProductions ( Nonterminal v ) : IList
GetUsefulNonterminals ( ) : HashSet

Return all useful nonterminal symbols.

GetUsefulNonterminals ( bool checkBackwardsOnly ) : HashSet

Return all useful nonterminal symbols. If checkBackwardsOnly is true, assume that all symbols are reachable from the start symbol.

IsValidVariable ( Nonterminal v ) : bool
MkCNF ( ContextFreeGrammar g ) : ContextFreeGrammar

Returns MkCNF(g, true)

MkCNF ( ContextFreeGrammar g, bool removeEpsilonsUselessSymbolsUnitsProductions ) : ContextFreeGrammar

Produces the CNF (Chomsky Normal Form) for the grammar g. It first eliminates epsilons, useless symbols, and unit productions. If Assumes that there are no epsilons, useless symbols or unit productions

MkEGNF ( ContextFreeGrammar g ) : ContextFreeGrammar

Produces the EGNF (Extended Greibach Normal Form) for the grammar g. The grammar g can be arbitrary. First removes epsilons and useless symbols from g. Implements a variation of the Blum-Koch algorithm. (Inf. and Comp. vol.150, pp.112-118, 1999)

MkEGNF ( ContextFreeGrammar g, bool removeEpsilonsAndUselessSymbols ) : ContextFreeGrammar

Produces the EGNF (Extended Greibach Normal Form) for the grammar g. Implements a variation of the Blum-Koch algorithm. (Inf. and Comp. vol.150, pp.112-118, 1999)

MkGNF ( ContextFreeGrammar g ) : ContextFreeGrammar

Returns MkGNF(g, true)

MkGNF ( ContextFreeGrammar g, bool removeEpsilonsUselessSymbolsUnitsProductions ) : ContextFreeGrammar

Produces the GNF (Greibach Normal Form) for the grammar g. If g is not already in GNF, first makes CNF. Implements a variation of the Koch-Blum algorithm. (STACS 97, pp. 47-54)

RemoveEpsilonsAndUselessSymbols ( ) : ContextFreeGrammar

Removes epsilon productions and then removes useless symbols. Assumes that the grammar does not accept the empty string and that the language is nonempty.

RemoveUnitProductions ( ) : ContextFreeGrammar

Removes all productions of the form A->B where A and B are variables. Removes also all the useless symbols after the unit production elimination. Assumes that the grammar has no epsilon productions.

RemoveUselessSymbols ( ) : ContextFreeGrammar

Removes useless symbols from the grammar. Assumes that the language is nonempty.

RestrictToVariables ( HashSet varSet ) : ContextFreeGrammar

Restrict the grammar to the given variables.

ToString ( ) : string

Returns the value of Description

Private Methods

Method Description
AllVariablesExceptTheStartSymbol ( ) : IEnumerable
ContextFreeGrammar ( List variables, Nonterminal startSymbol, Dictionary productionMap ) : System
DescribeProductions ( Nonterminal v ) : string
EliminateNullables ( Nonterminal v, HashSet nullables ) : IEnumerable
EnumerateNullableFreeVariations ( ConsList symbols, HashSet nullables ) : IEnumerable>
FinalStateHasVariableMoves ( Automaton MB ) : bool
GetNullables ( ) : HashSet
GetUnitClosure ( Nonterminal v ) : HashSet
IsInCNF ( ) : bool
IsInGNF ( ) : bool
Lookup ( Nonterminal>.Dictionary vars, Nonterminal key, int &nonterminalID ) : Nonterminal
StartSymbolAppearsInRhs ( ) : bool

Method Details

ContextFreeGrammar() public method

public ContextFreeGrammar ( Nonterminal startSymbol, IEnumerable productions ) : System
startSymbol Nonterminal
productions IEnumerable
return System

Display() public method

Writes the productions 'E -> alpha_1 | alpha_2 | ... | alpha_n' to tw with the set of productions for each nonterminal E (variable) per line.
public Display ( TextWriter tw ) : void
tw System.IO.TextWriter
return void

GetNonVariableSymbols() public method

public GetNonVariableSymbols ( ) : IEnumerable
return IEnumerable

GetProductions() public method

public GetProductions ( ) : IEnumerable
return IEnumerable

GetProductions() public method

public GetProductions ( Nonterminal v ) : IList
v Nonterminal
return IList

GetUsefulNonterminals() public method

Return all useful nonterminal symbols.
public GetUsefulNonterminals ( ) : HashSet
return HashSet

GetUsefulNonterminals() public method

Return all useful nonterminal symbols. If checkBackwardsOnly is true, assume that all symbols are reachable from the start symbol.
public GetUsefulNonterminals ( bool checkBackwardsOnly ) : HashSet
checkBackwardsOnly bool
return HashSet

IsValidVariable() public method

public IsValidVariable ( Nonterminal v ) : bool
v Nonterminal
return bool

MkCNF() public static method

Returns MkCNF(g, true)
public static MkCNF ( ContextFreeGrammar g ) : ContextFreeGrammar
g ContextFreeGrammar
return ContextFreeGrammar

MkCNF() public static method

Produces the CNF (Chomsky Normal Form) for the grammar g. It first eliminates epsilons, useless symbols, and unit productions. If Assumes that there are no epsilons, useless symbols or unit productions
public static MkCNF ( ContextFreeGrammar g, bool removeEpsilonsUselessSymbolsUnitsProductions ) : ContextFreeGrammar
g ContextFreeGrammar
removeEpsilonsUselessSymbolsUnitsProductions bool
return ContextFreeGrammar

MkEGNF() public static method

Produces the EGNF (Extended Greibach Normal Form) for the grammar g. The grammar g can be arbitrary. First removes epsilons and useless symbols from g. Implements a variation of the Blum-Koch algorithm. (Inf. and Comp. vol.150, pp.112-118, 1999)
public static MkEGNF ( ContextFreeGrammar g ) : ContextFreeGrammar
g ContextFreeGrammar the grammar to be normalized
return ContextFreeGrammar

MkEGNF() public static method

Produces the EGNF (Extended Greibach Normal Form) for the grammar g. Implements a variation of the Blum-Koch algorithm. (Inf. and Comp. vol.150, pp.112-118, 1999)
public static MkEGNF ( ContextFreeGrammar g, bool removeEpsilonsAndUselessSymbols ) : ContextFreeGrammar
g ContextFreeGrammar the grammar to be normalized
removeEpsilonsAndUselessSymbols bool if true, first removes epsilons and useless symbols, otherwise assumes that epsilons do not occur
return ContextFreeGrammar

MkGNF() public static method

Returns MkGNF(g, true)
public static MkGNF ( ContextFreeGrammar g ) : ContextFreeGrammar
g ContextFreeGrammar
return ContextFreeGrammar

MkGNF() public static method

Produces the GNF (Greibach Normal Form) for the grammar g. If g is not already in GNF, first makes CNF. Implements a variation of the Koch-Blum algorithm. (STACS 97, pp. 47-54)
public static MkGNF ( ContextFreeGrammar g, bool removeEpsilonsUselessSymbolsUnitsProductions ) : ContextFreeGrammar
g ContextFreeGrammar
removeEpsilonsUselessSymbolsUnitsProductions bool
return ContextFreeGrammar

RemoveEpsilonsAndUselessSymbols() public method

Removes epsilon productions and then removes useless symbols. Assumes that the grammar does not accept the empty string and that the language is nonempty.
public RemoveEpsilonsAndUselessSymbols ( ) : ContextFreeGrammar
return ContextFreeGrammar

RemoveUnitProductions() public method

Removes all productions of the form A->B where A and B are variables. Removes also all the useless symbols after the unit production elimination. Assumes that the grammar has no epsilon productions.
public RemoveUnitProductions ( ) : ContextFreeGrammar
return ContextFreeGrammar

RemoveUselessSymbols() public method

Removes useless symbols from the grammar. Assumes that the language is nonempty.
public RemoveUselessSymbols ( ) : ContextFreeGrammar
return ContextFreeGrammar

RestrictToVariables() public method

Restrict the grammar to the given variables.
public RestrictToVariables ( HashSet varSet ) : ContextFreeGrammar
varSet HashSet
return ContextFreeGrammar

ToString() public method

Returns the value of Description
public ToString ( ) : string
return string