antlr4-无法将Hello加载为词法分析器或解析器 [英] antlr4-Can't load Hello as lexer or parser

查看:239
本文介绍了antlr4-无法将Hello加载为词法分析器或解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近不得不使用解析器来做一个项目.我下载了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用作词法分析器或解析器.

Can't load Hello as lexer or parser.

我在Google上搜索了一些信息,但仍然无法确定发生了什么.

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加载为词法分析器或解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆