antlr - 删除ANTLR中的左递归?
问题描述
我想知道如何解决这个错误?
以下几组规则是相互左递归的 [type, array_type]
目标是实现这样的目标:
(数组类型)类型->类型[ expr ]
应该包含在类型参数中。任何帮助,将不胜感激
以下代码:
// Types
type
: atomic_type
| named_type
| pointer_type
| record_type
| enclosed_type
| array_type
;
atomic_type
: VOID
| CHAR
| INTEGER
| BOOLEAN
;
named_type
: IDENTIFIER
;
// LEFT SIDE RECURSION, SHOULD BE INCLUDED IN TYPE ABOVE
array_type
: type MLBRACE expr MRBRACE
;
pointer_type
: CARET type
;
record_type
: BLBRACE IDENTIFIER COLON type BLBRACE (COMMA? IDENTIFIER COLON type) BRBRACE BRBRACE
;
enclosed_type
: SLBRACE type SRBRACE
;
编辑:我已经在:
type
: atomic_type
| named_type
| pointer_type
| record_type
| enclosed_type
| type MLBRACE expr MRBRACE
;
但我的问题是,是否有可能array_type
代替type MLBRACE expr MRBRACE
?
解决方案
不,那是不可能的。您不能在 ANTLR4 中使用间接左递归。
推荐阅读
- python - 如何从异步多线程中获取顺序结果
- python-3.x - 如何绘制带有虚线轮廓且没有表面颜色的双锥?
- c# - 在前台引入折叠的最小化 wpf 应用程序
- reactjs - 使用 webpack 覆盖 node_modules lib 中的文件
- wordpress - WordPress 联系表 7 - 通过 cookie 数据填写字段
- reactjs - 箭头函数的参数
- mysql - 为什么MYSQL中的循环过程返回错误?
- hide - 是否可以在 wxTreeCtrl 中隐藏 wxTreeItems?
- android - 从 localhost 访问数据。在android中工作,但不在网络浏览器中
- ios - Where to put sqlite .db files in iOS project?