Parser parser = new Parser(text);
Automaton automaton = new Automaton();
int root = parser.parse(automaton);
automaton.setRoot(0, root);
PrettyAutomataWriter writer = new PrettyAutomataWriter(System.out,
Quantifiers.SCHEMA, "Or", "And");
System.out.println("------------------------------------");
writer.write(automaton);
writer.flush();
StrategyRewriter.Strategy<InferenceRule> inferenceStrategy;
StrategyRewriter.Strategy<ReductionRule> reductionStrategy;
switch (rwMode) {
case SIMPLE:
inferenceStrategy = new SimpleRewriteStrategy<InferenceRule>(
automaton, Quantifiers.inferences);
reductionStrategy = new SimpleRewriteStrategy<ReductionRule>(
automaton, Quantifiers.reductions);
break;
case STATIC_DISPATCH:
inferenceStrategy = new UnfairStateRuleRewriteStrategy<InferenceRule>(
automaton, Quantifiers.inferences,Quantifiers.SCHEMA);
reductionStrategy = new UnfairStateRuleRewriteStrategy<ReductionRule>(
automaton, Quantifiers.reductions,Quantifiers.SCHEMA);
case GLOBAL_DISPATCH:
inferenceStrategy = new UnfairRuleStateRewriteStrategy<InferenceRule>(
automaton, Quantifiers.inferences);
reductionStrategy = new UnfairRuleStateRewriteStrategy<ReductionRule>(
automaton, Quantifiers.reductions);
break;
default:
// DEAD-CODE
inferenceStrategy = null;
reductionStrategy = null;
}
StrategyRewriter rw = new StrategyRewriter(automaton,
inferenceStrategy, reductionStrategy, Quantifiers.SCHEMA);
rw.apply(50,100000);
System.out.println("\n\n=> (" + rw.getStats() + ")\n");
writer.write(automaton);
writer.flush();
System.out.println("\n");
} catch(RuntimeException e) {
// Catching runtime exceptions is actually rather bad style;
// see lecture about Exceptions later in the course!
System.err.println("error: " + e.getMessage());