-
Notifications
You must be signed in to change notification settings - Fork 0
/
toySQL.g4
76 lines (50 loc) · 870 Bytes
/
toySQL.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This grammar is released to the public domain.
// "Share and enjoy...." :)
grammar toySQL;
import toySQL_Tokens;
stmt
: SELECT what_to_select FROM table_stmt (where_stmt) Semi
;
SELECT : 'select' ;
FROM : 'from' ;
AS : 'as' ;
what_to_select
: Star
| (other_stmt)*
;
Star
: '*'
;
other_stmt
: field_stmt
| value_stmt
| other_stmt Comma ( field_stmt | value_stmt )
;
field_stmt
: field
| field AS alias
;
value_stmt
: value AS alias
;
field
: Identifier
;
alias
: Identifier
;
value
: Number
| String_Literal
;
table_stmt
: Identifier
;
where_stmt
: WHERE compare_stmt
;
compare_stmt
: ( field | value ) RelOp ( field | value )
| compare_stmt OR compare_stmt
| compare_stmt AND compare_stmt
;