Files
mdbtools/src/sql/parser.y

117 lines
2.2 KiB
Plaintext
Raw Normal View History

2001-04-08 01:32:43 +00: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 01:32:43 +00:00
#include "mdbsql.h"
MdbSQL *g_sql;
%}
%union {
char *name;
double dval;
int ival;
}
%token <name> NAME PATH STRING NUMBER
%token SELECT FROM WHERE CONNECT DISCONNECT TO LIST TABLES WHERE AND
%token DESCRIBE TABLE
%token LTEQ GTEQ LIKE
2001-04-08 01:32:43 +00:00
%type <name> database
%type <name> constant
%type <ival> operator
2001-04-08 01:32:43 +00:00
%%
query:
SELECT column_list FROM table where_clause {
mdb_sql_select(g_sql);
}
| CONNECT TO database {
mdb_sql_open(g_sql, $3); free($3);
2001-04-08 01:32:43 +00:00
}
| DISCONNECT {
mdb_sql_close(g_sql);
}
| DESCRIBE TABLE table {
mdb_sql_describe_table(g_sql);
}
2001-04-08 01:32:43 +00:00
| LIST TABLES {
mdb_sql_listtables(g_sql);
}
;
where_clause:
/* empty */
| WHERE sarg_list
;
sarg_list:
sarg
| sarg AND sarg_list
;
sarg:
NAME operator constant {
mdb_sql_add_sarg(g_sql, $1, $2, $3);
free($1);
free($3);
2001-04-08 01:32:43 +00:00
}
| constant operator NAME {
mdb_sql_add_sarg(g_sql, $3, $2, $1);
free($1);
free($3);
2001-04-08 01:32:43 +00:00
}
;
operator:
'=' { $$ = MDB_EQUAL; }
| '>' { $$ = MDB_GT; }
| '<' { $$ = MDB_LT; }
| LTEQ { $$ = MDB_LTEQ; }
| GTEQ { $$ = MDB_GTEQ; }
| LIKE { $$ = MDB_LIKE; }
2001-04-08 01:32:43 +00:00
;
constant:
NUMBER { $$ = $1; }
| STRING { $$ = $1; }
2001-04-08 01:32:43 +00:00
;
database:
PATH
| NAME
table:
NAME { mdb_sql_add_table(g_sql, $1); free($1); }
2001-04-08 01:32:43 +00:00
;
column_list:
'*' { mdb_sql_all_columns(g_sql); }
| column
| column ',' column_list
;
column:
NAME { mdb_sql_add_column(g_sql, $1); free($1); }
2001-04-08 01:32:43 +00:00
;
%%