Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.CommonTreeNodeStream


  public String grammarTreeToString(GrammarAST t, boolean showActions) {
    String s;
    try {
      s = t.getLine()+":"+(t.getCharPositionInLine()+1)+": ";
      s += new ANTLRTreePrinter(new CommonTreeNodeStream(t)).toString(this, showActions);
    }
    catch (Exception e) {
      s = "<invalid or missing tree structure>";
    }
    return s;
View Full Code Here


    }
    return s;
  }

  public void printGrammar(PrintStream output) {
    ANTLRTreePrinter printer = new ANTLRTreePrinter(new CommonTreeNodeStream(getGrammarTree()));
    try {
      String g = printer.toString(this, false);
      output.println(g);
    }
    catch (RecognitionException re) {
View Full Code Here

            Class<?> _return = classForName(parserName+"$"+testRuleName+"_return");
          Method returnName = _return.getMethod("getTree");
          CommonTree tree = (CommonTree) returnName.invoke(ruleReturn);

          // Walk resulting tree; create tree nodes stream first
          CommonTreeNodeStream nodes;
          if ( customTreeAdaptor!=null ) {
            nodes = new CommonTreeNodeStream(customTreeAdaptor, tree);
          }
          else {
            nodes = new CommonTreeNodeStream(tree);
          }
          // AST nodes have payload that point into token stream
          nodes.setTokenStream(tokens);
          // Create a tree walker attached to the nodes stream
          treeParser = classForName(treeParserPath).asSubclass(TreeParser.class);
            Constructor<? extends TreeParser> treeParConstructor = treeParser.getConstructor(TreeNodeStream.class);
            TreeParser treeParObj = treeParConstructor.newInstance(nodes)// makes new instance of tree parser
          // Invoke the tree rule, and store the return value if there is
View Full Code Here

  public Map<Integer, ASSOC> altAssociativity = new HashMap<Integer, ASSOC>();

  public LeftRecursiveRuleAnalyzer(GrammarAST ruleAST,
                   Tool tool, String ruleName, String language)
  {
    super(new CommonTreeNodeStream(new GrammarASTAdaptor(ruleAST.token.getInputStream()), ruleAST));
    this.tool = tool;
    this.ruleName = ruleName;
    this.language = language;
    this.tokenStream = ruleAST.g.tokenStream;
    if (this.tokenStream == null) {
View Full Code Here

        tool.log("grammar", "after: "+root.toStringTree());
  }

  public void reduceBlocksToSets(GrammarAST root) {
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(new GrammarASTAdaptor(), root);
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    BlockSetTransformer transformer = new BlockSetTransformer(nodes, g);
    transformer.setTreeAdaptor(adaptor);
    transformer.downup(root);
  }
View Full Code Here

  }

  /** Given list of X and r refs in alt, compute how many of each there are */
  protected FrequencySet<String> getElementFrequenciesForAlt(AltAST ast) {
    try {
      ElementFrequenciesVisitor visitor = new ElementFrequenciesVisitor(new CommonTreeNodeStream(new GrammarASTAdaptor(), ast));
      visitor.outerAlternative();
      if (visitor.frequencies.size() != 1) {
        factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR);
        return new FrequencySet<String>();
      }
View Full Code Here

  }

  public String toTokenString() {
    CharStream input = this.token.getInputStream();
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor(input);
    CommonTreeNodeStream nodes =
      new CommonTreeNodeStream(adaptor, this);
    StringBuilder buf = new StringBuilder();
    GrammarAST o = (GrammarAST)nodes.LT(1);
    int type = adaptor.getType(o);
    while ( type!=Token.EOF ) {
      buf.append(" ");
      buf.append(o.getText());
      nodes.consume();
      o = (GrammarAST)nodes.LT(1);
      type = adaptor.getType(o);
    }
    return buf.toString();
  }
View Full Code Here

    // GENERATE RECOGNIZER
    // Walk the AST holding the input grammar, this time generating code
    // Decisions are generated by using the precomputed DFAs
    // Fill in the various templates with data
    CodeGenTreeWalker gen = new CodeGenTreeWalker(new CommonTreeNodeStream(grammar.getGrammarTree()));
    try {
      gen.grammar_(
            grammar,
            recognizerST,
            outputFileST,
View Full Code Here

      ErrorManager.internalError("can't parse template action",tse);
    }
    GrammarAST rewriteTree = parseResult.getTree();

    // then translate via codegen.g
    CodeGenTreeWalker gen = new CodeGenTreeWalker(new CommonTreeNodeStream(rewriteTree));
    gen.init(grammar);
    gen.setCurrentRuleName(ruleName);
    gen.setOuterAltNum(outerAltNum);
    ST st = null;
    try {
View Full Code Here

    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    for (Rule r : rules) {
      // find rule's block
      GrammarAST blk = (GrammarAST)r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
      CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
      ATNBuilder b = new ATNBuilder(nodes,this);
      try {
        setCurrentRuleName(r.name);
        Handle h = b.ruleBlock(null);
        rule(r.ast, r.name, h);
View Full Code Here

TOP

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

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.