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

A ShiftReduceParser that allows you to setp through the parsing process, performing a single operation at a time. It also allows you to change the parser’s grammar midway through parsing a text.

The initialize method is used to start parsing a text. shift performs a single shift operation, and reduce performs a single reduce operation. step will perform a single reduce operation if possible; otherwise, it will perform a single shift operation. parses returns the set of parses that have been found by the parser.

Variables:_history – A list of (stack, remaining_text) pairs, containing all of the previous states of the parser. This history is used to implement the undo operation.


__init__(grammar[, trace])
initialize(tokens) Start parsing a given text.
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
reduce([production]) Use production to combine the rightmost stack elements into a single Tree.
return:A list of the productions for which reductions are
return:The portion of the text that is not yet covered by the
set_grammar(grammar) Change the grammar used to parse texts.
shift() Move a token from the beginning of the remaining text to the end of the stack.
return:The parser’s stack.
step() Perform a single parsing operation.
trace([trace]) Set the level of tracing output that should be generated when parsing a text.
undo() Return the parser to its state before the most recent shift or reduce operation.