Package org.antlr.v4.runtime.atn

Examples of org.antlr.v4.runtime.atn.ATN


  List<ANTLRMessage> checkRuleDFA(String gtext, int decision, String expecting)
    throws Exception
  {
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(gtext, equeue);
    ATN atn = createATN(g, false);
    DecisionState blk = atn.decisionToState.get(decision);
    checkRuleDFA(g, blk, expecting);
    return equeue.all;
  }
View Full Code Here


    this.g = g;

    ATNType atnType = g instanceof LexerGrammar ? ATNType.LEXER : ATNType.PARSER;
    int maxTokenType = g.getMaxTokenType();
    this.atn = new ATN(atnType, maxTokenType);
  }
View Full Code Here

    if (this.isCombined()) {
      return implicitLexer.createLexerInterpreter(input);
    }

    char[] serializedAtn = ATNSerializer.getSerializedAsChars(atn);
    ATN deserialized = new ATNDeserializer().deserialize(serializedAtn);
    return new LexerInterpreter(fileName, getVocabulary(), Arrays.asList(getRuleNames()), ((LexerGrammar)this).modes.keySet(), deserialized, input);
  }
View Full Code Here

    if (this.isLexer()) {
      throw new IllegalStateException("A parser interpreter can only be created for a parser or combined grammar.");
    }

    char[] serializedAtn = ATNSerializer.getSerializedAsChars(atn);
    ATN deserialized = new ATNDeserializer().deserialize(serializedAtn);
    return new ParserInterpreter(fileName, getVocabulary(), Arrays.asList(getRuleNames()), deserialized, tokenStream);
  }
View Full Code Here

    if ( g.modes.get(modeName)==null ) {
      System.err.println("no such mode "+modeName);
      return;
    }
    ParserATNFactory f = new LexerATNFactory(g);
    ATN nfa = f.createATN();
    ATNState startState = nfa.modeNameToStartState.get(modeName);
    ATNPrinter serializer = new ATNPrinter(g, startState);
    String result = serializer.asString();
    //System.out.print(result);
    assertEquals(expecting, result);
View Full Code Here

  public void checkMatchedAlt(LexerGrammar lg, final Grammar g,
                String inputString,
                int expected)
  {
    ATN lexatn = createATN(lg, true);
    LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn,new DFA[] { new DFA(lexatn.modeToStartState.get(Lexer.DEFAULT_MODE)) },null);
    IntegerList types = getTokenTypesViaATN(inputString, lexInterp);
    System.out.println(types);

    g.importVocab(lg);

    ParserATNFactory f = new ParserATNFactory(g);
    ATN atn = f.createATN();

    IntTokenStream input = new IntTokenStream(types);
    System.out.println("input="+input.types);
    ParserInterpreterForTesting interp = new ParserInterpreterForTesting(g, input);
    ATNState startState = atn.ruleToStartState[g.getRule("a").index];
View Full Code Here

    for (GrammarAST t : terminals) {
      int ttype = g.getTokenType(t.getText());
      set.add(ttype);
    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
      left.addTransition(new SetTransition(right, set));
    }
    associatedAST.atnState = left;
View Full Code Here

        BlockStartState star = newState(StarBlockStartState.class, ebnfRoot);
        if ( alts.size()>1 ) atn.defineDecisionState(star);
        h = makeBlock(star, blkAST, alts);
        return star(ebnfRoot, h);
      case ANTLRParser.POSITIVE_CLOSURE :
        PlusBlockStartState plus = newState(PlusBlockStartState.class, ebnfRoot);
        if ( alts.size()>1 ) atn.defineDecisionState(plus);
        h = makeBlock(plus, blkAST, alts);
        return plus(ebnfRoot, h);
    }
    return null;
View Full Code Here

   * start.
   */
  @NotNull
  @Override
  public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) {
    PlusBlockStartState blkStart = (PlusBlockStartState)blk.left;
    BlockEndState blkEnd = (BlockEndState)blk.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    PlusLoopbackState loop = newState(PlusLoopbackState.class, plusAST);
    loop.nonGreedy = !((QuantifierAST)plusAST).isGreedy();
View Full Code Here

  public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) {
    PlusBlockStartState blkStart = (PlusBlockStartState)blk.left;
    BlockEndState blkEnd = (BlockEndState)blk.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    PlusLoopbackState loop = newState(PlusLoopbackState.class, plusAST);
    loop.nonGreedy = !((QuantifierAST)plusAST).isGreedy();
    atn.defineDecisionState(loop);
    LoopEndState end = newState(LoopEndState.class, plusAST);
    blkStart.loopBackState = loop;
    end.loopBackState = loop;
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.atn.ATN

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.