ANTLR4 Parser,未创建访问者 [英] ANTLR4 Parser, Visitor not created

查看:361
本文介绍了ANTLR4 Parser,未创建访问者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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:


  1. 右键单击G4文件,然后运行方式

  2. 选择外部工具配置

  3. 无访客更改为访客 ,你可以为
    听众做同样的事。

  1. Right click on the G4 file then Run As
  2. Choose External tool configuration
  3. Change the no-visitor to visitor, you can do the same for listener.

现在访客生成文件。

这篇关于ANTLR4 Parser,未创建访问者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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