C# Class Microsoft.Automata.Grammars.ContextFreeGrammar

Symbolic Context Free Grammar
Afficher le fichier Open project: AutomataDotNet/Automata Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

public ContextFreeGrammar ( Nonterminal startSymbol, IEnumerable productions ) : System
startSymbol Nonterminal
productions IEnumerable
Résultat System

Display() public méthode

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
Résultat void

GetNonVariableSymbols() public méthode

public GetNonVariableSymbols ( ) : IEnumerable
Résultat IEnumerable

GetProductions() public méthode

public GetProductions ( ) : IEnumerable
Résultat IEnumerable

GetProductions() public méthode

public GetProductions ( Nonterminal v ) : IList
v Nonterminal
Résultat IList

GetUsefulNonterminals() public méthode

Return all useful nonterminal symbols.
public GetUsefulNonterminals ( ) : HashSet
Résultat HashSet

GetUsefulNonterminals() public méthode

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
Résultat HashSet

IsValidVariable() public méthode

public IsValidVariable ( Nonterminal v ) : bool
v Nonterminal
Résultat bool

MkCNF() public static méthode

Returns MkCNF(g, true)
public static MkCNF ( ContextFreeGrammar g ) : ContextFreeGrammar
g ContextFreeGrammar
Résultat ContextFreeGrammar

MkCNF() public static méthode

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
Résultat ContextFreeGrammar

MkEGNF() public static méthode

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
Résultat ContextFreeGrammar

MkEGNF() public static méthode

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
Résultat ContextFreeGrammar

MkGNF() public static méthode

Returns MkGNF(g, true)
public static MkGNF ( ContextFreeGrammar g ) : ContextFreeGrammar
g ContextFreeGrammar
Résultat ContextFreeGrammar

MkGNF() public static méthode

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
Résultat ContextFreeGrammar

RemoveEpsilonsAndUselessSymbols() public méthode

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
Résultat ContextFreeGrammar

RemoveUnitProductions() public méthode

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
Résultat ContextFreeGrammar

RemoveUselessSymbols() public méthode

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

RestrictToVariables() public méthode

Restrict the grammar to the given variables.
public RestrictToVariables ( HashSet varSet ) : ContextFreeGrammar
varSet HashSet
Résultat ContextFreeGrammar

ToString() public méthode

Returns the value of Description
public ToString ( ) : string
Résultat string