-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandaQ.g4
47 lines (35 loc) · 1.5 KB
/
pandaQ.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
grammar pandaQ;
root : 'plot' PAR ';' #rootPlot
| PAR ':=' exprSelectUnion ';' #rootStore
| exprSelectUnion ';' #rootNormal
;
exprSelectUnion: exprSelect ('union' 'all' exprSelect)*;
exprSelect : 'select' ('*'|camps) 'from' taulesExpr (whereClause)? (orderByClause)?
;
orderByClause: 'order by' orderByCamp (',' orderByCamp)* ;
orderByCamp : PAR ('asc' | 'desc')?;
camps : (paraula | campCalculat) (',' paraula |',' campCalculat)*;
campCalculat : calcul 'as' PAR;
paraula : PAR;
calcul : '(' calcul ')' #calculParentesis
| calcul ('*'|'/') calcul #calculBin
| calcul ('+'|'-') calcul #calculBin
| (PAR | NUM ) #calculNumPar
;
whereClause: 'where' whereExpr;
whereExpr: '(' whereExpr ')' #whereParentesis
| 'not' whereExpr #whereNot
| whereExpr ('and') whereExpr #whereAndOr
| whereExpr ('or') whereExpr #whereAndOr
| PAR 'in' '(' exprSelect ')' #whereSubconsulta
| whereCamp ('='|'<'|'>'|'<='|'>=') whereCamp #whereEqGt
;
whereCamp : NUM #whereCampNUM
| PAR #whereCampStringParaula
| '"' (PAR|NUM) (PAR|NUM)* '"' #whereCampStringCometes
;
taulesExpr: PAR (innerJoinExpr)*;
innerJoinExpr: 'inner join' PAR 'on' PAR '=' PAR;
NUM : [0-9]+ ('.' [0-9]+)?;
PAR : [A-Za-z0-9_]+ ;
WS : [ \t\n\r]+ -> skip ;