Beispiel #1
0
 def run_poodle_lex(self, language):
     output_dir = tempfile.mkdtemp()
     rules_file_path = os.path.join(base_directory, "Example", "CLexer", "CLexer.rules")
     rules_file = RulesFile.Parser.parse(rules_file_path, "utf-8")
     rules_file.accept(RulesFile.Traverser(RulesFile.Validator()))
     nfa_ir = RulesFile.NonDeterministicIR(rules_file)
     dfa_ir = RulesFile.DeterministicIR(nfa_ir)
     plugin_file_path = os.path.join(base_directory, "Plugins/Plugins.json")
     language_plugins, default_language = LanguagePlugins.load(plugin_file_path, 'utf-8')
     language_plugins[language].load()
     language_plugin = language_plugins[language]
     representation = dfa_ir
     if language_plugin.default_form == LanguagePlugins.PluginOptions.NFA_IR:
         representation = nfa_ir
     plugin_options = LanguagePlugins.PluginOptions()
     emitter = language_plugin.create(representation, plugin_options)
     executor = LanguagePlugins.Executor(emitter, language_plugin.plugin_files_directory, output_dir)
     executor.execute()
     return output_dir
Beispiel #2
0
minimizers = {
    'hopcroft': ('Minimize using Hopcroft\'s partition refinement algorithm', hopcroft),
    'polynomial': ('Minimize using a polynomial algorithm comparing each state', polynomial),
    'none': ('Do not minimize', lambda: None)
}

# Handle 'list' commands
command, arguments = CommandArguments.handle()
if command == 'list-minimizers':
    left_column_size = len(max(minimizers, key=lambda i: len(i))) + 1
    print("Supported DFA minimization algorithms:", file=sys.stderr)
    for name, (description, minimizer) in minimizers.iteritems():
        print("    %s%s%s\n" % (name, ' '*(left_column_size-len(name)), description), file=sys.stderr)
    sys.exit(0)
elif command == 'list-languages':
    LanguagePlugins.describe(this_folder, "Plugins/Plugins.json", 'utf-8')
    sys.exit(0)
elif command == 'list-forms':
    print("Supported State Machine Forms (language support may vary)")
    print("    nfa     Non-deterministic finite automata")
    print("    dfa     Minimized deterministic finit automata")
    print("    default Use the default specified for the language")
    
# Check minimizer
if arguments.minimizer not in minimizers:
    print("Minimizer '%s' not recognized\n" % arguments.minimizer, file=sys.stderr)
    sys.exit(1)
minimizer_description, minimizer = minimizers[arguments.minimizer]

# Load language plug-ins file and list languages if requested
language_plugins = None