|
@@ -81,7 +81,7 @@ class Parser(BisonParser):
|
|
|
self.read_buffer = ''
|
|
self.read_buffer = ''
|
|
|
self.read_queue = Queue.Queue()
|
|
self.read_queue = Queue.Queue()
|
|
|
|
|
|
|
|
- self.subtree_map = {}
|
|
|
|
|
|
|
+ #self.subtree_map = {}
|
|
|
self.root_node = None
|
|
self.root_node = None
|
|
|
self.possibilities = self.last_possibilities = []
|
|
self.possibilities = self.last_possibilities = []
|
|
|
|
|
|
|
@@ -193,18 +193,19 @@ class Parser(BisonParser):
|
|
|
if not retval.negated and retval.type != TYPE_OPERATOR:
|
|
if not retval.negated and retval.type != TYPE_OPERATOR:
|
|
|
return retval
|
|
return retval
|
|
|
|
|
|
|
|
- if self.subtree_map: # and retval.type == TYPE_OPERATOR:
|
|
|
|
|
- # Update the subtree map to let the subtree point to its parent
|
|
|
|
|
- # node.
|
|
|
|
|
- parent_nodes = self.subtree_map.keys()
|
|
|
|
|
|
|
+ #if self.subtree_map and retval.type == TYPE_OPERATOR:
|
|
|
|
|
+ # # Update the subtree map to let the subtree point to its parent
|
|
|
|
|
+ # # node.
|
|
|
|
|
+ # parent_nodes = self.subtree_map.keys()
|
|
|
|
|
|
|
|
- if retval.is_leaf:
|
|
|
|
|
- if retval in parent_nodes:
|
|
|
|
|
- self.subtree_map[retval] = None
|
|
|
|
|
- else:
|
|
|
|
|
- for child in retval:
|
|
|
|
|
- if child in parent_nodes:
|
|
|
|
|
- self.subtree_map[child] = retval
|
|
|
|
|
|
|
+ # #if retval.is_leaf:
|
|
|
|
|
+ # # if retval in parent_nodes:
|
|
|
|
|
+ # # self.subtree_map[retval] = None
|
|
|
|
|
+ # #else:
|
|
|
|
|
+ # for child in retval:
|
|
|
|
|
+ # print 'child:', child, 'in', parent_nodes
|
|
|
|
|
+ # if child in parent_nodes:
|
|
|
|
|
+ # self.subtree_map[child] = retval
|
|
|
|
|
|
|
|
if retval.type == TYPE_OPERATOR and retval.op in RULES:
|
|
if retval.type == TYPE_OPERATOR and retval.op in RULES:
|
|
|
handlers = RULES[retval.op]
|
|
handlers = RULES[retval.op]
|
|
@@ -220,8 +221,8 @@ class Parser(BisonParser):
|
|
|
# Record the subtree root node in order to avoid tree traversal.
|
|
# Record the subtree root node in order to avoid tree traversal.
|
|
|
# At this moment, the node is the root node since the expression is
|
|
# At this moment, the node is the root node since the expression is
|
|
|
# parser using the left-innermost parsing strategy.
|
|
# parser using the left-innermost parsing strategy.
|
|
|
- for p in possibilities:
|
|
|
|
|
- self.subtree_map[p.root] = None
|
|
|
|
|
|
|
+ #for p in possibilities:
|
|
|
|
|
+ # self.subtree_map[p.root] = None
|
|
|
|
|
|
|
|
self.possibilities.extend(possibilities)
|
|
self.possibilities.extend(possibilities)
|
|
|
|
|
|
|
@@ -242,8 +243,7 @@ class Parser(BisonParser):
|
|
|
if not suggestion:
|
|
if not suggestion:
|
|
|
return self.root_node
|
|
return self.root_node
|
|
|
|
|
|
|
|
- expression = apply_suggestion(self.root_node, self.subtree_map,
|
|
|
|
|
- suggestion)
|
|
|
|
|
|
|
+ expression = apply_suggestion(self.root_node, suggestion)
|
|
|
|
|
|
|
|
if self.verbose:
|
|
if self.verbose:
|
|
|
print 'After application, expression=', expression
|
|
print 'After application, expression=', expression
|