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

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

Issue 209473005: Experimental parser: dfa path iteration test (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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/dfa_path_writer.py ('k') | tools/lexer_generator/transition_key.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 16 matching lines...) Expand all
27 27
28 import logging 28 import logging
29 import argparse 29 import argparse
30 from dot_utilities import * 30 from dot_utilities import *
31 from nfa import Nfa 31 from nfa import Nfa
32 from nfa_builder import NfaBuilder 32 from nfa_builder import NfaBuilder
33 from dfa import Dfa 33 from dfa import Dfa
34 from dfa_minimizer import DfaMinimizer 34 from dfa_minimizer import DfaMinimizer
35 from rule_parser import RuleParser, RuleParserState, RuleProcessor 35 from rule_parser import RuleParser, RuleParserState, RuleProcessor
36 from code_generator import CodeGenerator 36 from code_generator import CodeGenerator
37 from dfa_path_writer import DfaPathWriter
37 38
38 file_template = ''' 39 file_template = '''
39 <html> 40 <html>
40 <head> 41 <head>
41 <script src="viz.js"></script> 42 <script src="viz.js"></script>
42 <script> 43 <script>
43 function draw(name, id) { 44 function draw(name, id) {
44 code = document.getElementById(id).innerHTML 45 code = document.getElementById(id).innerHTML
45 document.body.innerHTML += "<h1>" + name + "</h1>"; 46 document.body.innerHTML += "<h1>" + name + "</h1>";
46 try { 47 try {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 parser.add_argument('--input') 135 parser.add_argument('--input')
135 parser.add_argument('--code') 136 parser.add_argument('--code')
136 parser.add_argument('--encoding', default='latin1') 137 parser.add_argument('--encoding', default='latin1')
137 parser.add_argument('--no-optimize-default', action='store_true') 138 parser.add_argument('--no-optimize-default', action='store_true')
138 parser.add_argument('--no-minimize-default', action='store_true') 139 parser.add_argument('--no-minimize-default', action='store_true')
139 parser.add_argument('--no-verify-default', action='store_true') 140 parser.add_argument('--no-verify-default', action='store_true')
140 parser.add_argument('--no-inline', action='store_true') 141 parser.add_argument('--no-inline', action='store_true')
141 parser.add_argument('--verbose', action='store_true') 142 parser.add_argument('--verbose', action='store_true')
142 parser.add_argument('--debug-code', action='store_true') 143 parser.add_argument('--debug-code', action='store_true')
143 parser.add_argument('--profile', action='store_true') 144 parser.add_argument('--profile', action='store_true')
145 parser.add_argument('--lexer-shell-test-file')
144 parser.add_argument('--rule-html') 146 parser.add_argument('--rule-html')
145 args = parser.parse_args() 147 args = parser.parse_args()
146 148
147 minimize_default = not args.no_minimize_default 149 minimize_default = not args.no_minimize_default
148 if args.verbose: 150 if args.verbose:
149 logging.basicConfig(level=logging.INFO) 151 logging.basicConfig(level=logging.INFO)
150 152
151 if args.profile: 153 if args.profile:
152 profiler = start_profiling() 154 profiler = start_profiling()
153 155
154 re_file = args.re 156 re_file = args.re
155 logging.info("parsing %s" % re_file) 157 logging.info("parsing %s" % re_file)
156 with open(re_file, 'r') as f: 158 with open(re_file, 'r') as f:
157 rule_processor = RuleProcessor(f.read(), args.encoding) 159 rule_processor = RuleProcessor(f.read(), args.encoding)
158 160
159 if not args.no_optimize_default: 161 if not args.no_optimize_default:
160 rule_processor.default_automata().optimize_dfa() 162 rule_processor.default_automata().optimize_dfa()
161 163
162 if minimize_default: 164 if minimize_default:
163 if args.no_verify_default: 165 if args.no_verify_default:
164 DfaMinimizer.set_verify(False) 166 DfaMinimizer.set_verify(False)
165 dfa = rule_processor.default_automata().dfa() 167 dfa = rule_processor.default_automata().dfa()
166 mdfa = rule_processor.default_automata().minimal_dfa() 168 mdfa = rule_processor.default_automata().minimal_dfa()
167 logging.info("nodes reduced from %s to %s" % ( 169 logging.info("nodes reduced from %s to %s" % (
168 dfa.node_count(), mdfa.node_count())) 170 dfa.node_count(), mdfa.node_count()))
169 DfaMinimizer.set_verify(True) 171 DfaMinimizer.set_verify(True)
170 172
171 html_file = args.html 173 if args.lexer_shell_test_file:
172 if html_file: 174 dfa = rule_processor.default_automata().dfa()
175 if minimize_default:
176 dfa = rule_processor.default_automata().minimal_dfa()
177 path_writer = DfaPathWriter(dfa)
178 with open(args.lexer_shell_test_file, 'w') as f:
179 path_writer.write_lexer_shell_test_file(f)
180 logging.info("wrote lexer_shell file to %s" % args.lexer_shell_test_file)
181
182 if args.html:
173 html = generate_html( 183 html = generate_html(
174 rule_processor, minimize_default, not args.no_merge_html) 184 rule_processor, minimize_default, not args.no_merge_html)
175 with open(args.html, 'w') as f: 185 with open(args.html, 'w') as f:
176 f.write(html) 186 f.write(html)
177 logging.info("wrote html to %s" % html_file) 187 logging.info("wrote html to %s" % args.html)
178 188
179 rule_html_file = args.rule_html 189 if args.rule_html:
180 if rule_html_file:
181 html = generate_rule_tree_html(rule_processor) 190 html = generate_rule_tree_html(rule_processor)
182 with open(rule_html_file, 'w') as f: 191 with open(args.rule_html, 'w') as f:
183 f.write(html) 192 f.write(html)
184 logging.info("wrote html to %s" % rule_html_file) 193 logging.info("wrote rule html to %s" % args.rule_html)
185 194
186 code_file = args.code 195 if args.code:
187 if code_file:
188 code_generator = CodeGenerator(rule_processor, 196 code_generator = CodeGenerator(rule_processor,
189 minimize_default = minimize_default, 197 minimize_default = minimize_default,
190 inline = not args.no_inline, 198 inline = not args.no_inline,
191 debug_print = args.debug_code) 199 debug_print = args.debug_code)
192 code = code_generator.process() 200 code = code_generator.process()
193 with open(code_file, 'w') as f: 201 with open(args.code, 'w') as f:
194 f.write(code) 202 f.write(code)
195 logging.info("wrote code to %s" % code_file) 203 logging.info("wrote code to %s" % args.code)
196 204
197 input_file = args.input 205 if args.input:
198 if input_file: 206 with open(args.input, 'r') as f:
199 with open(input_file, 'r') as f:
200 lex(rule_processor, f.read()) 207 lex(rule_processor, f.read())
201 208
202 if args.profile: 209 if args.profile:
203 stop_profiling(profiler) 210 stop_profiling(profiler)
OLDNEW
« no previous file with comments | « tools/lexer_generator/dfa_path_writer.py ('k') | tools/lexer_generator/transition_key.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698