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
  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()]);
  }