mdbtools/src/sql/lexer.l

84 lines
2.1 KiB
Plaintext
Raw Normal View History

2001-04-08 09:32:43 +08:00
%{
/* MDB Tools - A library for reading MS Access database file
* Copyright (C) 2000 Brian Bruns
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
2001-04-08 09:32:43 +08:00
#include <string.h>
#include "mdbsql.h"
#include "parser.h"
2001-04-08 09:32:43 +08:00
%}
%%
select { return SELECT; }
from { return FROM; }
connect { return CONNECT; }
disconnect { return DISCONNECT; }
2001-04-08 09:32:43 +08:00
to { return TO; }
list { return LIST; }
where { return WHERE; }
tables { return TABLES; }
table { return TABLE; }
describe { return DESCRIBE; }
and { return AND; }
or { return OR; }
not { return NOT; }
2004-02-06 10:34:20 +08:00
is { return IS; }
null { return NULL; }
(<=) { return LTEQ; }
(>=) { return GTEQ; }
like { return LIKE; }
2001-04-08 09:32:43 +08:00
[ \t\r] ;
\"[A-z][A-z0-9 _]*\" {
yylval.name = strdup(&yytext[1]);
yylval.name[strlen(yylval.name)-1]='\0';
return IDENT;
}
[A-z][A-z0-9_]* { yylval.name = strdup(yytext); return NAME; }
2001-04-08 09:32:43 +08:00
'.*' { yylval.name = strdup(yytext); return STRING; }
([0-9]+|([0-9]*\.[0-9+)([eE][-+]?[0-9]+)?) {
yylval.name = strdup(yytext); return NUMBER;
}
~?(\/?[A-z0-9\.]+)+ { yylval.name = strdup(yytext); return PATH; }
2001-04-08 09:32:43 +08:00
. { return yytext[0]; }
%%
int yywrap()
{
return 1;
}
2001-04-08 09:32:43 +08:00
void yyerror(char *s)
{
fprintf(stderr,"Error at Line : %s near %s\n", s, yytext);
}
#if 0
int main(int argc, char **argv)
{
int i;
g_sql = mdb_sql_init();
yyin = stdin;
if (yyparse()) {
fprintf(stderr, "Couldn't parse SQL\n");
exit(1);
}
mdb_sql_dump(g_sql);
mdb_sql_exit(g_sql);
}
#endif