这是 SQL 选择语句的简单语法
grammar SQL;
@rulecatch {
//We want to stop parsing when SyntaxException is encountered
//So we re-throw the exception
catch (SyntaxException e) {
throw e;
}
}
eval
: sql_query
;
sql_query
: select_statement from_statement
| select_statement from_statement where_statement
;
select_statement
: 'select' attribute_list
;
from_statement
: 'from' table_name
;
where_statement
: 'where' attribute_name operator constant
;
attribute_list
: '*'
| attribute_name
| attribute_name ',' attribute_list?
;
table_name
: string_literal
;
attribute_name
: string_literal
;
operator
: '=' | '!=' | '>' | '>=' | '<' | '<='
;
constant
: INTEGER
| '"' string_literal '"'
;
fragment DIGIT: '0'..'9';
INTEGER: DIGIT+ ;
fragment LETTER: 'a'..'z'|'A'..'Z';
string_literal: LETTER | LETTER string_literal;
WS : (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel=HIDDEN;};
该工具对sql_query
定义和定义唠叨不休attribute_list
。老实说,我在我的代码中没有看到任何左递归。
谁能解释发生了什么?