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

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

Issue 68843002: Experimental lexer generator: More code generation. (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 | « src/lexer/lexer_py.re ('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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 def transitions(self): 53 def transitions(self):
54 return self.__transitions 54 return self.__transitions
55 55
56 def to_code(self): 56 def to_code(self):
57 # FIXME: add different check types (if, switch, lookup table) 57 # FIXME: add different check types (if, switch, lookup table)
58 # FIXME: add action + break / continue 58 # FIXME: add action + break / continue
59 # FIXME: add default action 59 # FIXME: add default action
60 code = ''' 60 code = '''
61 code_%s: 61 code_%s:
62 fprintf(stderr, "state %s, char at hand is %%c\\n", c); 62 fprintf(stderr, "state %s, char at hand is %%c (%%d)\\n", c, c);
63 ''' % (self.node_number(), self.node_number()) 63 ''' % (self.node_number(), self.node_number())
64 64
65 for key, state in self.__transitions.items(): 65 for key, state in self.__transitions.items():
66 code += key.to_code() 66 code += key.to_code()
67 code += ''' { 67 code += ''' {
68 c = *(++cursor); 68 c = *(++cursor);
69 goto code_%s; 69 goto code_%s;
70 }''' % state.node_number() 70 }
71 ''' % state.node_number()
72
73 action = self.action()
74 if action:
75 if action[1] == 'terminate':
76 code += 'return 0;'
77 elif action[1] == 'terminate_illegal':
78 code += 'return 1;'
79 else:
80 code += self.action()[1];
81
71 return code 82 return code
72 83
73 class Dfa(Automaton): 84 class Dfa(Automaton):
74 85
75 def __init__(self, start_name, mapping): 86 def __init__(self, start_name, mapping):
76 super(Dfa, self).__init__() 87 super(Dfa, self).__init__()
77 self.__terminal_set = set() 88 self.__terminal_set = set()
78 self.__name_map = {} 89 self.__name_map = {}
79 for i, (name, node_data) in enumerate(mapping.items()): 90 for i, (name, node_data) in enumerate(mapping.items()):
80 node = DfaState(name, i, node_data['actions']) 91 node = DfaState(name, i, node_data['actions'])
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return self.generate_dot(self.__start, self.__terminal_set, iterator, state_ iterator) 157 return self.generate_dot(self.__start, self.__terminal_set, iterator, state_ iterator)
147 158
148 def to_code(self): 159 def to_code(self):
149 code = ''' 160 code = '''
150 char c = *cursor; 161 char c = *cursor;
151 goto code_%s; 162 goto code_%s;
152 ''' % (self.__start.node_number()) 163 ''' % (self.__start.node_number())
153 for n in self.__name_map.values(): 164 for n in self.__name_map.values():
154 code += n.to_code() 165 code += n.to_code()
155 return code 166 return code
OLDNEW
« no previous file with comments | « src/lexer/lexer_py.re ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698