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 1.4 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 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))))