class nltk.SteppingRecursiveDescentParser(grammar, trace=0)[source]

A RecursiveDescentParser that allows you to step through the parsing process, performing a single operation at a time.

The initialize method is used to start parsing a text. expand expands the first element on the frontier using a single CFG production, and match matches the first element on the frontier against the next text token. backtrack undoes the most recent expand or match operation. step performs a single expand, match, or backtrack operation. parses returns the set of parses that have been found by the parser.

  • _history – A list of (rtext, tree, frontier) tripples, containing the previous states of the parser. This history is used to implement the backtrack operation.
  • _tried_e – A record of all productions that have been tried for a given tree. This record is used by expand to perform the next untried production.
  • _tried_m – A record of what tokens have been matched for a given tree. This record is used by step to decide whether or not to match a token.



__init__(grammar[, trace])
backtrack() Return the parser to its state before the most recent match or expand operation.
return:Whether the parser’s current state represents a
expand([production]) Expand the first element of the frontier.
return:A list of all the productions for which expansions
return:A list of the tree locations of all subtrees that
initialize(tokens) Start parsing a given text.
match() Match the first element of the frontier.
parse_all(sent, *args, **kwargs)
parse_one(sent, *args, **kwargs)
rtype:Tree or None
parse_sents(sents, *args, **kwargs) Apply self.parse() to each element of sents.
return:An iterator of the parses that have been found by this
return:The portion of the text that is not yet covered by the
set_grammar(grammar) Change the grammar used to parse texts.
step() Perform a single parsing operation.
trace([trace]) Set the level of tracing output that should be generated when parsing a text.
return:A partial structure for the text that is
return:A list of all the untried productions for which
return:Whether the first element of the frontier is a token