Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.ParseTree


    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr MismatchedSetException(9!={5,10,11})))))";
    assertEquals(expecting, result);
  }
View Full Code Here


    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr NoViableAltException(9!=[4:1: expr : ( INT | FLOAT | ID );])))))";
    assertEquals(expecting, result);
  }
View Full Code Here

  Stack<ParseTree> callStack = new Stack<ParseTree>();
  List<Token> hiddenTokens = new ArrayList<Token>();
  int backtracking = 0;

  public ParseTreeBuilder(String grammarName) {
    ParseTree root = create("<grammar "+grammarName+">");
    callStack.push(root);
  }
View Full Code Here

  /**  What kind of node to create.  You might want to override
   *   so I factored out creation here.
   */
  public ParseTree create(Object payload) {
    return new ParseTree(payload);
  }
View Full Code Here

  public void exitDecision(int i) { backtracking--; }

  @Override
  public void enterRule(String filename, String ruleName) {
    if ( backtracking>0 ) return;
    ParseTree parentRuleNode = callStack.peek();
    ParseTree ruleNode = create(ruleName);
    parentRuleNode.addChild(ruleNode);
    callStack.push(ruleNode);
  }
View Full Code Here

  }

  @Override
  public void exitRule(String filename, String ruleName) {
    if ( backtracking>0 ) return;
    ParseTree ruleNode = callStack.peek();
    if ( ruleNode.getChildCount()==0 ) {
      ruleNode.addChild(epsilonNode());
    }
    callStack.pop();   
  }
View Full Code Here

  }

  @Override
  public void consumeToken(Token token) {
    if ( backtracking>0 ) return;
    ParseTree ruleNode = callStack.peek();
    ParseTree elementNode = create(token);
    elementNode.hiddenTokens = this.hiddenTokens;
    this.hiddenTokens = new ArrayList<Token>();
    ruleNode.addChild(elementNode);
  }
View Full Code Here

  }

  @Override
  public void recognitionException(RecognitionException e) {
    if ( backtracking>0 ) return;
    ParseTree ruleNode = callStack.peek();
    ParseTree errorNode = create(e);
    ruleNode.addChild(errorNode);
  }
View Full Code Here

*/
public class ParseTreeBuilder extends BlankDebugEventListener {
  Stack callStack = new Stack();

  public ParseTreeBuilder(String grammarName) {
    ParseTree root = create("<grammar "+grammarName+">");
    callStack.push(root);
  }
View Full Code Here

  /**  What kind of node to create.  You might want to override
   *   so I factored out creation here.
   */
  public ParseTree create(Object payload) {
    return new ParseTree(payload);
  }
View Full Code Here

TOP

Related Classes of org.antlr.runtime.tree.ParseTree

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.