使用 cmd 编译此文件:javac Test.java。但是编译失败,说找不到符号 parser.prog()。有什么想法吗?
import org.antlr.runtime.*;
public class TestT {
public static void main(String[] args) throws Exception {
// Create an TLexer that feeds from that stream
//TLexer lexer = new TLexer(new ANTLRInputStream(System.in));
TLexer lexer = new TLexer(new ANTLRFileStream("input.txt"));
// Create a stream of tokens fed by the lexer
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Create a parser that feeds off the token stream
TParser parser = new TParser(tokens);
// Begin parsing at rule prog
parser.prog();
}
}
最佳答案
在您的 T.g4
语法(或 T.g
)中,您还必须有一个名为 prog
的解析器规则:
grammar T;
prog
: ...
;
...
查看生成的解析器,我发现您有这样的解析器规则:
filter
: expression EOF
;
使用它来代替:
// Begin parsing at rule prog
parser.filter();
关于java - 编译java代码时找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60512470/