Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 name = ".".join(str(x.node_number()) for x in sorted(nfa_state_set)) | 326 name = ".".join(str(x.node_number()) for x in sorted(nfa_state_set)) |
| 327 if name in dfa_nodes: | 327 if name in dfa_nodes: |
| 328 return name | 328 return name |
| 329 dfa_nodes[name] = { | 329 dfa_nodes[name] = { |
| 330 'transitions': {}, | 330 'transitions': {}, |
| 331 'terminal': end_node in nfa_state_set} | 331 'terminal': end_node in nfa_state_set} |
| 332 for key in NfaState.gather_transition_keys(nfa_state_set): | 332 for key in NfaState.gather_transition_keys(nfa_state_set): |
| 333 f = lambda acc, state: acc | state.key_matches(key) | 333 f = lambda acc, state: acc | state.key_matches(key) |
| 334 transitions = reduce(f, nfa_state_set, set()) | 334 transitions = reduce(f, nfa_state_set, set()) |
| 335 match_states = set() | 335 match_states = set() |
| 336 actions = set() | 336 actions = [] |
| 337 for (state, action) in transitions: | 337 for (state, action) in transitions: |
| 338 match_states.add(state) | 338 match_states.add(state) |
| 339 if action: | 339 if action: |
| 340 actions.add(action) | 340 actions.append((action[2], action[0], action[1])) |
|
dcarney
2013/11/07 08:08:54
action should just always be (precedence, id, code
marja
2013/11/07 08:25:41
Done.
| |
| 341 | |
| 342 # Pull in actions which can be taken with an epsilon transition from the | |
| 343 # match state. | |
|
dcarney
2013/11/07 08:08:54
what's with all these spaces and comments - you wa
| |
| 344 e = TransitionKey.epsilon() | |
| 345 if e in state.transitions(): | |
| 346 for e_trans in state.transitions()[e]: | |
| 347 if e_trans[1]: | |
| 348 actions.append((e_trans[1][2], e_trans[1][0], e_trans[1][1])) | |
| 349 | |
| 341 assert len(match_states) == len(transitions) | 350 assert len(match_states) == len(transitions) |
| 342 assert not actions or len(actions) == 1 | 351 |
| 343 action = iter(actions).next() if actions else None | 352 actions.sort() |
| 353 action = (actions[0][1], actions[0][2]) if actions else None | |
| 344 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) | 354 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) |
| 345 dfa_nodes[name]['transitions'][key] = (transition_state, action) | 355 dfa_nodes[name]['transitions'][key] = (transition_state, action) |
| 346 return name | 356 return name |
| 347 | 357 |
| 348 def compute_dfa(self): | 358 def compute_dfa(self): |
| 349 self.__compute_epsilon_closures() | 359 self.__compute_epsilon_closures() |
| 350 dfa_nodes = {} | 360 dfa_nodes = {} |
| 351 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) | 361 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) |
| 352 return (start_name, dfa_nodes) | 362 return (start_name, dfa_nodes) |
| 353 | 363 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 376 digraph finite_state_machine { | 386 digraph finite_state_machine { |
| 377 rankdir=LR; | 387 rankdir=LR; |
| 378 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s | 388 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s |
| 379 node [shape = doublecircle, style=unfilled]; S_%s | 389 node [shape = doublecircle, style=unfilled]; S_%s |
| 380 node [shape = circle]; | 390 node [shape = circle]; |
| 381 %s | 391 %s |
| 382 } | 392 } |
| 383 ''' % (self.__start.node_number(), | 393 ''' % (self.__start.node_number(), |
| 384 self.__end.node_number(), | 394 self.__end.node_number(), |
| 385 "\n".join(node_content)) | 395 "\n".join(node_content)) |
| OLD | NEW |