英文:
Cannot Find Symbol when compiling a java code
问题
Compiling this using cmd : javac Test.java. However compilation fails, saying it cant find symbol parser.prog(). Any ideas?
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();
}
}
英文:
Compiling this using cmd : javac Test.java. However compilation fails, saying it cant find symbol parser.prog(). Any ideas?
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();
}
}
答案1
得分: 0
在您的 T.g4
语法文件(或 T.g
)中,您还必须有一个名为 prog
的解析规则:
grammar T;
prog
: ...
;
...
从您生成的解析器中可以看出,您有一个类似于以下的解析规则:
filter
: expression EOF
;
请改用以下方式:
// 从规则 prog 开始解析
parser.filter();
英文:
In your T.g4
grammar (or T.g
), you must also have a parser rule named prog
:
grammar T;
prog
: ...
;
...
Looking at your generated parser, I see you have a parser rule like this:
filter
: expression EOF
;
Use that instead:
// Begin parsing at rule prog
parser.filter();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论