forked from mastermay/sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.l
More file actions
42 lines (38 loc) · 963 Bytes
/
sql.l
File metadata and controls
42 lines (38 loc) · 963 Bytes
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
%{
#include "head.h"
#include "y.tab.h"
#include<iostream>
#include<string>
using namespace std;
extern YYSTYPE yylval;
%}
digit [0-9]
letter [A-Za-z]
word {letter}({letter}|{digit})*
whitespace ([ \t]*)
compare [<>=]|(!=)|(>=)|(<=)|(like)
number {digit}+\.?(digit)*
%%
[\(] {return LEFTPARENTHESIS;}
[\)] {return RIGHTPARENTHESIS;}
select {return SELECT;}
from {return FROM;}
where {return WHERE;}
{whitespace} {}
and {yylval = new TreeNode("AND"); return LOGIC;}
or {yylval = new TreeNode("OR"); return LOGIC;}
, {return COMMA;}
; {return SEMICOLON;}
{compare} {yylval = new TreeNode(yytext);return COMPARE;}
{number} {yylval = new TreeNode(yytext); return NUMBER;}
{word} {yylval = new TreeNode(yytext); return WORD;}
. {}
%%
int yywrap(void) {
return 1;
}
int yyerror(string s)
{
cout << s << endl;
return 1;
}