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

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

Issue 62223002: Experimental lexer generator: transfer actions across epsilon transitions correctly when constructi… (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: code review (dcarney) 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 | tools/lexer_generator/nfa.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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 loads.append(load_template % ("dfa [%s]" % name, dfa_i)) 73 loads.append(load_template % ("dfa [%s]" % name, dfa_i))
74 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) 74 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads))
75 return file_template % body 75 return file_template % body
76 76
77 def process_rules(parser_state): 77 def process_rules(parser_state):
78 rule_map = {} 78 rule_map = {}
79 builder = NfaBuilder() 79 builder = NfaBuilder()
80 builder.set_character_classes(parser_state.character_classes) 80 builder.set_character_classes(parser_state.character_classes)
81 for k, v in parser_state.rules.items(): 81 for k, v in parser_state.rules.items():
82 graphs = [] 82 graphs = []
83 for (graph, code, action) in v['regex']: 83 for (graph, code, action, precedence) in v['regex']:
84 # graphs.append(NfaBuilder.add_action(graph, (action, identifier))) 84 graphs.append(NfaBuilder.add_action(graph, (code, action, precedence)))
85 graphs.append(graph)
86 rule_map[k] = builder.nfa(NfaBuilder.or_graphs(graphs)) 85 rule_map[k] = builder.nfa(NfaBuilder.or_graphs(graphs))
87 html_data = [] 86 html_data = []
88 for rule_name, nfa in rule_map.items(): 87 for rule_name, nfa in rule_map.items():
89 (start, dfa_nodes) = nfa.compute_dfa() 88 (start, dfa_nodes) = nfa.compute_dfa()
90 dfa = Dfa(start, dfa_nodes) 89 dfa = Dfa(start, dfa_nodes)
91 html_data.append((rule_name, nfa, dfa)) 90 html_data.append((rule_name, nfa, dfa))
92 html = generate_html(html_data) 91 html = generate_html(html_data)
93 # print html 92 # print html
94 93
95 def parse_file(file_name): 94 def parse_file(file_name):
96 parser_state = RuleParserState() 95 parser_state = RuleParserState()
97 with open(file_name, 'r') as f: 96 with open(file_name, 'r') as f:
98 RuleParser.parse(f.read(), parser_state) 97 RuleParser.parse(f.read(), parser_state)
99 process_rules(parser_state) 98 process_rules(parser_state)
100 99
101 if __name__ == '__main__': 100 if __name__ == '__main__':
102 parse_file('src/lexer/lexer_py.re') 101 parse_file('src/lexer/lexer_py.re')
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/nfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698