编译 java 代码时找不到符号

Cannot Find Symbol when compiling a java code

使用 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();