summaryrefslogtreecommitdiff
path: root/ply
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2015-04-22 06:59:25 -0500
committerDavid Beazley <dave@dabeaz.com>2015-04-22 06:59:25 -0500
commit8fb06b0c55e91d2d097a4d19782e22664a759830 (patch)
tree1fdebe57f15d4edf7fadd2209cee525de3546e14 /ply
parentaf651673ba6117a0a5405055a92170fffd028106 (diff)
downloadply-8fb06b0c55e91d2d097a4d19782e22664a759830.tar.gz
Continued work on defaulted states. Some bug fixes. In progress.
Diffstat (limited to 'ply')
-rw-r--r--ply/yacc.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/ply/yacc.py b/ply/yacc.py
index 63d4877..7dcd6c5 100644
--- a/ply/yacc.py
+++ b/ply/yacc.py
@@ -288,7 +288,8 @@ class LRParser:
self.action = lrtab.lr_action
self.goto = lrtab.lr_goto
self.errorfunc = errorf
- self.defaulted_states = { }
+ self.set_defaulted_states()
+ self.errorok = True
def errok(self):
self.errorok = True
@@ -301,7 +302,7 @@ class LRParser:
self.symstack.append(sym)
self.statestack.append(0)
- # Defaulted state support (Experimental)
+ # Defaulted state support.
# This method identifies parser states where there is only one possible reduction action.
# For such states, the parser can make a choose to make a rule reduction without consuming
# the next look-ahead token. This delayed invocation of the tokenizer can be useful in
@@ -309,12 +310,16 @@ class LRParser:
# each other or change states (i.e., manipulation of scope, lexer states, etc.).
#
# See: http://www.gnu.org/software/bison/manual/html_node/Default-Reductions.html#Default-Reductions
- def use_defaulted_states(self):
+ def set_defaulted_states(self):
+ self.defaulted_states = {}
for state, actions in self.action.items():
rules = list(actions.values())
if rules and rules[0] < 0 and all(rules[0] == rule for rule in rules):
self.defaulted_states[state] = rules[0]
+ def disable_defaulted_states(self):
+ self.defaulted_states = {}
+
def parse(self, input=None, lexer=None, debug=False, tracking=False, tokenfunc=None):
if debug or yaccdevel:
if isinstance(debug, int):