我正在学习如何使用Antlr4生成符号表。我碰到过this示例(也是迄今为止唯一的一个示例),但是它给出了Antlr4生成的文件的编译错误。
(命令:
antlr4 Simple.g4
和javac Simple*.java
)
-bash-4.1$ javac Simple*.java
SimpleBaseListener.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
SimpleListener.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
SimpleParser.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
SimpleParser.java:87: error: cannot find symbol
public Scope scope;
^
symbol: class Scope
location: class FileContext
SimpleParser.java:166: error: cannot find symbol
public Scope scope;
^
symbol: class Scope
location: class FuncContext
SimpleParser.java:356: error: cannot find symbol
public Scope scope;
^
symbol: class Scope
location: class BlockContext
SimpleLexer.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
7 errors
我的猜测是此实现使用的是Antlr的旧版本。
是否有Antlr4的示例?我尝试了官方的documentation,但是对于新手来说不是很有帮助。