Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: tools/lexer_generator/dfa.py

Issue 70443006: Expermental parser: fix state iteration in codegen (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 the V8 project authors. All rights reserved. 1 # Copyright 2013 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 def start_state(self): 85 def start_state(self):
86 return self.__start 86 return self.__start
87 87
88 def start_set(self): 88 def start_set(self):
89 return set([self.__start]) 89 return set([self.__start])
90 90
91 def terminal_set(self): 91 def terminal_set(self):
92 return set(self.__terminal_set) 92 return set(self.__terminal_set)
93 93
94 def all_states_iter(self):
95 return self.__start.state_iter()
96
97 @staticmethod 94 @staticmethod
98 def __match_char(state, char): 95 def __match_char(state, char):
99 match = list(state.state_iter(key_filter = lambda k: k.matches_char(char))) 96 match = list(state.state_iter(key_filter = lambda k: k.matches_char(char)))
100 if not match: return None 97 if not match: return None
101 assert len(match) == 1 98 assert len(match) == 1
102 return match[0] 99 return match[0]
103 100
104 def collect_actions(self, string): 101 def collect_actions(self, string):
105 state = self.__start 102 state = self.__start
106 for c in string: 103 for c in string:
(...skipping 22 matching lines...) Expand all
129 yield (state.action(), last_position, pos) 126 yield (state.action(), last_position, pos)
130 last_position = pos 127 last_position = pos
131 # lex next token 128 # lex next token
132 next = Dfa.__match_char(self.__start, c) 129 next = Dfa.__match_char(self.__start, c)
133 assert next 130 assert next
134 state = next 131 state = next
135 assert state.action() # must invoke default action here 132 assert state.action() # must invoke default action here
136 yield (state.action(), last_position, len(string)) 133 yield (state.action(), last_position, len(string))
137 134
138 def minimize(self): 135 def minimize(self):
139 pass 136 paritions = []
137 working_set = []
138 action_map = {}
139 id_map = {}
140 def f(state, visitor_state):
141 node_number = state.node_number()
142 assert not node_number in id_map
143 id_map[node_number] = state
144 action = state.action()
145 if not action in action_map:
146 action_map[action] = set()
147 action_map[action].add(node_number)
148 self.visit_all_states(f)
149 total = 0
150 for p in action_map.values():
151 paritions.append(p)
152 total += len(p)
153 assert total == self.__node_count
154
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698