Package org.antlr.analysis

Examples of org.antlr.analysis.DFA


        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : 'a' 'b' | 'a' 'c' | 'd' 'e' ;");
    g.buildNFA();
        g.createLookaheadDFAs(false);
        DFA dfa = g.getLookaheadDFA(1);
        checkPrediction(dfa,"ab",1);
        checkPrediction(dfa,"ac",2);
        checkPrediction(dfa,"de",3);
        checkPrediction(dfa,"q", NFA.INVALID_ALT_NUMBER);
    }
View Full Code Here


                "lexer grammar t;\n"+
                "A : (DIGIT)+ '.' DIGIT | (DIGIT)+ ;\n" +
                "fragment DIGIT : '0'..'9' ;\n");
    g.buildNFA();
        g.createLookaheadDFAs(false);
        DFA dfa = g.getLookaheadDFA(3);
        checkPrediction(dfa,"32",2);
        checkPrediction(dfa,"999.2",1);
        checkPrediction(dfa,".2", NFA.INVALID_ALT_NUMBER);
    }
View Full Code Here

  protected String getDFALocations(Set dfas) {
    Set decisions = new HashSet();
    StringBuffer buf = new StringBuffer();
    Iterator it = dfas.iterator();
    while ( it.hasNext() ) {
      DFA dfa = (DFA) it.next();
      // if we aborted a DFA and redid with k=1, the backtrackin
      if ( decisions.contains(Utils.integer(dfa.decisionNumber)) ) {
        continue;
      }
      decisions.add(Utils.integer(dfa.decisionNumber));
View Full Code Here

    if ( g.getNumberOfDecisions()==0 ) {
      g.buildNFA();
      g.createLookaheadDFAs(false);
    }

    DFA dfa = g.getLookaheadDFA(1);
    assertEquals(null, dfa); // can't analyze.

    /*
    String result = serializer.serialize(dfa.startState);
    assertEquals(expecting, result);
View Full Code Here

    }

    assertEquals("unexpected number of expected problems",
           expectingNumWarnings, equeue.size());

    DFA dfa = g.getLookaheadDFA(decision);
    FASerializer serializer = new FASerializer(g);
    String result = serializer.serialize(dfa.startState);
    //System.out.print(result);
    List unreachableAlts = dfa.getUnreachableAlts();

    // make sure unreachable alts are as expected
    if ( expectingUnreachableAlts!=null ) {
      BitSet s = new BitSet();
      s.addAll(expectingUnreachableAlts);
View Full Code Here

  }

  protected ST genSemanticPredicateExpr(STGroup templates,
                            Transition edge)
  {
    DFA dfa = ((DFAState)edge.target).dfa; // which DFA are we in
    Label label = edge.label;
    SemanticContext semCtx = label.getSemanticContext();
    return semCtx.genExpr(this,templates,dfa);
  }
View Full Code Here

    // This is ok because we've already verified there are no problems
    // with the enter/exit decision
    DFAOptimizer optimizer = new DFAOptimizer(g);
    optimizer.optimize();
    FASerializer serializer = new FASerializer(g);
    DFA dfa = g.getLookaheadDFA(1);
    String result = serializer.serialize(dfa.startState);
    expecting = ".s0-'x'->:s1=>1\n";
    assertEquals(expecting, result);
  }
View Full Code Here

      g.setCodeGenerator(generator);
      g.buildNFA();
      g.createLookaheadDFAs(false);
    }

    DFA dfa = g.getLookaheadDFA(decision);
    assertNotNull("unknown decision #"+decision, dfa);
    FASerializer serializer = new FASerializer(g);
    String result = serializer.serialize(dfa.startState);
    //System.out.print(result);
    List nonDetAlts = dfa.getUnreachableAlts();
    //System.out.println("alts w/o predict state="+nonDetAlts);

    // first make sure nondeterministic alts are as expected
    if ( expectingUnreachableAlts==null ) {
      if ( nonDetAlts!=null && nonDetAlts.size()!=0 ) {
View Full Code Here

        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : {;}'a' | 'b' | 'c';");
    g.createNFAs();
    g.createLookaheadDFAs();
        DFA dfa = g.getLookaheadDFA(1);
        checkPrediction(dfa,"a",1);
        checkPrediction(dfa,"b",2);
        checkPrediction(dfa,"c",3);
        checkPrediction(dfa,"d", NFA.INVALID_ALT_NUMBER);
    }
View Full Code Here

        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : {;}'a'..'z' | ';' | '0'..'9' ;");
    g.createNFAs();
        g.createLookaheadDFAs();
        DFA dfa = g.getLookaheadDFA(1);
        checkPrediction(dfa,"a",1);
        checkPrediction(dfa,"q",1);
        checkPrediction(dfa,"z",1);
        checkPrediction(dfa,";",2);
        checkPrediction(dfa,"9",3);
View Full Code Here

TOP

Related Classes of org.antlr.analysis.DFA

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.