问题描述
我最近不得不使用解析器来做一个项目.我下载了 ANTLR4
并按照 The Definitive ANTLR4 Reference
一书中描述的步骤进行操作.以下是我在命令行中输入的步骤:
I recently have to use parser to do a project. I download ANTLR4
and follow the steps described in the book The Definitive ANTLR4 Reference
. The following are the steps I type in command line:
1. export CLASSPATH=".:/<Mydirectory>/antlr-4.2.2-complete.jar:$CLASSPATH"
2. alias antlr4='java -jar /<My directory>/antlr-4.2.2-complete.jar'
3. alias grun='java org.antlr.v4.runtime.misc.TestRig'
4. antlr4 Hello.g4
一切正常,它生成了我需要的 java 文件.但是,在我输入
All the things work fine, it generates java files that I need. However, after I enter
5. grun Hello r -tokens
报告
无法将 Hello 加载为词法分析器或解析器.
我在谷歌上搜索了一些信息,但仍然无法弄清楚发生了什么.
I google some info, but still cannot figure out what happened.
推荐答案
您通过在语法上运行 ANTLR 生成了 Java 源文件,但 TestRig 正在寻找已编译的 .class 文件.在使用 TestRig 之前,您需要在源文件上运行 Java 编译器.
You generated Java source files by running ANTLR on the grammar, but TestRig is looking for compiled .class files. You need to run the Java compiler on the source files before using TestRig.
这篇关于antlr4-无法将 Hello 加载为词法分析器或解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!