Ejemplo n.º 1
0
  public LL1PlusBlock(OutputModelFactory factory, GrammarAST plusRoot, List<CodeBlockForAlt> alts) {
    super(factory, plusRoot, alts);

    PlusBlockStartState blkStart = (PlusBlockStartState) plusRoot.atnState;

    stateNumber = blkStart.loopBackState.stateNumber;
    blockStartStateNumber = blkStart.stateNumber;

    this.decision = blkStart.decision;
    Grammar g = factory.getGrammar();
    CodeGenerator gen = factory.getGenerator();
    /** Lookahead for each alt 1..n */
    IntervalSet[] altLookSets = g.decisionLOOK.get(decision);
    altLook = getAltLookaheadAsStringLists(altLookSets);
    IntervalSet all = new IntervalSet();
    for (IntervalSet s : altLookSets) all.addAll(s);

    this.error = getThrowNoViableAlt(factory, plusRoot, all);

    loopExpr = addCodeForLoopLookaheadTempVar(all);

    loopLabel = gen.getTarget().getLoopLabel(plusRoot);
    loopCounterVar = gen.getTarget().getLoopCounter(plusRoot);

    IntervalSet exitLookSet = altLookSets[altLookSets.length - 1];
    this.exitLook = gen.getTarget().getTokenTypesAsTargetLabels(g, exitLookSet.toArray());
  }
Ejemplo n.º 2
0
 public StarBlock(
     OutputModelFactory factory, GrammarAST blkOrEbnfRootAST, List<CodeBlockForAlt> alts) {
   super(factory, blkOrEbnfRootAST, alts);
   loopLabel = factory.getGenerator().getTarget().getLoopLabel(blkOrEbnfRootAST);
   StarLoopEntryState star = (StarLoopEntryState) blkOrEbnfRootAST.atnState;
   loopBackStateNumber = star.loopBackState.stateNumber;
   decision = star.decision;
 }
Ejemplo n.º 3
0
  private static Bitset[] createBitsets(
      OutputModelFactory factory, IntervalSet set, boolean useZeroOffset) {
    List<Bitset> bitsetList = new ArrayList<Bitset>();
    for (int ttype : set.toArray()) {
      Bitset current = !bitsetList.isEmpty() ? bitsetList.get(bitsetList.size() - 1) : null;
      if (current == null || ttype > (current.shift + 63)) {
        current = new Bitset();
        if (useZeroOffset && ttype >= 0 && ttype < 63) {
          current.shift = 0;
        } else {
          current.shift = ttype;
        }

        bitsetList.add(current);
      }

      current.ttypes.add(
          factory.getGenerator().target.getTokenTypeAsTargetLabel(factory.getGrammar(), ttype));
    }

    return bitsetList.toArray(new Bitset[bitsetList.size()]);
  }
Ejemplo n.º 4
0
 public SerializedATN(OutputModelFactory factory, ATN atn) {
   super(factory);
   IntegerList data = ATNSerializer.getSerialized(atn);
   serialized = new ArrayList<String>(data.size());
   for (int c : data.toArray()) {
     String encoded =
         factory
             .getGenerator()
             .getTarget()
             .encodeIntAsCharEscape(c == -1 ? Character.MAX_VALUE : c);
     serialized.add(encoded);
   }
   //		System.out.println(ATNSerializer.getDecoded(factory.getGrammar(), atn));
 }