Package org.antlr.v4.runtime.atn

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


        @Override
        public void run() {
          if (CLEAR_DFA) {
            int index = FILE_GRANULARITY ? 0 : ((NumberedThread)Thread.currentThread()).getThreadNumber();
            if (sharedLexers.length > 0 && sharedLexers[index] != null) {
              ATN atn = sharedLexers[index].getATN();
              for (int j = 0; j < sharedLexers[index].getInterpreter().decisionToDFA.length; j++) {
                sharedLexers[index].getInterpreter().decisionToDFA[j] = new DFA(atn.getDecisionState(j), j);
              }
            }

            if (sharedParsers.length > 0 && sharedParsers[index] != null) {
              ATN atn = sharedParsers[index].getATN();
              for (int j = 0; j < sharedParsers[index].getInterpreter().decisionToDFA.length; j++) {
                sharedParsers[index].getInterpreter().decisionToDFA[j] = new DFA(atn.getDecisionState(j), j);
              }
            }

            if (FILE_GRANULARITY) {
              Arrays.fill(sharedLexers, null);
View Full Code Here


            lexer.removeErrorListeners();
            lexer.addErrorListener(DescriptiveErrorListener.INSTANCE);

            if (lexer.getInterpreter().decisionToDFA[0] == null) {
              ATN atn = lexer.getATN();
              for (int i = 0; i < lexer.getInterpreter().decisionToDFA.length; i++) {
                lexer.getInterpreter().decisionToDFA[i] = new DFA(atn.getDecisionState(i), i);
              }
            }

                        CommonTokenStream tokens = new CommonTokenStream(lexer);
                        tokens.fill();
                        tokenCount.addAndGet(currentPass, tokens.size());

            if (COMPUTE_CHECKSUM) {
              for (Token token : tokens.getTokens()) {
                updateChecksum(checksum, token);
              }
            }

                        if (!RUN_PARSER) {
                            return new FileParseResult(input.getSourceName(), (int)checksum.getValue(), null, tokens.size(), startTime, lexer, null);
                        }

            final long parseStartTime = System.nanoTime();
            Parser parser = sharedParsers[thread];
                        if (REUSE_PARSER && parser != null) {
                            parser.setInputStream(tokens);
                        } else {
              Parser previousParser = parser;

              if (USE_PARSER_INTERPRETER) {
                Parser referenceParser = parserCtor.newInstance(tokens);
                parser = new ParserInterpreter(referenceParser.getGrammarFileName(), referenceParser.getVocabulary(), Arrays.asList(referenceParser.getRuleNames()), referenceParser.getATN(), tokens);
              }
              else {
                parser = parserCtor.newInstance(tokens);
              }

              DFA[] decisionToDFA = (FILE_GRANULARITY || previousParser == null ? parser : previousParser).getInterpreter().decisionToDFA;
              if (!REUSE_PARSER_DFA || (!FILE_GRANULARITY && previousParser == null)) {
                decisionToDFA = new DFA[decisionToDFA.length];
              }

              if (COMPUTE_TRANSITION_STATS) {
                parser.setInterpreter(new StatisticsParserATNSimulator(parser, parser.getATN(), decisionToDFA, parser.getInterpreter().getSharedContextCache()));
              } else if (!REUSE_PARSER_DFA) {
                parser.setInterpreter(new ParserATNSimulator(parser, parser.getATN(), decisionToDFA, parser.getInterpreter().getSharedContextCache()));
              }

              sharedParsers[thread] = parser;
                        }

            parser.removeParseListeners();
            parser.removeErrorListeners();
            if (!TWO_STAGE_PARSING) {
              parser.addErrorListener(DescriptiveErrorListener.INSTANCE);
              parser.addErrorListener(new SummarizingDiagnosticErrorListener());
            }

            if (parser.getInterpreter().decisionToDFA[0] == null) {
              ATN atn = parser.getATN();
              for (int i = 0; i < parser.getInterpreter().decisionToDFA.length; i++) {
                parser.getInterpreter().decisionToDFA[i] = new DFA(atn.getDecisionState(i), i);
              }
            }

            parser.getInterpreter().setPredictionMode(TWO_STAGE_PARSING ? PredictionMode.SLL : PREDICTION_MODE);
            parser.setBuildParseTree(BUILD_PARSE_TREES);
View Full Code Here

      "C : 'c';\n");
    checkDeserializationIsStable(lg);
  }

  protected void checkDeserializationIsStable(Grammar g) {
    ATN atn = createATN(g, false);
    char[] data = Utils.toCharArray(ATNSerializer.getSerialized(atn));
    String atnData = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    ATN atn2 = new ATNDeserializer().deserialize(data);
    String atn2Data = ATNSerializer.getDecoded(atn2, Arrays.asList(g.getTokenNames()));

    assertEquals(atnData, atn2Data);
  }
View Full Code Here

   */
  public void checkPredictedAlt(LexerGrammar lg, Grammar g, int decision,
                  String inputString, int expectedAlt)
  {
    Tool.internalOption_ShowATNConfigsInDFA = true;
    ATN lexatn = createATN(lg, true);
    LexerATNSimulator lexInterp =
      new LexerATNSimulator(lexatn,new DFA[] { new DFA(lexatn.modeToStartState.get(Lexer.DEFAULT_MODE)) },new PredictionContextCache());
    IntegerList types = getTokenTypesViaATN(inputString, lexInterp);
    System.out.println(types);

    semanticProcess(lg);
    g.importVocab(lg);
    semanticProcess(g);

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

    DOTGenerator dot = new DOTGenerator(g);

    Rule r = g.getRule("a");
    if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
View Full Code Here

  public void checkDFAConstruction(LexerGrammar lg, Grammar g, int decision,
                   String[] inputString, String[] dfaString)
  {
//    Tool.internalOption_ShowATNConfigsInDFA = true;
    ATN lexatn = createATN(lg, true);
    LexerATNSimulator lexInterp =
      new LexerATNSimulator(lexatn,new DFA[] { new DFA(lexatn.getDecisionState(Lexer.DEFAULT_MODE)) }, new PredictionContextCache());

    semanticProcess(lg);
    g.importVocab(lg);
    semanticProcess(g);
View Full Code Here

        "rule 0:0\n" +
        "0->2 EPSILON 0,0,0\n" +
        "2->3 ATOM 1,0,0\n" +
        "3->4 ATOM 2,0,0\n" +
        "4->1 EPSILON 0,0,0\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

        "rule 0:0\n" +
        "0->2 EPSILON 0,0,0\n" +
        "2->3 ATOM 1,0,0\n" +
        "3->4 ATOM 0,0,1\n" +
        "4->1 EPSILON 0,0,0\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

        "rule 0:0\n" +
        "0:EOF, A..A\n" +
        "0->2 EPSILON 0,0,0\n" +
        "2->3 SET 0,0,0\n" +
        "3->1 EPSILON 0,0,0\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

      "rule 0:0\n" +
      "0:A..A\n" +
      "0->2 EPSILON 0,0,0\n" +
      "2->3 NOT_SET 0,0,0\n" +
      "3->1 EPSILON 0,0,0\n";
    ATN atn = createATN(g, true);
    DOTGenerator gen = new DOTGenerator(g);
    System.out.println(gen.getDOT(atn.ruleToStartState[0]));
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

      "4:BASIC 0\n" +
      "rule 0:0\n" +
      "0->2 EPSILON 0,0,0\n" +
      "2->3 WILDCARD 0,0,0\n" +
      "3->1 EPSILON 0,0,0\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
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.