Package org.antlr.tool

Examples of org.antlr.tool.GrammarAST


          stripWildCardAlts(disabledAlts);
          if ( disabledAlts.size()>0 ) {
            // nondeterminism; same input predicts multiple alts.
            // but don't emit error if greedy=true explicitly set
            boolean explicitlyGreedy = false;
            GrammarAST blockAST =
              d.dfa.nfa.grammar.getDecisionBlockAST(d.dfa.decisionNumber);
            if ( blockAST!=null ) {
              String greedyS = (String)blockAST.getBlockOption("greedy");
              if ( greedyS!=null && greedyS.equals("true") ) explicitlyGreedy = true;
            }
            if ( !explicitlyGreedy) ErrorManager.nondeterminism(this,d);
          }
        }
      }
    }

    Set<DFAState> danglingStates = getDanglingStates();
    if ( danglingStates.size()>0 ) {
      //System.err.println("no emanating edges for states: "+danglingStates);
      for (DFAState d : danglingStates) {
        ErrorManager.danglingState(this,d);
      }
    }

    if ( !nonLLStarDecision ) {
      List<Integer> unreachableAlts = dfa.getUnreachableAlts();
      if ( unreachableAlts!=null && unreachableAlts.size()>0 ) {
        // give different msg if it's an empty Tokens rule from delegate
        boolean isInheritedTokensRule = false;
        if ( dfa.isTokensRuleDecision() ) {
          for (Integer altI : unreachableAlts) {
            GrammarAST decAST = dfa.getDecisionASTNode();
            GrammarAST altAST = (GrammarAST)decAST.getChild(altI-1);
            GrammarAST delegatedTokensAlt =
              (GrammarAST)altAST.getFirstChildWithType(ANTLRParser.DOT);
            if ( delegatedTokensAlt !=null ) {
              isInheritedTokensRule = true;
              ErrorManager.grammarWarning(ErrorManager.MSG_IMPORTED_TOKENS_RULE_EMPTY,
                            dfa.nfa.grammar,
                            null,
                            dfa.nfa.grammar.name,
                            delegatedTokensAlt.getChild(0).getText());
            }
          }
        }
        if ( isInheritedTokensRule ) {
        }
View Full Code Here


  protected void stripWildCardAlts(Set<Integer> disabledAlts) {
    List<Integer> sortedDisableAlts = new ArrayList<Integer>(disabledAlts);
    Collections.sort(sortedDisableAlts);
    Integer lastAlt =
      sortedDisableAlts.get(sortedDisableAlts.size()-1);
    GrammarAST blockAST =
      dfa.nfa.grammar.getDecisionBlockAST(dfa.decisionNumber);
    //System.out.println("block with error = "+blockAST.toStringTree());
    GrammarAST lastAltAST;
    if ( blockAST.getChild(0).getType()==ANTLRParser.OPTIONS ) {
      // if options, skip first child: ( options { ( = greedy false ) )
      lastAltAST = (GrammarAST)blockAST.getChild(lastAlt.intValue());
    }
    else {
      lastAltAST = (GrammarAST)blockAST.getChild(lastAlt -1);
    }
    //System.out.println("last alt is "+lastAltAST.toStringTree());
    // if last alt looks like ( ALT . <end-of-alt> ) then wildcard
    // Avoid looking at optional blocks etc... that have last alt
    // as the EOB:
    // ( BLOCK ( ALT 'else' statement <end-of-alt> ) <end-of-block> )
    if ( lastAltAST.getType()!=ANTLRParser.EOB &&
       lastAltAST.getChild(0).getType()== ANTLRParser.WILDCARD &&
       lastAltAST.getChild(1).getType()== ANTLRParser.EOA )
    {
      //System.out.println("wildcard");
      disabledAlts.remove(lastAlt);
    }
  }
View Full Code Here

     *  value like true or TRUE.
     */
    protected int constantValue = INVALID_PRED_VALUE;

    public Predicate(int constantValue) {
      predicateAST = new GrammarAST();
      this.constantValue=constantValue;
    }
View Full Code Here

          stripWildCardAlts(disabledAlts);
          if ( disabledAlts.size()>0 ) {
            // nondeterminism; same input predicts multiple alts.
            // but don't emit error if greedy=true explicitly set
            boolean explicitlyGreedy = false;
            GrammarAST blockAST =
              d.dfa.nfa.grammar.getDecisionBlockAST(d.dfa.decisionNumber);
            if ( blockAST!=null ) {
              String greedyS = (String)blockAST.getBlockOption("greedy");
              if ( greedyS!=null && greedyS.equals("true") ) explicitlyGreedy = true;
            }
            if ( !explicitlyGreedy) ErrorManager.nondeterminism(this,d);
          }
        }
      }
    }

    Set danglingStates = getDanglingStates();
    if ( danglingStates.size()>0 ) {
      //System.err.println("no emanating edges for states: "+danglingStates);
      for (Iterator it = danglingStates.iterator(); it.hasNext();) {
        DFAState d = (DFAState) it.next();
        ErrorManager.danglingState(this,d);
      }
    }

    if ( !nonLLStarDecision ) {
      List<Integer> unreachableAlts = dfa.getUnreachableAlts();
      if ( unreachableAlts!=null && unreachableAlts.size()>0 ) {
        // give different msg if it's an empty Tokens rule from delegate
        boolean isInheritedTokensRule = false;
        if ( dfa.isTokensRuleDecision() ) {
          for (Integer altI : unreachableAlts) {
            GrammarAST decAST = dfa.getDecisionASTNode();
            GrammarAST altAST = (GrammarAST)decAST.getChild(altI-1);
            GrammarAST delegatedTokensAlt =
              (GrammarAST)altAST.getFirstChildWithType(ANTLRParser.DOT);
            if ( delegatedTokensAlt !=null ) {
              isInheritedTokensRule = true;
              ErrorManager.grammarWarning(ErrorManager.MSG_IMPORTED_TOKENS_RULE_EMPTY,
                            dfa.nfa.grammar,
                            null,
                            dfa.nfa.grammar.name,
                            delegatedTokensAlt.getChild(0).getText());
            }
          }
        }
        if ( isInheritedTokensRule ) {
        }
View Full Code Here

  protected void stripWildCardAlts(Set disabledAlts) {
    List sortedDisableAlts = new ArrayList(disabledAlts);
    Collections.sort(sortedDisableAlts);
    Integer lastAlt =
      (Integer)sortedDisableAlts.get(sortedDisableAlts.size()-1);
    GrammarAST blockAST =
      dfa.nfa.grammar.getDecisionBlockAST(dfa.decisionNumber);
    //System.out.println("block with error = "+blockAST.toStringTree());
    GrammarAST lastAltAST = null;
    if ( blockAST.getChild(0).getType()==ANTLRParser.OPTIONS ) {
      // if options, skip first child: ( options { ( = greedy false ) )
      lastAltAST = (GrammarAST)blockAST.getChild(lastAlt.intValue());
    }
    else {
      lastAltAST = (GrammarAST)blockAST.getChild(lastAlt.intValue()-1);
    }
    //System.out.println("last alt is "+lastAltAST.toStringTree());
    // if last alt looks like ( ALT . <end-of-alt> ) then wildcard
    // Avoid looking at optional blocks etc... that have last alt
    // as the EOB:
    // ( BLOCK ( ALT 'else' statement <end-of-alt> ) <end-of-block> )
    if ( lastAltAST.getType()!=ANTLRParser.EOB &&
       lastAltAST.getChild(0).getType()== ANTLRParser.WILDCARD &&
       lastAltAST.getChild(1).getType()== ANTLRParser.EOA )
    {
      //System.out.println("wildcard");
      disabledAlts.remove(lastAlt);
    }
  }
View Full Code Here

     *  value like true or TRUE.
     */
    protected int constantValue = INVALID_PRED_VALUE;

    public Predicate(int constantValue) {
      predicateAST = new GrammarAST();
      this.constantValue=constantValue;
    }
View Full Code Here

      if ( unreachableAlts!=null && unreachableAlts.size()>0 ) {
        // give different msg if it's an empty Tokens rule from delegate
        boolean isInheritedTokensRule = false;
        if ( dfa.isTokensRuleDecision() ) {
          for (Integer altI : unreachableAlts) {
            GrammarAST decAST = dfa.getDecisionASTNode();
            GrammarAST altAST = decAST.getChild(altI-1);
            GrammarAST delegatedTokensAlt =
              altAST.getFirstChildWithType(ANTLRParser.DOT);
            if ( delegatedTokensAlt !=null ) {
              isInheritedTokensRule = true;
              ErrorManager.grammarWarning(ErrorManager.MSG_IMPORTED_TOKENS_RULE_EMPTY,
                            dfa.nfa.grammar,
                            null,
                            dfa.nfa.grammar.name,
                            delegatedTokensAlt.getFirstChild().getText());
            }
          }
        }
        if ( isInheritedTokensRule ) {
        }
View Full Code Here

  protected void stripWildCardAlts(Set disabledAlts) {
    List sortedDisableAlts = new ArrayList(disabledAlts);
    Collections.sort(sortedDisableAlts);
    Integer lastAlt =
      (Integer)sortedDisableAlts.get(sortedDisableAlts.size()-1);
    GrammarAST blockAST =
      dfa.nfa.grammar.getDecisionBlockAST(dfa.decisionNumber);
    //System.out.println("block with error = "+blockAST.toStringTree());
    GrammarAST lastAltAST = null;
    if ( blockAST.getChild(0).getType()==ANTLRParser.OPTIONS ) {
      // if options, skip first child: ( options { ( = greedy false ) )
      lastAltAST = blockAST.getChild(lastAlt.intValue());
    }
    else {
      lastAltAST = blockAST.getChild(lastAlt.intValue()-1);
    }
    //System.out.println("last alt is "+lastAltAST.toStringTree());
    // if last alt looks like ( ALT . <end-of-alt> ) then wildcard
    // Avoid looking at optional blocks etc... that have last alt
    // as the EOB:
    // ( BLOCK ( ALT 'else' statement <end-of-alt> ) <end-of-block> )
    if ( lastAltAST.getType()!=ANTLRParser.EOB &&
       lastAltAST.getChild(0).getType()== ANTLRParser.WILDCARD &&
       lastAltAST.getChild(1).getType()== ANTLRParser.EOA )
    {
      //System.out.println("wildcard");
      disabledAlts.remove(lastAlt);
    }
  }
View Full Code Here

     *  value like true or TRUE.
     */
    protected int constantValue = INVALID_PRED_VALUE;

    public Predicate() {
      predicateAST = new GrammarAST();
      this.gated=false;
    }
View Full Code Here

  protected void stripWildCardAlts(Set disabledAlts) {
    List sortedDisableAlts = new ArrayList(disabledAlts);
    Collections.sort(sortedDisableAlts);
    Integer lastAlt =
      (Integer)sortedDisableAlts.get(sortedDisableAlts.size()-1);
    GrammarAST blockAST =
      dfa.nfa.grammar.getDecisionBlockAST(dfa.decisionNumber);
    //System.out.println("block with error = "+blockAST.toStringTree());
    GrammarAST lastAltAST = null;
    if ( blockAST.getChild(0).getType()==ANTLRParser.OPTIONS ) {
      // if options, skip first child: ( options { ( = greedy false ) )
      lastAltAST = blockAST.getChild(lastAlt.intValue());
    }
    else {
      lastAltAST = blockAST.getChild(lastAlt.intValue()-1);
    }
    //System.out.println("last alt is "+lastAltAST.toStringTree());
    // if last alt looks like ( ALT . <end-of-alt> ) then wildcard
    // Avoid looking at optional blocks etc... that have last alt
    // as the EOB:
    // ( BLOCK ( ALT 'else' statement <end-of-alt> ) <end-of-block> )
    if ( lastAltAST.getType()!=ANTLRParser.EOB &&
       lastAltAST.getChild(0).getType()== ANTLRParser.WILDCARD &&
       lastAltAST.getChild(1).getType()== ANTLRParser.EOA )
    {
      //System.out.println("wildcard");
      disabledAlts.remove(lastAlt);
    }
  }
View Full Code Here

TOP

Related Classes of org.antlr.tool.GrammarAST

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.