| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 import argparse | 28 import argparse |
| 29 from nfa import Nfa | 29 from nfa import Nfa |
| 30 from nfa_builder import NfaBuilder | 30 from nfa_builder import NfaBuilder |
| 31 from dfa import Dfa | 31 from dfa import Dfa, DfaMinimizer |
| 32 from rule_parser import RuleParser, RuleParserState, RuleProcessor | 32 from rule_parser import RuleParser, RuleParserState, RuleProcessor |
| 33 from code_generator import CodeGenerator | 33 from code_generator import CodeGenerator |
| 34 | 34 |
| 35 file_template = ''' | 35 file_template = ''' |
| 36 <html> | 36 <html> |
| 37 <head> | 37 <head> |
| 38 <script src="viz.js"></script> | 38 <script src="viz.js"></script> |
| 39 <script> | 39 <script> |
| 40 function draw(name, id) { | 40 function draw(name, id) { |
| 41 code = document.getElementById(id).innerHTML | 41 code = document.getElementById(id).innerHTML |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 print t | 91 print t |
| 92 | 92 |
| 93 if __name__ == '__main__': | 93 if __name__ == '__main__': |
| 94 | 94 |
| 95 parser = argparse.ArgumentParser() | 95 parser = argparse.ArgumentParser() |
| 96 parser.add_argument('--html') | 96 parser.add_argument('--html') |
| 97 parser.add_argument('--re', default='src/lexer/lexer_py.re') | 97 parser.add_argument('--re', default='src/lexer/lexer_py.re') |
| 98 parser.add_argument('--input') | 98 parser.add_argument('--input') |
| 99 parser.add_argument('--code') | 99 parser.add_argument('--code') |
| 100 parser.add_argument('--minimize-default', action='store_true') | 100 parser.add_argument('--minimize-default', action='store_true') |
| 101 parser.add_argument('--no-verify-default', action='store_true') |
| 101 args = parser.parse_args() | 102 args = parser.parse_args() |
| 102 | 103 |
| 103 re_file = args.re | 104 re_file = args.re |
| 104 print "parsing %s" % re_file | 105 print "parsing %s" % re_file |
| 105 with open(re_file, 'r') as f: | 106 with open(re_file, 'r') as f: |
| 106 rule_processor = RuleProcessor.parse(f.read()) | 107 rule_processor = RuleProcessor.parse(f.read()) |
| 107 | 108 |
| 109 if args.minimize_default: |
| 110 if args.no_verify_default: |
| 111 DfaMinimizer.set_verify(False) |
| 112 rule_processor.default_automata().minimal_dfa() |
| 113 DfaMinimizer.set_verify(True) |
| 114 |
| 108 html_file = args.html | 115 html_file = args.html |
| 109 if html_file: | 116 if html_file: |
| 110 html = generate_html(rule_processor, args.minimize_default) | 117 html = generate_html(rule_processor, args.minimize_default) |
| 111 with open(args.html, 'w') as f: | 118 with open(args.html, 'w') as f: |
| 112 f.write(html) | 119 f.write(html) |
| 113 print "wrote html to %s" % html_file | 120 print "wrote html to %s" % html_file |
| 114 | 121 |
| 115 code_file = args.code | 122 code_file = args.code |
| 116 if code_file: | 123 if code_file: |
| 117 code = generate_code(rule_processor, args.minimize_default) | 124 code = generate_code(rule_processor, args.minimize_default) |
| 118 with open(code_file, 'w') as f: | 125 with open(code_file, 'w') as f: |
| 119 f.write(code) | 126 f.write(code) |
| 120 print "wrote code to %s" % code_file | 127 print "wrote code to %s" % code_file |
| 121 | 128 |
| 122 input_file = args.input | 129 input_file = args.input |
| 123 if input_file: | 130 if input_file: |
| 124 with open(input_file, 'r') as f: | 131 with open(input_file, 'r') as f: |
| 125 lex(rule_processor, f.read()) | 132 lex(rule_processor, f.read()) |
| OLD | NEW |