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

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

Issue 66673003: Experimental lexer generator: DfaState += __str__ (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 | « no previous file | 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 28 matching lines...) Expand all
39 def name(self): 39 def name(self):
40 return self.__name 40 return self.__name
41 41
42 def add_transition(self, key, action, state): 42 def add_transition(self, key, action, state):
43 assert not self.__transitions.has_key(key) 43 assert not self.__transitions.has_key(key)
44 self.__transitions[key] = (state, action) 44 self.__transitions[key] = (state, action)
45 45
46 def transitions(self): 46 def transitions(self):
47 return self.__transitions 47 return self.__transitions
48 48
49 def __str__(self):
50 return str(self.node_number())
51
49 class Dfa(Automaton): 52 class Dfa(Automaton):
50 53
51 def __init__(self, start_name, mapping): 54 def __init__(self, start_name, mapping):
52 super(Dfa, self).__init__() 55 super(Dfa, self).__init__()
53 self.__terminal_set = set() 56 self.__terminal_set = set()
54 name_map = {} 57 name_map = {}
55 action_map = {} 58 action_map = {}
56 for i, name in enumerate(mapping.keys()): 59 for i, name in enumerate(mapping.keys()):
57 name_map[name] = DfaState(name, i) 60 name_map[name] = DfaState(name, i)
58 for name, node_data in mapping.items(): 61 for name, node_data in mapping.items():
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 136
134 def __visit_all_edges(self, visitor, state): 137 def __visit_all_edges(self, visitor, state):
135 edge = set([self.__start]) 138 edge = set([self.__start])
136 first = lambda v: set([x[0] for x in v]) 139 first = lambda v: set([x[0] for x in v])
137 next_edge = lambda node: first(node.transitions().values()) 140 next_edge = lambda node: first(node.transitions().values())
138 return self.visit_edges(edge, next_edge, visitor, state) 141 return self.visit_edges(edge, next_edge, visitor, state)
139 142
140 def to_dot(self): 143 def to_dot(self):
141 iterator = lambda visitor, state: self.__visit_all_edges(visitor, state) 144 iterator = lambda visitor, state: self.__visit_all_edges(visitor, state)
142 return self.generate_dot(self.__start, self.__terminal_set, iterator) 145 return self.generate_dot(self.__start, self.__terminal_set, iterator)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698