1
創建解析樹請幫我這個問題: 我做網頁上的例子:http://www.antlr.org/wiki/pages/viewpage.action?pageId=1760請幫我從Java和ANTLR
爲了使用這個例子中,我已經建立了語法P於ANTLRWork 1.4和生成代碼以獲得類PLexer
和PParser
。 但是,當我在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());
}
}
錯誤出現:
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);
當我在PParser(tokens,builder)
下降一個參數builder
那麼這個錯誤不找到。但我不知道該怎麼辦好有以下結果:
java TestP
int i;
i=4;
(<grammar prog> (prog (decl (type int) i ;) (stat i = (expr 4))))