Examples of GrammarAST


Examples of org.antlr.tool.GrammarAST

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

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

Examples of org.antlr.tool.GrammarAST

     *  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

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

Examples of org.antlr.tool.GrammarAST

  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

Examples of org.antlr.tool.GrammarAST

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

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

Examples of org.antlr.tool.GrammarAST

      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

Examples of org.antlr.v4.tool.ast.GrammarAST

    AltAST altTree = (AltAST)originalAltTree.dupTree();
    String altLabel = altTree.altLabel!=null ? altTree.altLabel.getText() : null;

    String label = null;
    boolean isListLabel = false;
    GrammarAST lrlabel = stripLeftRecursion(altTree);
    if ( lrlabel!=null ) {
      label = lrlabel.getText();
      isListLabel = lrlabel.getParent().getType() == PLUS_ASSIGN;
      leftRecursiveRuleRefLabels.add(new Pair<GrammarAST,String>(lrlabel,altLabel));
    }

    stripAltLabel(altTree);
View Full Code Here

Examples of org.antlr.v4.tool.ast.GrammarAST

    AltAST altTree = (AltAST)originalAltTree.dupTree();
    String altLabel = altTree.altLabel!=null ? altTree.altLabel.getText() : null;

    String label = null;
    boolean isListLabel = false;
    GrammarAST lrlabel = stripLeftRecursion(altTree);
    if ( lrlabel!=null ) {
      label = lrlabel.getText();
      isListLabel = lrlabel.getParent().getType() == PLUS_ASSIGN;
      leftRecursiveRuleRefLabels.add(new Pair<GrammarAST,String>(lrlabel,altLabel));
    }
    stripAltLabel(altTree);
    String altText = text(altTree);
    altText = altText.trim();
View Full Code Here

Examples of org.antlr.v4.tool.ast.GrammarAST

    for (GrammarAST x : outerAltRuleRefs) {
      RuleRefAST rref = (RuleRefAST)x;
      boolean recursive = rref.getText().equals(ruleName);
      boolean rightmost = rref == outerAltRuleRefs.get(outerAltRuleRefs.size()-1);
      if ( recursive && rightmost ) {
        GrammarAST dummyValueNode = new GrammarAST(new CommonToken(ANTLRParser.INT, ""+prec));
        rref.setOption(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME, dummyValueNode);
      }
    }
    return t;
  }
View Full Code Here

Examples of org.antlr.v4.tool.ast.GrammarAST

   * Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*)))
   * Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))
   */
  public static boolean hasImmediateRecursiveRuleRefs(GrammarAST t, String ruleName) {
    if ( t==null ) return false;
    GrammarAST blk = (GrammarAST)t.getFirstChildWithType(BLOCK);
    if ( blk==null ) return false;
    int n = blk.getChildren().size();
    for (int i = 0; i < n; i++) {
      GrammarAST alt = (GrammarAST)blk.getChildren().get(i);
      Tree first = alt.getChild(0);
      if ( first==null ) continue;
      if (first.getType() == ELEMENT_OPTIONS) {
        first = alt.getChild(1);
        if (first == null) {
          continue;
        }
      }
      if ( first.getType()==RULE_REF && first.getText().equals(ruleName) ) return true;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.