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

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

Issue 70273008: Experimental lexer generator: default action fix. (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 | « no previous file | 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 for key, s in state.transitions().items(): 83 for key, s in state.transitions().items():
84 code += CodeGenerator.key_to_code(key) 84 code += CodeGenerator.key_to_code(key)
85 code += ''' { 85 code += ''' {
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 code += '%s\nBACK();\ngoto code_%s;\n' % (action.data(), 91 code += '%s\nBACK();\ngoto code_%s;\n' % (action.data(),
92 start_node_number) 92 start_node_number)
93 else: 93 else:
94 code += 'goto default_action;' 94 code += 'goto default_action;'
95 return code 95 return code
96 96
97 @staticmethod 97 @staticmethod
98 def rule_processor_to_code(rule_processor): 98 def rule_processor_to_code(rule_processor):
99 dfa = rule_processor.default_automata().dfa() 99 dfa = rule_processor.default_automata().dfa()
100 start_node_number = dfa.start_state().node_number() 100 start_node_number = dfa.start_state().node_number()
101 code = ''' 101 code = '''
102 #include "lexer/even-more-experimental-scanner.h" 102 #include "lexer/even-more-experimental-scanner.h"
103 103
104 namespace v8 { 104 namespace v8 {
105 namespace internal { 105 namespace internal {
106 uint32_t EvenMoreExperimentalScanner::DoLex() { 106 uint32_t EvenMoreExperimentalScanner::DoLex() {
107 YYCTYPE yych = *cursor_; 107 YYCTYPE yych = *cursor_;
108 goto code_%s; 108 goto code_%s;
109 ''' % start_node_number 109 ''' % start_node_number
110 def f(state, code): 110 def f(state, code):
111 code += CodeGenerator.dfa_state_to_code(state, start_node_number) 111 code += CodeGenerator.dfa_state_to_code(state, start_node_number)
112 return code 112 return code
113 code = dfa.visit_all_states(f, code) 113 code = dfa.visit_all_states(f, code)
114 code += ''' 114 code += '''
115 CHECK(false); 115 CHECK(false);
116 default_action: 116 default_action:
117 //fprintf(stderr, "default action\\n"); 117 //fprintf(stderr, "default action\\n");
118 %s 118 %s
119 BACK();
120 goto code_%s; 119 goto code_%s;
121 return 0; 120 return 0;
122 } 121 }
123 122
124 } 123 }
125 } 124 }
126 ''' % (rule_processor.default_action, start_node_number) 125 ''' % (rule_processor.default_action, start_node_number)
127 return code 126 return code
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698