예제 #1
0
  @Override
  public void outAConcat(AConcat node) {
    AUnExp[] unExps = (AUnExp[]) node.getUnExps().toArray(new AUnExp[0]);

    if (unExps.length == 0) {
      setOut(node, new NFA());
    } else if (unExps.length == 1) {
      setOut(node, getOut(unExps[0]));

      // free memory
      if (getOut(unExps[0]) != null) setOut(unExps[0], null);
    } else {
      NFA result = null;

      for (int i = unExps.length - 1; i >= 0; i--) {
        Object o = getOut(unExps[i]);
        NFA nfa = (o instanceof NFA) ? (NFA) o : new NFA((CharSet) o);

        if (result == null) {
          result = nfa;
        } else {
          result = nfa.concatenate(result);
        }

        // free memory
        if (getOut(unExps[i]) != null) setOut(unExps[i], null);
      }

      setOut(node, result);
    }
  }
예제 #2
0
  @Override
  public void outARegExp(ARegExp node) {
    AConcat[] concats = (AConcat[]) node.getConcats().toArray(new AConcat[0]);
    NFA result = null;

    if (concats.length > 1) {
      for (int i = concats.length - 1; i >= 0; i--) {
        Object o = getOut(concats[i]);
        NFA nfa = (o instanceof NFA) ? (NFA) o : new NFA((CharSet) o);

        if (result == null) {
          result = nfa;
        } else {
          result = nfa.alternate(result);
        }

        // free memory
        if (getOut(concats[i]) != null) setOut(concats[i], null);
      }
      setOut(node, result);
    } else if (concats.length == 1) {
      setOut(node, getOut(concats[0]));

      // free memory
      if (getOut(concats[0]) != null) setOut(concats[0], null);
    }
  }
예제 #3
0
  @Override
  public void outATokens(ATokens node) {
    ATokenDef[] tokenDefs = (ATokenDef[]) node.getTokenDefs().toArray(new ATokenDef[0]);
    NFA result = null;

    for (int i = tokenDefs.length - 1; i >= 0; i--) {
      NFA nfa = (NFA) getOut(tokenDefs[i]);
      if (nfa != null) {
        if (result == null) {
          result = nfa;
        } else {
          result = nfa.merge(result);
        }

        // free memory
        if (getOut(tokenDefs[i]) != null) setOut(tokenDefs[i], null);
      }
    }

    if (result != null) setOut(node, result);
  }
예제 #4
0
  @Override
  public void outAUnExp(AUnExp node) {
    Object o = getOut(node.getBasic());

    char c = ' ';
    if (node.getUnOp() != null) c = ((Character) getOut(node.getUnOp())).charValue();

    switch (c) {
      case '*':
        {
          NFA n = (o instanceof NFA) ? (NFA) o : new NFA((CharSet) o);
          setOut(node, n.zeroOrMore());
        }
        break;
      case '?':
        {
          NFA n = (o instanceof NFA) ? (NFA) o : new NFA((CharSet) o);
          setOut(node, n.zeroOrOne());
        }
        break;
      case '+':
        {
          NFA n = (o instanceof NFA) ? (NFA) o : new NFA((CharSet) o);
          setOut(node, n.oneOrMore());
        }
        break;
      default:
        {
          setOut(node, o);
        }
        break;
    }

    // free memory
    if (getOut(node.getBasic()) != null) setOut(node.getBasic(), null);
    if (getOut(node.getUnOp()) != null) setOut(node.getUnOp(), null);
  }