Package wyautl.core

Examples of wyautl.core.Automaton


    return type;
  }

  protected Type expandAsType(Type type, HashMap<String, Type> macros) {
    Automaton automaton = type.automaton();
    HashMap<String, Integer> roots = new HashMap<String, Integer>();
    HashMap<Integer,Integer> visited = new HashMap<Integer,Integer>();

    ArrayList<Automaton.State> states = new ArrayList<Automaton.State>();
    for(int i=0;i!=automaton.nStates();++i) {
      states.add(automaton.get(i).clone());
    }
    int root = expand(automaton.getRoot(0), states, visited,
        roots, macros);
    automaton = new Automaton(states.toArray(new Automaton.State[states.size()]));
    automaton.setRoot(0, root);
    return Type.construct(automaton);
  }
View Full Code Here


            } else {
              // In this, we have a term which is specified to
              // have an argument, but for which no argument is
              // given. In which case, we simply expand the term
              // to include its default argument type.
              Automaton macro_automaton = macro.automaton();
              int root = Automata.extract(macro_automaton, macro_automaton.getRoot(0), states);
              // We store the location of the expanded macro into the
              // roots cache so that it can be reused if/when we
              // encounter the same macro again.
              roots.put(name, root);
              visited.put(node, root);
              return expand(root, states, visited, roots, macros);
            }
          } else if (macro != null && !(macro instanceof Type.Term)) {
            // In this case, we have identified a nominal type which
            // should be inlined into this automaton and then
            // recursively expanded as necessary.
            Automaton macro_automaton = macro.automaton();
            int element =  Automata.extract(macro_automaton, macro_automaton.getRoot(0), states);
            int base = states.size();
            states.add(new Automaton.Strung(name));
            states.add(new Automaton.List(base, element));
            states.add(new Automaton.Term(K_Nominal,
                base+1));
View Full Code Here

  private void readTypePool(int size) throws IOException {
    final SemanticType[] myTypePool = new SemanticType[size];
    BinaryAutomataReader reader = new BinaryAutomataReader(input,
        Types.SCHEMA);
    Automaton global = reader.read();

    for (int i = 0; i != size; ++i) {
      Automaton automaton = new Automaton();
      int root = automaton.addAll(global.getRoot(i), global);
      automaton.setRoot(0, root);
      SemanticType t = SemanticType.construct(automaton);
      myTypePool[i] = t;
    }

    typePool = myTypePool;
View Full Code Here

    myOut();
  }

  private void writeSchema(Type.Term tt) {
    Automaton automaton = tt.automaton();
    BitSet visited = new BitSet(automaton.nStates());
    writeSchema(automaton.getRoot(0), automaton, visited);
  }
View Full Code Here

  }

  private void writeTypePool(BinaryOutputStream output) throws IOException {
    // First, we accumulate the automata for all types in the pool into one
    // automaton. This helps reduce the amount of redundancy between types.
    Automaton global = new Automaton();
    for (int i = 0; i != typePool.size(); ++i) {
      Automaton automaton = typePool.get(i).automaton();
      int root = global.addAll(automaton.getRoot(0), automaton);
      global.setRoot(i, root);
    }

    global.minimise();
    global.compact();
View Full Code Here

        // this is basically a hack to allow reading in wyone files so
        // we can debug them.
        try {
          FileInputStream fin = new FileInputStream(args.get(0));
          PrettyAutomataReader reader = new PrettyAutomataReader(fin,SCHEMA);
          Automaton automaton = reader.read();

          new PrettyAutomataWriter(System.err, SCHEMA, "And",
              "Or").write(automaton);
          IterativeRewriter.Strategy<InferenceRule> inferenceStrategy = new UnfairStateRuleRewriteStrategy<InferenceRule>(
              automaton, Solver.inferences, Solver.SCHEMA);
View Full Code Here

    }

  private static void reduce(String text, RewriteMode rwMode) {
    try {
      Parser parser = new Parser(text);
      Automaton automaton = new Automaton();
      int root = parser.parse(automaton);
      automaton.setRoot(0, root);

      PrettyAutomataWriter writer = new PrettyAutomataWriter(System.out,
          Arithmetic.SCHEMA, "Or", "And");
      System.out.println("------------------------------------");
      writer.write(automaton);
View Full Code Here

    }

    private static void reduce(String text, RewriteMode rwMode) {
  try {
      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);
View Full Code Here

   * @param type
   * @return the minimal size, or Integer.MAX_VALUE (to signal infinity ---
   *         which *should* be impossible).
   */
  public static int minimumSize(Type type) {
    Automaton automaton = type.automaton();
    automaton.compact();
    automaton.minimise();
    BitSet onStack = new BitSet();
    int size = minimumSize(automaton.getRoot(0), onStack, automaton);
    if(size < 0) {
      throw new RuntimeException("PROBLEM --- " + type);
    }
    return size;
  }
View Full Code Here

    }

    private static void reduce(String text, RewriteMode rwMode) {
  try {
      Parser parser = new Parser(text);
      Automaton automaton = new Automaton();
      int root = parser.parse(automaton);
      automaton.setRoot(0, root);

      PrettyAutomataWriter writer = new PrettyAutomataWriter(System.out,
                   Closure.SCHEMA, "Or", "And");
      System.out.println("------------------------------------");
      writer.write(automaton);
View Full Code Here

TOP

Related Classes of wyautl.core.Automaton

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.