FAdo.cgf¶
Context Free Grammars Manipulation.
Basic context-free grammars manipulation for building uniform random generetors
- class CFGGenerator(cfgr, size)[source]¶
CFG uniform genetaror
- ..seealso: Generating words in a context-free language uniformly at random. Harry Mairson
Information Processing Letters, 49-2, 95-92. 1994
Object initialization :param cfgr: grammar for the random objects :type cfgr: CNF :param size: size of objects :type size: integer
- class CFGrammar(gram)[source]¶
Class for context-free grammars
- Variables:
Rules – grammar rules
Terminals – terminals symbols
Nonterminals – nonterminals symbols
Start (str) – start symbol
ntr – dictionary of rules for each nonterminal
Initialization
- Parameters:
gram – is a list for productions; each production is a tuple (LeftHandside, RightHandside) with LeftHandside nonterminal, RightHandside list of symbols, First production is for start symbol
- class CNF(gram, mark='A@')[source]¶
Chomsky Normal Form. No useless nonterminals or eepsipsilon rules are ALLOWED… Given a CFG grammar description generates one in CNF Then its possible to random generate words of a given size. Before some pre-calculations are needed.
Initialization
- Parameters:
gram – is a list for productions; each production is a tuple (LeftHandside, RightHandside) with LeftHandside nonterminal, RightHandside list of symbols, First production is for start symbol
- class REStringRGenerator(Sigma=None, size=10, cfgr=None, epsilon=None, empty=None, ident='Ti')[source]¶
Uniform random Generator for reStrings
- Uniform random generator for regular expressions. Used without arguments generates an uncollapsible re
over {a,b} with size 10. For generate an arbitary re over an alphabet of 10 symbols of size 100: reStringRGenerator (smallAlphabet(10),100,reGrammar[“g_regular_base”])
- Parameters:
Note
the grammar can have already this symbols