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

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

Issue 59403010: Experimental parser: easier to read rules and default rule (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 | « tools/lexer_generator/generator.py ('k') | tools/lexer_generator/rule_lexer.py » ('j') | 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 dfa_nodes = {} 350 dfa_nodes = {}
351 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) 351 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end)
352 return (start_name, dfa_nodes) 352 return (start_name, dfa_nodes)
353 353
354 def to_dot(self): 354 def to_dot(self):
355 355
356 def f(node, node_content): 356 def f(node, node_content):
357 for key, values in node.transitions().items(): 357 for key, values in node.transitions().items():
358 if key == TransitionKey.epsilon(): 358 if key == TransitionKey.epsilon():
359 key = "ε" 359 key = "ε"
360 key = str(key).replace('\\', '\\\\')
360 for value in values: 361 for value in values:
361 if value[1]: 362 if value[1]:
362 node_content.append( 363 node_content.append(
363 " S_%d -> S_%d [ label = \"%s {%s} -> %s\" ];" % 364 " S_%d -> S_%d [ label = \"%s {%s} -> %s\" ];" %
364 (node.node_number(), value[0].node_number(), key, value[1][0], 365 (node.node_number(), value[0].node_number(), key, value[1][0],
365 value[1][1])) 366 value[1][1]))
366 else: 367 else:
367 node_content.append( 368 node_content.append(
368 " S_%d -> S_%d [ label = \"%s\" ];" % 369 " S_%d -> S_%d [ label = \"%s\" ];" %
369 (node.node_number(), value[0].node_number(), key)) 370 (node.node_number(), value[0].node_number(), key))
370 return node_content 371 return node_content
371 372
372 node_content = self.__visit_all_edges(f, []) 373 node_content = self.__visit_all_edges(f, [])
373 374
374 return ''' 375 return '''
375 digraph finite_state_machine { 376 digraph finite_state_machine {
376 rankdir=LR; 377 rankdir=LR;
377 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s 378 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s
378 node [shape = doublecircle, style=unfilled]; S_%s 379 node [shape = doublecircle, style=unfilled]; S_%s
379 node [shape = circle]; 380 node [shape = circle];
380 %s 381 %s
381 } 382 }
382 ''' % (self.__start.node_number(), 383 ''' % (self.__start.node_number(),
383 self.__end.node_number(), 384 self.__end.node_number(),
384 "\n".join(node_content)) 385 "\n".join(node_content))
OLDNEW
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | tools/lexer_generator/rule_lexer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698