| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 code += ''' | 61 code += ''' |
| 62 code_start: | 62 code_start: |
| 63 ''' | 63 ''' |
| 64 code += ''' | 64 code += ''' |
| 65 code_%s: | 65 code_%s: |
| 66 //fprintf(stderr, "state %s\\n"); | 66 //fprintf(stderr, "state %s\\n"); |
| 67 ''' % (state.node_number(), | 67 ''' % (state.node_number(), |
| 68 state.node_number()) | 68 state.node_number()) |
| 69 | 69 |
| 70 action = state.action() | 70 action = state.action() |
| 71 if (action and action.type() != 'terminate' and |
| 72 action.type() != 'terminate_illegal' and action.type() != 'code' and |
| 73 action.type() != 'push_token' and action.type() != 'skip'): |
| 74 raise Exception("unknown type %s" % action.type()) |
| 75 |
| 71 if action: | 76 if action: |
| 72 if action.type() == 'terminate': | 77 if action.type() == 'terminate': |
| 73 code += 'PUSH_TOKEN(Token::EOS); return 0;' | 78 code += 'PUSH_TOKEN(Token::EOS); return 0;' |
| 74 return code | 79 return code |
| 75 elif action.type() == 'terminate_illegal': | 80 elif action.type() == 'terminate_illegal': |
| 76 code += 'PUSH_TOKEN(Token::ILLEGAL); return 1;' | 81 code += 'PUSH_TOKEN(Token::ILLEGAL); return 1;' |
| 77 return code | 82 return code |
| 78 elif action.type() == 'skip': | 83 elif action.type() == 'skip': |
| 79 code += 'SKIP(); goto code_start;' | 84 code += 'SKIP(); goto code_start;' |
| 80 return code | 85 return code |
| 86 elif action.type() == 'code': |
| 87 code += '%s\n' % action.data() |
| 81 | 88 |
| 82 code += ''' | 89 code += ''' |
| 83 //fprintf(stderr, "char at hand is %c (%d)\\n", yych, yych);\n''' | 90 //fprintf(stderr, "char at hand is %c (%d)\\n", yych, yych);\n''' |
| 84 | 91 |
| 85 for key, s in state.transitions().items(): | 92 for key, s in state.transitions().items(): |
| 86 code += CodeGenerator.key_to_code(key) | 93 code += CodeGenerator.key_to_code(key) |
| 87 code += ''' { | 94 code += ''' { |
| 88 FORWARD(); | 95 FORWARD(); |
| 89 goto code_%s; | 96 goto code_%s; |
| 90 } | 97 } |
| 91 ''' % s.node_number() | 98 ''' % s.node_number() |
| 92 | 99 |
| 93 if action: | 100 if action: |
| 94 if action.type() == 'code': | 101 if action.type() == 'push_token': |
| 95 code += '%s\n\ngoto code_%s;\n' % (action.data(), | |
| 96 start_node_number) | |
| 97 elif action.type() == 'push_token': | |
| 98 content = 'PUSH_TOKEN(Token::%s);' % action.data() | 102 content = 'PUSH_TOKEN(Token::%s);' % action.data() |
| 99 code += '%s\ngoto code_%s;\n' % (content, | 103 code += '%s\ngoto code_%s;\n' % (content, |
| 100 start_node_number) | 104 start_node_number) |
| 101 else: | 105 elif action.type() == 'code': |
| 102 raise Exception("unknown type %s" % action.type()) | 106 code += 'goto code_start;' |
| 103 else: | 107 else: |
| 104 code += 'goto default_action;' | 108 code += 'goto default_action;' |
| 105 return code | 109 return code |
| 106 | 110 |
| 107 @staticmethod | 111 @staticmethod |
| 108 def rule_processor_to_code(rule_processor, use_mdfa): | 112 def rule_processor_to_code(rule_processor, use_mdfa): |
| 109 if use_mdfa: | 113 if use_mdfa: |
| 110 dfa = rule_processor.default_automata().minimal_dfa() | 114 dfa = rule_processor.default_automata().minimal_dfa() |
| 111 else: | 115 else: |
| 112 dfa = rule_processor.default_automata().dfa() | 116 dfa = rule_processor.default_automata().dfa() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 140 code += ''' | 144 code += ''' |
| 141 CHECK(false); | 145 CHECK(false); |
| 142 %s | 146 %s |
| 143 return 0; | 147 return 0; |
| 144 } | 148 } |
| 145 | 149 |
| 146 } | 150 } |
| 147 } | 151 } |
| 148 ''' % default_action_code | 152 ''' % default_action_code |
| 149 return code | 153 return code |
| OLD | NEW |