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

Unified Diff: tools/lexer_generator/code_generator.py

Issue 65643005: Experimental lexer generator: Add an option to add debug prints. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/code_generator.py
diff --git a/tools/lexer_generator/code_generator.py b/tools/lexer_generator/code_generator.py
index 7c14c99e710c5df9f9cfd1154d02ceb19a27cbe3..aa21b3b986417e22e03d7a922f6b68618ef577c3 100644
--- a/tools/lexer_generator/code_generator.py
+++ b/tools/lexer_generator/code_generator.py
@@ -28,6 +28,7 @@
from dfa import Dfa
class CodeGenerator:
+ debug = False
@staticmethod
def key_to_code(key):
@@ -109,11 +110,15 @@ class CodeGenerator:
code += '''
code_start:
'''
+
code += '''
code_%s:
- //fprintf(stderr, "state %s\\n");
-''' % (state.node_number(),
- state.node_number())
+''' % state.node_number()
+
+ if CodeGenerator.debug:
+ code += '''
+ fprintf(stderr, "state %s\\n");
+''' % state.node_number()
entry_action = state.action().entry_action() if state.action() else None
match_action = state.action().match_action() if state.action() else None
@@ -121,8 +126,10 @@ code_%s:
if entry_action:
code += self.__action_code_map[entry_action[0]](entry_action[1])
- code += '''
- //fprintf(stderr, "char at hand is %c (%d)\\n", yych, yych);\n'''
+ if CodeGenerator.debug:
+ code += '''
+ fprintf(stderr, "char at hand is %c (%d)\\n", yych, yych);
+'''
for key, s in state.transitions().items():
code += CodeGenerator.key_to_code(key)
@@ -162,8 +169,12 @@ uint32_t EvenMoreExperimentalScanner::DoLex() {
default_action_code = self.__action_code_map[action[0]](action[1])
code += '''
CHECK(false); goto code_start;
-default_action:
- //fprintf(stderr, "default action\\n");
+default_action:'''
+ if CodeGenerator.debug:
+ code += '''
+fprintf(stderr, "default action\\n");
+'''
+ code += '''
%s
FORWARD();
goto code_%s;
« 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