Package org.antlr.v4.runtime.misc

Examples of org.antlr.v4.runtime.misc.IntervalSet


        "[@29,41:43=''+'',<62>,4:6]\n" +
        "[@31,45:45='e',<57>,4:10]\n" +
        "[@37,53:55=''.'',<62>,5:6]\n" +
        "[@39,57:58='ID',<66>,5:10]";

    IntervalSet types =
        new IntervalSet(ANTLRParser.TOKEN_REF,
        ANTLRParser.STRING_LITERAL,
        ANTLRParser.RULE_REF);
    List<GrammarAST> nodes = g.ast.getNodesWithTypePreorderDFS(types);
    List<Token> tokens = new ArrayList<Token>();
    for (GrammarAST node : nodes) {
View Full Code Here


        "[@31,43:45=''+'',<62>,4:6]\n" +
        "[@33,47:47='e',<57>,4:10]\n" +
        "[@39,55:57=''.'',<62>,5:6]\n" +
        "[@43,61:62='ID',<66>,5:12]";

    IntervalSet types =
        new IntervalSet(ANTLRParser.TOKEN_REF,
        ANTLRParser.STRING_LITERAL,
        ANTLRParser.RULE_REF);
    List<GrammarAST> nodes = g.ast.getNodesWithTypePreorderDFS(types);
    List<Token> tokens = new ArrayList<Token>();
    for (GrammarAST node : nodes) {
View Full Code Here

        "[@35,50:52=''+'',<62>,4:6]\n" +
        "[@37,54:54='e',<57>,4:10]\n" +
        "[@43,62:64=''.'',<62>,5:6]\n" +
        "[@45,66:67='ID',<66>,5:10]";

    IntervalSet types =
        new IntervalSet(ANTLRParser.TOKEN_REF,
        ANTLRParser.STRING_LITERAL,
        ANTLRParser.RULE_REF);
    List<GrammarAST> nodes = g.ast.getNodesWithTypePreorderDFS(types);
    List<Token> tokens = new ArrayList<Token>();
    for (GrammarAST node : nodes) {
View Full Code Here

      if (rule.isFragment()) {
        continue;
      }

      LL1Analyzer analyzer = new LL1Analyzer(g.atn);
      IntervalSet look = analyzer.LOOK(g.atn.ruleToStartState[rule.index], null);
      if (look.contains(Token.EPSILON)) {
        g.tool.errMgr.grammarError(ErrorType.EPSILON_TOKEN, g.fileName, ((GrammarAST)rule.ast.getChild(0)).getToken(), rule.name);
      }
    }
  }
View Full Code Here

  }

  /** Return whether lookahead sets are disjoint; no lookahead => not disjoint */
  public static boolean disjoint(IntervalSet[] altLook) {
    boolean collision = false;
    IntervalSet combined = new IntervalSet();
    if ( altLook==null ) return false;
    for (IntervalSet look : altLook) {
      if ( look==null ) return false; // lookahead must've computation failed
      if ( !look.and(combined).isNil() ) {
        collision = true;
        break;
      }
      combined.addAll(look);
    }
    return !collision;
  }
View Full Code Here

          // parser codegen doesn't currently support SetTransition
          continue;
        }
      }

      IntervalSet setTransitions = new IntervalSet();
      for (int i = 0; i < decision.getNumberOfTransitions(); i++) {
        Transition epsTransition = decision.transition(i);
        if (!(epsTransition instanceof EpsilonTransition)) {
          continue;
        }

        if (epsTransition.target.getNumberOfTransitions() != 1) {
          continue;
        }

        Transition transition = epsTransition.target.transition(0);
        if (!(transition.target instanceof BlockEndState)) {
          continue;
        }

        if (transition instanceof NotSetTransition) {
          // TODO: not yet implemented
          continue;
        }

        if (transition instanceof AtomTransition
          || transition instanceof RangeTransition
          || transition instanceof SetTransition)
        {
          setTransitions.add(i);
        }
      }

      // due to min alt resolution policies, can only collapse sequential alts
      for (int i = setTransitions.getIntervals().size() - 1; i >= 0; i--) {
        Interval interval = setTransitions.getIntervals().get(i);
        if (interval.length() <= 1) {
          continue;
        }

        ATNState blockEndState = decision.transition(interval.a).target.transition(0).target;
        IntervalSet matchSet = new IntervalSet();
        for (int j = interval.a; j <= interval.b; j++) {
          Transition matchTransition = decision.transition(j).target.transition(0);
          if (matchTransition instanceof NotSetTransition) {
            throw new UnsupportedOperationException("Not yet implemented.");
          } else {
            matchSet.addAll(matchTransition.label());
          }
        }

        Transition newTransition;
        if (matchSet.getIntervals().size() == 1) {
          if (matchSet.size() == 1) {
            newTransition = new AtomTransition(blockEndState, matchSet.getMinElement());
          } else {
            Interval matchInterval = matchSet.getIntervals().get(0);
            newTransition = new RangeTransition(blockEndState, matchInterval.a, matchInterval.b);
          }
        } else {
          newTransition = new SetTransition(blockEndState, matchSet);
        }
View Full Code Here

   *  restricted to tokens reachable staying within {@code s}'s rule.
   */
  @NotNull
  public IntervalSet nextTokens(ATNState s, RuleContext ctx) {
    LL1Analyzer anal = new LL1Analyzer(this);
    IntervalSet next = anal.LOOK(s, ctx);
    return next;
  }
View Full Code Here

      throw new IllegalArgumentException("Invalid state number.");
    }

    RuleContext ctx = context;
    ATNState s = states.get(stateNumber);
    IntervalSet following = nextTokens(s);
    if (!following.contains(Token.EPSILON)) {
      return following;
    }

    IntervalSet expected = new IntervalSet();
    expected.addAll(following);
    expected.remove(Token.EPSILON);
    while (ctx != null && ctx.invokingState >= 0 && following.contains(Token.EPSILON)) {
      ATNState invokingState = states.get(ctx.invokingState);
      RuleTransition rt = (RuleTransition)invokingState.transition(0);
      following = nextTokens(rt.followState);
      expected.addAll(following);
      expected.remove(Token.EPSILON);
      ctx = ctx.parent;
    }

    if (following.contains(Token.EPSILON)) {
      expected.add(Token.EOF);
    }

    return expected;
  }
View Full Code Here

      return null;
    }

    IntervalSet[] look = new IntervalSet[s.getNumberOfTransitions()];
    for (int alt = 0; alt < s.getNumberOfTransitions(); alt++) {
      look[alt] = new IntervalSet();
      Set<ATNConfig> lookBusy = new HashSet<ATNConfig>();
      boolean seeThruPreds = false; // fail to get lookahead upon pred
      _LOOK(s.transition(alt).target, null, PredictionContext.EMPTY,
          look[alt], lookBusy, new BitSet(), seeThruPreds, false);
      // Wipe out lookahead for this alternative if we found nothing
View Full Code Here

   * @return The set of tokens that can follow {@code s} in the ATN in the
   * specified {@code ctx}.
   */
    @NotNull
     public IntervalSet LOOK(@NotNull ATNState s, @Nullable ATNState stopState, @Nullable RuleContext ctx) {
       IntervalSet r = new IntervalSet();
    boolean seeThruPreds = true; // ignore preds; get all lookahead
    PredictionContext lookContext = ctx != null ? PredictionContext.fromRuleContext(s.atn, ctx) : null;
       _LOOK(s, stopState, lookContext,
        r, new HashSet<ATNConfig>(), new BitSet(), seeThruPreds, true);
       return r;
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.misc.IntervalSet

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.