How to convert MySQL yacc grammar to antlr LL(1)?(如何将 MySQL yacc 语法转换为 antlr LL(1)?)
问题描述
我正在用 ANTLR 构建一个 MySQL 语法验证器.我从 MySQL 源代码中的 sql_yacc.yy
开始,但我在转换以下语法时遇到了一些困难.我尝试了很多次,但它不起作用.有人可以帮我吗?
I am constructing a MySQL grammar validator with ANTLR. I started with the sql_yacc.yy
from the MySQL source code, but I have some difficulties converting the following grammar. I tried many times, but it doesn't work. Can anyone help me?
expr
: expr or expr
| expr XOR expr
| expr and expr
| NOT_SYM expr
| bool_pri IS TRUE_SYM
| bool_pri IS not TRUE_SYM
| bool_pri IS FALSE_SYM
| bool_pri IS not FALSE_SYM
| bool_pri IS UNKNOWN_SYM
| bool_pri IS not UNKNOWN_SYM
| bool_pri
;
bool_pri
: bool_pri IS NULL_SYM
| bool_pri IS not NULL_SYM
| bool_pri EQUAL_SYM predicate
| bool_pri comp_op predicate
| bool_pri comp_op all_or_any '(' subselect ')'
| predicate
;
predicate
: bit_expr IN_SYM '(' subselect ')'
| bit_expr not IN_SYM '(' subselect ')'
| bit_expr IN_SYM '(' expr ')'
| bit_expr IN_SYM '(' expr ',' expr_list ')'
| bit_expr not IN_SYM '(' expr ')'
| bit_expr not IN_SYM '(' expr ',' expr_list ')'
| bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
| bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
| bit_expr SOUNDS_SYM LIKE bit_expr
| bit_expr LIKE simple_expr opt_escape
| bit_expr not LIKE simple_expr opt_escape
| bit_expr REGEXP bit_expr
| bit_expr not REGEXP bit_expr
| bit_expr
;
bit_expr
: bit_expr '|' bit_expr
| bit_expr '&' bit_expr
| bit_expr SHIFT_LEFT bit_expr
| bit_expr SHIFT_RIGHT bit_expr
| bit_expr '+' bit_expr
| bit_expr '-' bit_expr
| bit_expr '+' INTERVAL_SYM expr interval
| bit_expr '-' INTERVAL_SYM expr interval
| bit_expr '*' bit_expr
| bit_expr '/' bit_expr
| bit_expr '%' bit_expr
| bit_expr DIV_SYM bit_expr
| bit_expr MOD_SYM bit_expr
| bit_expr '^' bit_expr
| simple_expr
;
推荐答案
ANTLR 无法应对 left-recursion,因此没有简单的方法可以将 sql_yacc.yy
转换为 ANTLR 等效项.您可能想查看 ANTLR Wiki 中的以下资源:
ANTLR cannot cope with left-recursion, so there's no trivial way to convert sql_yacc.yy
into the ANTLR equivalent. You might want to have a look at the following resources from the ANTLR Wiki:
- 左递归移除
- MySQL 方言 (ANTLR v3) 的 SQL 语法
请注意,MySQL 语法不完整,但可能会给您一个起点.
Note that the MySQL grammar is incomplete, but might give you a starting point.
这篇关于如何将 MySQL yacc 语法转换为 antlr LL(1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 MySQL yacc 语法转换为 antlr LL(1)?


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01