ANTLR4 Parser,未创建访问者 [英] ANTLR4 Parser, Visitor not created
问题描述
我是ANTLR的新手,并尝试在ANTLR4中编写语法,而不需要事先刷过以前的版本。我正在阅读 The Definitive ANTLR 4 Reference 一书。我使用Eclipse并安装了此处中给出的ANTLR4 IDE。我在Expr.g4中写了以下语法:
I'm new to ANTLR and trying to write grammar in ANTLR4 without any prior brush with the previous version. I'm following the book 'The Definitive ANTLR 4 Reference'. I use Eclipse and installed ANTLR4 IDE as given in here. I wrote the following grammar in Expr.g4:
grammar Expr;
import Common;
options{
language = Java;
}
prog: stat+;
stat: expr NEWLINE
| ID '=' expr NEWLINE
| NEWLINE;
expr: expr ('/'|'*') expr
| expr ('+'|'-') expr
| INT
| ID
| '('expr')';
Common.g4包含以下内容:
The Common.g4 contains the following:
lexer grammar Common;
ID: [A-Za-z]+;
INT: [0-9]+;
NEWLINE: '\r'?'\n';
WS: [\t]+ -> skip;
创建了lexer.java,但没有创建parser.java和visitor.java以及其他基本文件。请帮我解决问题。在此先感谢。
The lexer.java was created but not parser.java and visitor.java and other base file. Please help me fix the problem. Thanks in advance.
推荐答案
事实上我曾经遇到过同样的问题,我曾经在同一个项目中整合了两个G4文件第一个生成访问者,但第二个没有。
In fact I had the same problem once, I used to integrate two G4 files within the same project the first one generated Visitor but the second didn't.
然后我意识到每个G4文件都有自己的代码生成配置,您可以通过以下方式更改:
Then I realized that each G4 file has its own configuration for code generation that you can change by:
- 右键单击G4文件,然后
运行方式
- 选择
外部工具配置
- 将无访客更改为访客 ,你可以为
听众做同样的事。
- Right click on the G4 file then
Run As
- Choose
External tool configuration
- Change the no-visitor to visitor, you can do the same for listener.
现在访客
生成文件。
这篇关于ANTLR4 Parser,未创建访问者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!