Hi everyone, I'm writing following code to test the ANTLRParser AST import java.util.List; import org.antlr.runtime.*; import org.antlr.runtime.tree.*; import org.antlr.grammar.v3.*; import org.antlr.tool.*;
//javac -classpath E:\SRC\ANTLR\antlr-3.4-complete.jar;. ANTLRTest.java //java -classpath E:\SRC\ANTLR\antlr-3.4-complete.jar;. ANTLRTest public class ANTLRTest { public static void main(String args[]) { testANTLRParser(); } public static void testANTLRParser() { try { ANTLRParser.grammar__return rt; ANTLRFileStream fs = new ANTLRFileStream("ANTLR.g"); ANTLRLexer lex = new ANTLRLexer(fs); CommonTokenStream token = new CommonTokenStream(lex); ANTLRParser par = ANTLRParser.createParser(token); Grammar gmr = new Grammar(); gmr.setFileName("ANTLR.g"); rt = par.grammar_(gmr); GrammarAST t =(GrammarAST)rt.getTree(); System.out.println( t.toStringTree()); } catch(Exception e) { e.printStackTrace(); } } } when I'm trying to indent the tree I find the parenthesis unbalanced in following text ... (rule grammar_ public (ARG Grammar g) RET scope (@ init this.grammar = g; Map<String, Object> opts;) (@ after cleanup( $tree );) (BLOCK (ALT (? (BLOCK (ALT ACTION <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT (= cmt DOC_COMMENT) <end-of-alt>) <end-of-block>)) (= gr grammarType) (= gid id) grammar.setName($gid.text); SEMI (? (BLOCK (ALT optionsSpec opts = $optionsSpec.opts; grammar.setOptions(opts, $optionsSpec.start); <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT (= ig delegateGrammars) <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT (= ts tokensSpec) <end-of-alt>) <end-of-block>)) (= scopes attrScopes) (? (BLOCK (ALT (= a actions) <end-of-alt>) <end-of-block>)) (= r rules) EOF <end-of-alt>) (REWRITES (-> (ALT (^( gr gid (? (BLOCK (ALT cmt <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT optionsSpec <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT ig <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT ts <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT scopes <end-of-alt>) <end-of-block>)) (? (BLOCK (ALT a <end-of-alt>) <end-of-block>)) r) <end-of-alt>))) <end-of-block>) <end-of-rule>) ... the last parenthesis does not match with the first one but the parenthesis before the first BLOCK . Could someone verify this for me ? Many thanks. List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.