how to use the generated parser from antlr with java

38 views
Skip to first unread message

exia...@gmail.com

unread,
Apr 2, 2013, 2:09:02 PM4/2/13
to antlr-di...@googlegroups.com
0 down vote favorite

I am trying to generate an AST with Java, for that I used this code:

String src = "int k = 5;";
cAST3Lexer lexer = new cAST3Lexer(new ANTLRStringStream(src));
System.out.println("a");
cAST3Parser parser = new cAST3Parser(new CommonTokenStream(lexer));
System.out.println("b");

CommonTree arbre = (CommonTree)parser.translation_unit().getTree();
DOTTreeGenerator gen = new DOTTreeGenerator();
StringTemplate st = gen.toDOT(arbre);
System.out.println(st);

Unfortunatly, when I run the programme the code stops at this line :

cAST3Parser parser = new cAST3Parser(new CommonTokenStream(lexer));

Well the programme is still running, but the "b" won't be printed.It seems I can then write on the console. Did I do something wrong ? Here is my grammar .
http://sd-g1.archive-host.com/membres/up/24fe084677d7655eb57ba66e1864081450017dd9/cAST3.txt

Reply all
Reply to author
Forward
0 new messages