[antlr-interest] Help me create treeParser

le nguyen beginner.nguyen at gmail.com
Fri Aug 27 01:01:14 PDT 2010


Hi, everybody,
Please help me this problem:
I do the example on the page:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=1760
in order use this example, i have built the grammar P on ANTLRWork and
generate code to have class PLexer and PParser.
But when i run this code on java Jcreator 4.5:
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.runtime.debug.*;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import ParserAndLexer.*;
public class TestP {
public static void main (String[] args) throws Exception{
    ANTLRInputStream input=new ANTLRInputStream(System.in);
    PLexer lexer=new PLexer(input);
    CommonTokenStream tokens=new CommonTokenStream(lexer);
    ParseTreeBuilder builder=new ParseTreeBuilder("prog");
    PParser parser=new PParser(tokens,builder);
    parser.prog();
    System.out.println(builder.getTree().toStringTree());
}
}
-----------------------------

the error appear:
D:\CAO HOC\TAI LIEU THAM KHAO\ANTLR-EBNF\CREATE PARSTREE\TestP.java:14:
cannot find symbol
symbol  : constructor
PParser(org.antlr.runtime.CommonTokenStream,org.antlr.runtime.debug.ParseTreeBuilder)
location: class ParserAndLexer.PParser
    PParser parser=new PParser(tokens,builder);
---------------------------
When I drop one argument "builder" in method PParser(tokens,builder) then
that error not found. but i don't know how to run to have the following
result:
java TestP
int i;
i=4;
(<grammar prog> (prog (decl (type int) i ;) (stat i = (expr 4))))

note: I have attach a file. Could you have me.
Thanh you very much.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CREATE PARSTREE.rar
Type: application/rar
Size: 8474 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100827/b5b35b3d/attachment.bin 


More information about the antlr-interest mailing list