在“之间”编写 ANTLR 动作多重性
我正在研究一个 ANTLR 语法,看起来像............
A : B+;
并且我希望能够在 B 的每个实例之前和之后执行一个操作。例如,我想要类似......
A : A {out("Before");} B {out("After");}
| {out("Before");} B {out("After");};
所以在输入流 AB B
上我会看到输出...
Before
After
Before
After
当然,由于左递归规则,第二个示例不是有效的 ANTLR 语法。有没有办法用正确的 ANTLR 语法来完成我想要的事情?
我还应该提到,还有其他方法可以达到 B 规则,因此简单地用 before 和 after 包围 B 规则是行不通的。
I'm working on an ANTLR grammar that looks like...
A : B+;
...and I'd like to be able to perform an action before and after each instance of B. For example, I'd like something like...
A : A {out("Before");} B {out("After");}
| {out("Before");} B {out("After");};
So that on the input stream A B B
I would see the output...
Before
After
Before
After
Of course the second example isn't valid ANTLR syntax because of the left recursive rule. Is there a way to accomplish what I want with proper ANTLR syntax?
I should also mention that there are other ways of reaching the B rule so simply surrounding the B rule with before and after won't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道就没有
工作之类的吗?
Doesn't something like
work?