-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLParser.g4
More file actions
33 lines (32 loc) · 1.01 KB
/
SQLParser.g4
File metadata and controls
33 lines (32 loc) · 1.01 KB
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
grammar SQLParser;
program: {query | command};
query: relationname ' <- ' expr;
relationname: IDENTIFIER;
expr:
relationname
| 'select ' condition expr //selection
| 'project ' attributelist expr //projection
| 'rename ' attributelist expr//renaming
| expr ' + ' expr //union
| expr ' - ' expr //difference
| expr ' * ' expr //product
| expr ' & ' expr; //naturaljoin
//selection: 'select ' condition expr;
condition: conjunction (' || ' conjunction)*;
conjunction: comparison (' && ' comparison)*;
comparison: operand (op operand)?;
op: ('==' | '!=' | '<' | '>' | '<=' | '>=');
operand: attributename;// | literal;
attributename: IDENTIFIER;
//literal: who knows finish this
//projection: 'project' (attributelist) expr;
attributelist: attributename (', ' attributelist)*;
/*renaming: 'rename ' (attributelist) expr;
union: expr ' + ' expr;
difference: expr ' - ' expr;
product: expr ' * ' expr;
naturaljoin: expr ' & ' expr;
*/
IDENTIFIER: ALPHA (ALPHA | DIGIT)*;
ALPHA: [a-zA-Z];
DIGIT: [0-9];