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

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

Issue 72693002: Experimental lexer generator: Don't go BACK(); (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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 action = state.action() 70 action = state.action()
71 if action: 71 if action:
72 if action.type() == 'terminate': 72 if action.type() == 'terminate':
73 code += 'PUSH_TOKEN(Token::EOS); return 0;' 73 code += 'PUSH_TOKEN(Token::EOS); return 0;'
74 return code 74 return code
75 elif action.type() == 'terminate_illegal': 75 elif action.type() == 'terminate_illegal':
76 code += 'PUSH_TOKEN(Token::ILLEGAL); return 1;' 76 code += 'PUSH_TOKEN(Token::ILLEGAL); return 1;'
77 return code 77 return code
78 78
79 code += ''' 79 code += '''
80 yych = *(++cursor_);
81 //fprintf(stderr, "char at hand is %c (%d)\\n", yych, yych);\n''' 80 //fprintf(stderr, "char at hand is %c (%d)\\n", yych, yych);\n'''
82 81
83 for key, s in state.transitions().items(): 82 for key, s in state.transitions().items():
84 code += CodeGenerator.key_to_code(key) 83 code += CodeGenerator.key_to_code(key)
85 code += ''' { 84 code += ''' {
85 FORWARD();
86 goto code_%s; 86 goto code_%s;
87 } 87 }
88 ''' % s.node_number() 88 ''' % s.node_number()
89 89
90 if action: 90 if action:
91 if action.type() == 'code': 91 if action.type() == 'code':
92 code += '%s\nBACK();\ngoto code_%s;\n' % (action.data(), 92 code += '%s\n\ngoto code_%s;\n' % (action.data(),
93 start_node_number) 93 start_node_number)
94 elif action.type() == 'push_token': 94 elif action.type() == 'push_token':
95 content = 'PUSH_TOKEN(Token::%s);' % action.data() 95 content = 'PUSH_TOKEN(Token::%s);' % action.data()
96 code += '%s\nBACK();\ngoto code_%s;\n' % (content, 96 code += '%s\ngoto code_%s;\n' % (content,
97 start_node_number) 97 start_node_number)
98 else: 98 else:
99 raise Exception("unknown type %s" % action.type()) 99 raise Exception("unknown type %s" % action.type())
100 else: 100 else:
101 code += 'goto default_action;' 101 code += 'goto default_action;'
102 return code 102 return code
103 103
104 @staticmethod 104 @staticmethod
105 def rule_processor_to_code(rule_processor, use_mdfa): 105 def rule_processor_to_code(rule_processor, use_mdfa):
106 if use_mdfa: 106 if use_mdfa:
107 dfa = rule_processor.default_automata().minimal_dfa() 107 dfa = rule_processor.default_automata().minimal_dfa()
(...skipping 13 matching lines...) Expand all
121 code += CodeGenerator.dfa_state_to_code(state, start_node_number) 121 code += CodeGenerator.dfa_state_to_code(state, start_node_number)
122 return code 122 return code
123 code = dfa.visit_all_states(f, code) 123 code = dfa.visit_all_states(f, code)
124 124
125 default_action_code = '' 125 default_action_code = ''
126 if rule_processor.default_action: 126 if rule_processor.default_action:
127 if rule_processor.default_action.type() == 'push_token': 127 if rule_processor.default_action.type() == 'push_token':
128 default_action_code = ''' 128 default_action_code = '''
129 default_action: 129 default_action:
130 //fprintf(stderr, "default action\\n"); 130 //fprintf(stderr, "default action\\n");
131 PUSH_TOKEN(Token::%s) 131 PUSH_TOKEN(Token::%s);
132 FORWARD();
132 goto code_%s;''' % (rule_processor.default_action.data(), start_node_number) 133 goto code_%s;''' % (rule_processor.default_action.data(), start_node_number)
133 else: 134 else:
134 raise Exception("Default action type %s not supported" % action.type()) 135 raise Exception("Default action type %s not supported" % action.type())
135 136
136 code += ''' 137 code += '''
137 CHECK(false); 138 CHECK(false);
138 %s 139 %s
139 return 0; 140 return 0;
140 } 141 }
141 142
142 } 143 }
143 } 144 }
144 ''' % default_action_code 145 ''' % default_action_code
145 return code 146 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