-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.l
86 lines (75 loc) · 1.71 KB
/
sql.l
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
74
75
76
77
78
79
80
81
82
83
84
85
86
%{
#include <stdio.h>
#include <vector>
#include "dbCore.h"
#include "sql.tab.h"
#include <cstring>
int cur_line = 1;
%}
CREATE CREATE|create
SHOW SHOW|show
DROP DROP|drop
USE USE|use
DATABASE DATABASE|database
DATABASES DATABASES|databases
TABLE TABLE|table
TABLES TABLES|tables
CHAR CHAR|char
INT INT|int
FROM from|FROM
SELECT SELECT|select
WHERE WHERE|where
AND AND|and
OR OR|or
INSERT INSERT|insert
INTO INTO|into
VALUES VALUES|VALUES
DELETE DELETE|delete
UPDATE UPDATE|update
SET SET|set
ID [a-zA-Z][a-zA-Z_0-9]*
NUMBER [-+]?[0-9][0-9]*
STRING '.*'
%%
{CHAR} {yylval.typeval = CHAR; return CHAR; }
{INT} {yylval.typeval = INT; return INT;}
{CREATE} { return CREATE;}
{SHOW} {return SHOW; }
{DROP} {return DROP; }
{USE} {return USE;}
{TABLE} {return TABLE;}
{TABLES} { return TABLES;}
{DATABASE} { return DATABASE;}
{DATABASES} { return DATABASES;}
{SELECT} {return SELECT;}
{FROM} {return FROM;}
{WHERE} {return WHERE;}
{AND} {return AND;}
{OR} {return OR;}
{INSERT} {return INSERT;}
{INTO} {return INTO;}
{VALUES} {return VALUES;}
{DELETE} {return DELETE;}
{UPDATE} {return UPDATE;}
{SET} {return SET;}
{ID} { yylval.chval = strdup(yytext); return ID;}
{NUMBER} {yylval.intval = atoi(yytext); return NUMBER;}
"(" { return '('; }
")" { return ')'; }
";" { return ';'; }
"," { return ','; }
"*" { return '*'; }
"." { return '.'; }
"<" { return '<'; }
">" { return '>'; }
"=" { return '='; }
"!" { return '!'; }
\n { cur_line++; }
{STRING} {*(yytext+strlen(yytext)-1) = '\0'; yylval.chval = strdup(yytext+1); return STRING;}
[ \t]+ /* ignore whitespace */;
"//".* { /* DO NOTHING */ }
%%
int yywrap()//此函数必须由用户提供
{
return 1;
}