Antlr 3.2 重写规则

发布于 2024-10-03 23:49:17 字数 486 浏览 1 评论 0原文

我最近开始学习 Antlr 并下载 AntlrWorks 1.4,其中应该包含 Antlr 3.2。现在,3.2 应该支持重写规则语法,如“->”但我什至无法获得基于 Lexer 或 Parser 规则构建的最简单的情况:

grammar TestRewrite;

ab  :   a b -> a;

a   :   A;
b   :   B;

A   :   'a';
B   :   'b';

当我尝试编译它时,我收到错误:

[11:26:29] error(100): TestRewrite.g:3:13: syntax error: antlr: TestRewrite.g:3:13: unexpected token: a

为什么是这样。构造看起来很简单:ab 应该生成一棵树,其中仅捕获 a 节点。你不就是这样做的吗?我也无法让它与生根('^')或忽略('!')一起工作。我已经很迷茫了。

I've recently started learning Antlr and downloading AntlrWorks 1.4 which supposedly includes Antlr 3.2. Now, 3.2 is supposed to support the rewrite rules grammars like '->' but I've not been able to get even the simplest case I could construct to work either based on Lexer or Parser rules:

grammar TestRewrite;

ab  :   a b -> a;

a   :   A;
b   :   B;

A   :   'a';
B   :   'b';

When I try to compile this, I get the error:

[11:26:29] error(100): TestRewrite.g:3:13: syntax error: antlr: TestRewrite.g:3:13: unexpected token: a

Why is this. The construction seems simple enough: ab should generate a tree where only the a node is captured. Isn't that how you do it? I can't get it to work with rooting ('^') or ignoring ('!') either. I've very confused.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带刺的爱情 2024-10-10 23:49:17

选项 {输出=AST;}

options {output=AST;}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文