JavaCC参考程序正在循环
我正在研究JavACC,因此开始从a “ NOFOLLOWN NOREFERRER”>巴西大学。
编码文件并使用JavACC Gradle插件对其进行编译。但是,当使用输入调用生成的类时,该程序似乎闲置了,好像在等待输入一样。
java Adder 123 + 1
实际上,解析器将系统定义为加法类别的参数(请参阅源代码进一步)。因此,我尝试仅运行加法文件并之后输入输入。但是,这有同样的效果。
java Adder
123 + 1
我还尝试使用字符串文字“”和附加\ n的字符串的不同组合,因为BNF期望在表达式之后进行EOF。
编辑:我能够部分解决问题,但决定将这个问题发布到将来,这也可能涉及别人。该教程通过A&lt提供了该程序的输入;操作员。我在Ubuntu WSL安装上运行Java,并与同一命令一起使用。有趣的是,在Windows上不起作用(即使教程显然使用相同的OS系列,但可能与他们在某个时候提到Windows 2000 ... GO GO Digue也不是同一版本)。
java Adder < input.txt
input.txt的内容:123 + 1
对于完整的透明度,我添加了.jj和gradle config
build.gradle:
plugins {
id 'java'
id "ca.coglinc.javacc" version "2.4.0"
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
compileJavacc {
inputDirectory = file('src/main/java/javacc')
outputDirectory = file(project.buildDir.absolutePath + '/generated/javacc')
}
parser.jj
// Parser specification
options {
STATIC = false ;
}
PARSER_BEGIN(Adder)
public class Adder {
public static void main( String[] args ) throws ParseException, TokenMgrError {
// System.out.println("Initializing adder...");
Adder parser = new Adder( System.in ) ;
// System.out.println("Parsing input...");
parser.Start() ;
// System.out.println("done");
}
}
PARSER_END(Adder)
// Lexical analyzer specification
SKIP : { " " }
SKIP : { "\n" | "\r" | "\r\n" }
TOKEN : { < PLUS : "+" > }
TOKEN : { < NUMBER : (["0"-"9"])+ > }
void Start() : {}
{
<NUMBER>
(
<PLUS>
<NUMBER>
)*
<EOF>
}
我已经待了一段时间了,因此它可能会归结为细节。明天我会再次尝试一下,并在这里检查输入。
Godspeed。
I am studying JavaCC and thus started working through an example from a Brazilian university.
Coding the file and compiling it using the JavaCC gradle plugin worked fine. However, when invoking the generated class with input, the program seems idle as if it's waiting for input.
java Adder 123 + 1
Indeed, the Parser defines System.in as an argument to the Adder class (see source code further down). Therefore I tried just running the Adder file and typing the input afterwards. This had the same effect, though.
java Adder
123 + 1
I also tried different combinations using String literal "" and appending \n at the end, since the BNF expects EOF after the expression.
PRE-EDIT: I was able to solve the problem partially but decided to post the question anyway as in the future it might concern someone else, too. The tutorial provides the input to the program with a < operator. I ran java on my Ubuntu WSL installation and got it working with the same command. Interestingly enough that doesn't work on Windows (even though the tutorial obviously uses the same OS family - but probably not the same edition as they mention Windows 2000 at some point...go figure).
java Adder < input.txt
Content of input.txt: 123 + 1
For full transparency I added the .jj and gradle config
build.gradle:
plugins {
id 'java'
id "ca.coglinc.javacc" version "2.4.0"
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
compileJavacc {
inputDirectory = file('src/main/java/javacc')
outputDirectory = file(project.buildDir.absolutePath + '/generated/javacc')
}
Parser.jj
// Parser specification
options {
STATIC = false ;
}
PARSER_BEGIN(Adder)
public class Adder {
public static void main( String[] args ) throws ParseException, TokenMgrError {
// System.out.println("Initializing adder...");
Adder parser = new Adder( System.in ) ;
// System.out.println("Parsing input...");
parser.Start() ;
// System.out.println("done");
}
}
PARSER_END(Adder)
// Lexical analyzer specification
SKIP : { " " }
SKIP : { "\n" | "\r" | "\r\n" }
TOKEN : { < PLUS : "+" > }
TOKEN : { < NUMBER : (["0"-"9"])+ > }
void Start() : {}
{
<NUMBER>
(
<PLUS>
<NUMBER>
)*
<EOF>
}
I've been at it for a while so it might as well come down to a detail. I'll give it another try with a fresh mind tomorrow and check here for input as well.
Godspeed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 WSL 运行命令 java Adder
Works when running the command java Adder <input.txt from the WSL. Seems to be an operating system problem.