MysqlQuery.g4 内容如下:
// 1. 定义⼀个名为 MysqlQuery 的语法
grammar MysqlQuery;
// 2. rule - 这是核⼼,表⽰规则,以 “:” 开始, “;” 结束, 多规则以 "|" 分隔。// 2.1 lexer - 词法(符号(Token)名⼤写开头 - 词法)
AS : A S;
SELECT : S E L E C T;
FROM : F R O M;
TABLE : T A B L E;
MAX : M A X;
SUM : S U M;
AVG : A V G;
MIN : M I N;
COUNT : C O U N T;
ALL : A L L;
DISTINCT : D I S T I N C T;
WHERE : W H E R E;
GROUP : G R O U P;
BY : B Y ;
ORDER : O R D E R;
HAVING : H A V I N G;
我们的故事作文NOT : N O T;
IS : I S ;
TRUE : T R U E;
FALSE : F A L S E;
UNKNOWN : U N K N O W N;
BETWEEN : B E T W E E N;
AND : A N D;
IN : I N;
NULL : N U L L;
OR : O R ;
ASC : A S C;
DESC : D E S C;
LIMIT : L I M I T ;
OFFSET : O F F S E T;
fragment A : [aA];
fragment B : [bB];
fragment C : [cC];
fragment D : [dD];
fragment E : [eE];
fragment F : [fF];
fragment G : [gG];
fragment H : [hH];
fragment I : [iI];
fragment J : [jJ];
fragment K : [kK];
fragment L : [lL];
武汉周边一日游fragment M : [mM];菜花简笔画
fragment N : [nN];
fragment O : [oO];
fragment P : [pP];
fragment Q : [qQ];
fragment R : [rR];
fragment S : [sS];
fragment T : [tT];
fragment U : [uU];
fragment V : [vV];
fragment W : [wW];
fragment X : [xX];
fragment Y : [yY];
fragment Z : [zZ];
fragment HEX_DIGIT: [0-9A-F];
青山公园fragment DEC_DIGIT: [0-9];
fragment LETTER: [a-zA-Z];
ID: ( 'A'..'Z' | 'a'..'z' | '_' | '$') ( 'A'..'Z' | 'a'..'z' | '_' | '$' | '0'..'9' )*; TEXT_STRING : ( '\'' ( ('\\' '\\') | ('\'' '\'') | ('\\' '\'') | ~('\'') )* '\'' ); ID_LITERAL: '*'|('@'|'_'|LETTER)(LETTER|DEC_DIGIT|'_')*; REVERSE_QUOTE_ID : '`' ~'`'+ '`';
DECIMAL_LITERAL: DEC_DIGIT+;
// 2.2 parr - 语法
//解析规则(Parr rule)名⼩写开头,后⾯可以跟字母、数字、下划线 - 语法tableName : tmpName=ID;
column_name :ID;
function_name : tmpName=ID ;
lectStatement:
SELECT
lectElements
(
FROM tableSources
( whereClau )?
( groupByCalu )?
( havingCalu )?
) ?投资计划书模板
( orderByClau )?
( limitClau )?
;
lectElements
: (star='*' | lectElement ) (',' lectElement)*
;
tableSources
: tableName (',' tableName)*
;
whereClau
: WHERE logicExpression
;
logicExpression
: logicExpression logicalOperator logicExpression
| fullColumnName comparisonOperator value
好英语
| fullColumnName BETWEEN value AND value
| fullColumnName NOT? IN '(' value (',' value)* ')'
| '(' logicExpression ')'
;
groupByCalu
:
GROUP BY groupByItem (',' groupByItem)*
;
havingCalu
: HAVING logicExpression
;
orderByClau
: ORDER BY orderByExpression (',' orderByExpression)* ;
limitClau
: LIMIT
(
(offt=decimalLiteral ',')? limit=decimalLiteral
| limit=decimalLiteral OFFSET offt=decimalLiteral
)
;
orderByExpression
: fullColumnName order=(ASC | DESC)?
;
groupByItem
: fullColumnName order=(ASC | DESC)?
;
logicalOperator
: AND | '&' '&' | OR | '|' '|'
;
调研论文
comparisonOperator
: '=' | '>' | ' | ' '=' | '>' '='
| ' '>' | '!' '=' | ' '=' '>'
腊肉炒白菜的做法;
value
: uid
| textLiteral
| decimalLiteral
;
decimalLiteral