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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* %define api.prefix {orafce_sql_yy} is not compileable on old bison 2.4
* so I am using obsolete but still working option.
*/
%name-prefix "orafce_sql_yy"
%{
#define YYDEBUG 1
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \
(Current) = (Rhs)[1]; \
else \
(Current) = (Rhs)[0]; \
} while (0)
#include "postgres.h"
#include "orafce.h"
#include "plvlex.h"
#include "nodes/pg_list.h"
#define MOVE_TO_S(src,dest,col) dest->col = src.col ? pstrdup(src.col) : NULL
#define MOVE_TO(src,dest,col) dest->col = src.col
#define FILL_NODE(src,dest) \
MOVE_TO_S(src,dest,str), \
MOVE_TO(src,dest,keycode), \
MOVE_TO(src,dest,lloc), \
MOVE_TO_S(src,dest,sep), \
MOVE_TO(src,dest,modificator)
static orafce_lexnode *__node;
#define CREATE_NODE(src,type) \
( \
__node = (orafce_lexnode*) palloc(sizeof(orafce_lexnode)), \
__node->typenode = X_##type, \
__node->classname = #type, \
FILL_NODE(src,__node), \
__node)
extern int yylex(void); /* defined as fdate_yylex in fdatescan.l */
static char *scanbuf;
static int scanbuflen;
void orafce_sql_yyerror(List **result, const char *message);
#define YYMALLOC malloc /* XXX: should use palloc? */
#define YYFREE free /* XXX: should use pfree? */
/* silence -Wmissing-variable-declarations */
extern int orafce_sql_yychar;
extern int orafce_sql_yynerrs;
%}
%locations
%parse-param {List **result}
%union
{
int ival;
orafce_lexnode *node;
List *list;
struct
{
char *str;
int keycode;
int lloc;
char *sep;
char *modificator;
} val;
}
/* BISON Declarations */
%token <val> X_IDENT X_NCONST X_SCONST X_OP X_PARAM X_COMMENT X_WHITESPACE X_KEYWORD X_OTHERS X_TYPECAST
%type <list> elements
%type <node> anyelement
%type <list> root
%start root
/* Grammar follows */
%%
root:
elements { *((void**)result) = $1; }
;
elements:
anyelement { $$ = list_make1($1);}
| elements anyelement { $$ = lappend($1, $2);}
;
anyelement:
X_IDENT { $$ = (orafce_lexnode*) CREATE_NODE($1, IDENT); }
| X_NCONST { $$ = (orafce_lexnode*) CREATE_NODE($1, NCONST); }
| X_SCONST { $$ = (orafce_lexnode*) CREATE_NODE($1, SCONST); }
| X_OP { $$ = (orafce_lexnode*) CREATE_NODE($1, OP); }
| X_PARAM { $$ = (orafce_lexnode*) CREATE_NODE($1, PARAM); }
| X_COMMENT { $$ = (orafce_lexnode*) CREATE_NODE($1, COMMENT); }
| X_WHITESPACE { $$ = (orafce_lexnode*) CREATE_NODE($1, WHITESPACE); }
| X_KEYWORD { $$ = (orafce_lexnode*) CREATE_NODE($1, KEYWORD); }
| X_OTHERS { $$ = (orafce_lexnode*) CREATE_NODE($1, OTHERS); }
;
%%
#undef YYLTYPE
#include "sqlscan.c"
|