-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsql.l
More file actions
46 lines (37 loc) · 892 Bytes
/
sql.l
File metadata and controls
46 lines (37 loc) · 892 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
43
44
45
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "y.tab.h"
void yyerror(char *s, ...);
%}
var [A-Za-z][A-Za-z0-9]*
digit [0-9]+
%option noyywrap yylineno case-insensitive
%%
CREATE { return CREATE;}
DATABASE { return DATABASE; }
TABLE { return TABLE; }
CHAR {return CHAR;}
INT {return INT;}
AND {return AND;}
OR {return OR;}
SELECT { return SELECT;}
FROM { return FROM; }
WHERE { return WHERE;}
DELETE { return DELETE;}
DROP {return DROP;}
USE {return USE;}
UPDATE {return UPDATE;}
INSERT {return INSERT;}
INTO {return INTO;}
VALUES {return VALUES;}
SET {return SET;}
SHOW {return SHOW;}
TABLES {return TABLES;}
{var} { yylval.sval = strdup(yytext); return VAR; }
{digit} {yylval.ival = atoi(yytext); return NUMBER;}
[*,;{}()!=<>] { return yytext[0]; }
[ \t\n] { }
. { yyerror("mystery character '%c'", *yytext);}
%%