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

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

Issue 152823002: Experimental parser: use sentinal values for actions (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 months 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/lexer_test.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | 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 17 matching lines...) Expand all
28 from transition_keys import TransitionKey 28 from transition_keys import TransitionKey
29 from automaton import * 29 from automaton import *
30 30
31 class NfaState(AutomatonState): 31 class NfaState(AutomatonState):
32 32
33 def __init__(self): 33 def __init__(self):
34 super(NfaState, self).__init__() 34 super(NfaState, self).__init__()
35 self.__transitions = {} 35 self.__transitions = {}
36 self.__unclosed = set() 36 self.__unclosed = set()
37 self.__epsilon_closure = None 37 self.__epsilon_closure = None
38 self.__action = None 38 self.__action = Action.empty_action()
39 39
40 def transitions_to_multiple_states(self): 40 def transitions_to_multiple_states(self):
41 return True 41 return True
42 42
43 def epsilon_closure_iter(self): 43 def epsilon_closure_iter(self):
44 return iter(self.__epsilon_closure) 44 return iter(self.__epsilon_closure)
45 45
46 def set_epsilon_closure(self, closure): 46 def set_epsilon_closure(self, closure):
47 assert self.is_closed() 47 assert self.is_closed()
48 assert self.__epsilon_closure == None 48 assert self.__epsilon_closure == None
49 self.__epsilon_closure = frozenset(closure) 49 self.__epsilon_closure = frozenset(closure)
50 50
51 def action(self): 51 def action(self):
52 assert self.is_closed() 52 assert self.is_closed()
53 return self.__action 53 return self.__action
54 54
55 def set_action(self, action): 55 def set_action(self, action):
56 assert not self.is_closed() 56 assert not self.is_closed()
57 assert not self.__action 57 assert not self.__action
58 assert isinstance(action, Action)
58 self.__action = action 59 self.__action = action
59 60
60 def transitions(self): 61 def transitions(self):
61 assert self.is_closed() 62 assert self.is_closed()
62 return self.__transitions 63 return self.__transitions
63 64
64 def __add_transition(self, key, next_state): 65 def __add_transition(self, key, next_state):
65 assert key != None 66 assert key != None
66 if next_state == None: 67 if next_state == None:
67 assert not self.is_closed(), "already closed" 68 assert not self.is_closed(), "already closed"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 f = lambda state: state.transition_state_iter_for_key(key) 157 f = lambda state: state.transition_state_iter_for_key(key)
157 match_states = set(chain(*map(f, nfa_state_set))) 158 match_states = set(chain(*map(f, nfa_state_set)))
158 transition_state = self.__to_dfa(match_states, dfa_nodes, end_node) 159 transition_state = self.__to_dfa(match_states, dfa_nodes, end_node)
159 dfa_nodes[name]['transitions'][key] = transition_state 160 dfa_nodes[name]['transitions'][key] = transition_state
160 return name 161 return name
161 162
162 def compute_dfa(self): 163 def compute_dfa(self):
163 dfa_nodes = {} 164 dfa_nodes = {}
164 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) 165 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end)
165 return (start_name, dfa_nodes) 166 return (start_name, dfa_nodes)
OLDNEW
« no previous file with comments | « tools/lexer_generator/lexer_test.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698