A context-free grammar. A grammar consists of a start state and a set
of productions. The set of terminals and nonterminals is implicitly
specified by the productions.
If you need efficient key-based access to productions, you can use a
subclass to implement it.
|
|
__init__(self,
start,
productions,
calculate_leftcorners=True)
Create a new context-free grammar, from the given start state and set
of Productions. |
source code
|
|
|
|
|
|
|
|
|
Nonterminal
|
|
list of Production
|
productions(self,
lhs=None,
rhs=None,
empty=False)
Return the grammar productions, filtered by the left-hand side or the
first item in the right-hand side. |
source code
|
|
set of Nonterminal
|
leftcorners(self,
cat)
Return the set of all nonterminals that the given nonterminal can
start with, including itself. |
source code
|
|
bool
|
is_leftcorner(self,
cat,
left)
True if left is a leftcorner of cat, where left can be a terminal or
a nonterminal. |
source code
|
|
set of Nonterminal
|
|
|
|
|
|
|
_calculate_grammar_forms(self)
Pre-calculate of which form(s) the grammar is. |
source code
|
|
|
|
is_lexical(self)
True if all productions are lexicalised. |
source code
|
|
|
|
is_nonlexical(self)
True if all lexical rules are "preterminals", that is,
unary rules which can be separated in a preprocessing step. |
source code
|
|
|
|
min_len(self)
The right-hand side length of the shortest grammar production. |
source code
|
|
|
|
max_len(self)
The right-hand side length of the longest grammar production. |
source code
|
|
|
|
is_nonempty(self)
True if there are no empty productions. |
source code
|
|
|
|
|
|
|
is_flexible_chomsky_normal_form(self)
True if all productions are of the forms A -> B C, A -> B, or A
-> "s". |
source code
|
|
|
|
is_chomsky_normal_form(self)
A grammar is of Chomsky normal form if all productions are of the
forms A -> B C, or A -> "s". |
source code
|
|
|
|
|
|
|
|