From 7f660adeb1fd4a1b8f75fef1bdc7ead8e31e6737 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Mon, 20 May 2002 09:29:41 +0000 Subject: [PATCH] - Fixed some parser bugs. - Removed some simple rules to work arounf bison limit for now. - Update c_keywords.c to reflect changes in keywords.c. --- src/interfaces/ecpg/ChangeLog | 6 + src/interfaces/ecpg/preproc/c_keywords.c | 2 +- src/interfaces/ecpg/preproc/extern.h | 2 +- src/interfaces/ecpg/preproc/pgc.l | 30 ++--- src/interfaces/ecpg/preproc/preproc.y | 142 +++++++++++------------ 5 files changed, 81 insertions(+), 101 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index b07d22d6806..2b05d3de38e 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1254,6 +1254,12 @@ Sun May 19 19:21:34 CEST 2002 - Synced preproc.y with gram.y. - Synced pgc.l with scan.l. - Synced keywords.c. + +Mon May 20 10:58:36 CEST 2002 + + - Fixed some parser bugs. + - Removed some simple rules to work arounf bison limit for now. + - Update c_keywords.c to reflect changes in keywords.c. - Set ecpg version to 2.10.0. - Set library version to 3.4.0. diff --git a/src/interfaces/ecpg/preproc/c_keywords.c b/src/interfaces/ecpg/preproc/c_keywords.c index 7ce7e376c1b..e057d5b5ec8 100644 --- a/src/interfaces/ecpg/preproc/c_keywords.c +++ b/src/interfaces/ecpg/preproc/c_keywords.c @@ -29,7 +29,7 @@ static ScanKeyword ScanKeywords[] = { {"enum", SQL_ENUM}, {"extern", S_EXTERN}, {"float", FLOAT}, - {"int", SQL_INT}, + {"int", INT}, {"long", SQL_LONG}, {"register", S_REGISTER}, {"short", SQL_SHORT}, diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index 9759db21a2c..4ef4f510028 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -18,7 +18,7 @@ extern char *descriptor_index; extern char *descriptor_name; extern char *connection; extern char *input_filename; -extern char *yytext, +extern char *yytext, *token_start, errortext[128]; #ifdef YYDEBUG diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index 3bc4a0aa722..d8478e3bc3b 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.91 2002/05/19 20:00:53 meskes Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.92 2002/05/20 09:29:41 meskes Exp $ * *------------------------------------------------------------------------- */ @@ -50,9 +50,8 @@ static int literalalloc; /* current allocated buffer size */ #define startlit() (literalbuf[0] = '\0', literallen = 0) static void addlit(char *ytext, int yleng); static void addlitchar (unsigned char); -static unsigned char unescape_single_char(unsigned char); -static char *token_start; +char *token_start; int state_before; struct _yy_buffer @@ -307,7 +306,7 @@ cppline {space}*#(.*\\{space})*.* ECHO; if (xcdepth <= 0) { - BEGIN(INITIAL); + BEGIN(state_before); token_start = NULL; } else @@ -377,7 +376,7 @@ cppline {space}*#(.*\\{space})*.* } {xqdouble} { addlitchar('\''); } {xqinside} { addlit(yytext, yyleng); } -{xqescape} { addlitchar(unescape_single_char(yytext[1])); } +{xqescape} { addlit(yytext, yyleng); } {xqoctesc} { unsigned char c = strtoul(yytext+1, NULL, 8); addlitchar(c); } {xqcat} { /* ignore */ } @@ -936,22 +935,9 @@ addlitchar(unsigned char ychar) literalbuf[literallen] = '\0'; } -unsigned char -unescape_single_char(unsigned char c) +int +yywrap(void) { - switch (c) - { - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - default: - return c; - } + return(1); } + diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index f8535560d42..49c7016b7ad 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.188 2002/05/19 20:00:53 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.189 2002/05/20 09:29:41 meskes Exp $ */ /* Copyright comment */ %{ @@ -328,7 +328,7 @@ make_name(void) %type RemoveAggrStmt opt_procedural select_no_parens %type RemoveOperStmt RenameStmt all_Op opt_Trusted opt_lancompiler %type VariableSetStmt var_value zone_value VariableShowStmt -%type VariableResetStmt AlterTableStmt DropUserStmt from_list +%type VariableResetStmt AlterTableStmt from_list %type opt_trans user_list OptUserList OptUserElem relation_name %type CreateUserStmt AlterUserStmt CreateSeqStmt OptSeqList %type OptSeqElem TriggerForSpec TriggerForOpt TriggerForType @@ -361,18 +361,19 @@ make_name(void) %type insert_target_list insert_column_item DropRuleStmt %type createfunc_opt_item set_rest var_list_or_default %type CreateFunctionStmt createfunc_opt_list func_table +%type DropUserStmt %type ECPGWhenever ECPGConnect connection_target ECPGOpen %type indicator ECPGExecute ECPGPrepare ecpg_using ecpg_into -%type storage_clause opt_initializer c_anything blockstart -%type blockend variable_list variable c_thing c_term +%type storage_clause opt_initializer c_anything +%type variable_list variable c_thing c_term %type opt_pointer ECPGDisconnect dis_name storage_modifier %type stmt ECPGRelease execstring server_name %type connection_object opt_server opt_port c_stuff c_stuff_item %type user_name opt_user char_variable ora_user ident opt_reference %type quoted_ident_stringvar var_type_declarations %type db_prefix server opt_options opt_connection_name c_list -%type ECPGSetConnection cpp_line ECPGTypedef c_args ECPGKeywords +%type ECPGSetConnection ECPGTypedef c_args ECPGKeywords %type enum_type civar civarind ECPGCursorStmt ECPGDeallocate %type ECPGFree ECPGDeclare ECPGVar opt_at enum_definition %type struct_type s_struct vt_declarations variable_declarations @@ -382,7 +383,7 @@ make_name(void) %type ECPGGetDescriptorHeader ECPGColLabel %type reserved_keyword unreserved_keyword %type col_name_keyword func_name_keyword -%type ECPGTypeName variablelist cvariable +%type ECPGTypeName variablelist %type ECPGGetDescriptor @@ -409,10 +410,10 @@ statements: /*EMPTY*/ statement: ecpgstart opt_at stmt ';' { connection = NULL; } | ecpgstart stmt ';' | ECPGDeclaration - | c_thing { fprintf(yyout, "%s", $1); free($1); } - | cpp_line { fprintf(yyout, "%s", $1); free($1); } - | blockstart { fputs($1, yyout); free($1); } - | blockend { fputs($1, yyout); free($1); } + | c_thing { fprintf(yyout, "%s", $1); free($1); } + | CPP_LINE { fprintf(yyout, "%s", $1); free($1); } + | '{' { braces_open++; fputs("{", yyout); } + | '}' { remove_variables(braces_open--); fputs("}", yyout); } ; opt_at: AT connection_target @@ -689,14 +690,13 @@ AlterUserSetStmt: ALTER USER UserId SET set_rest * * *****************************************************************************/ - DropUserStmt: DROP USER user_list { $$ = cat2_str(make_str("drop user"), $3);} ; - /* * Options for CREATE USER and ALTER USER */ + OptUserList: OptUserList OptUserElem { $$ = cat2_str($1, $2); } | /* EMPTY */ { $$ = EMPTY; } ; @@ -725,7 +725,6 @@ user_list: user_list ',' UserId { $$ = $1; } ; - /***************************************************************************** * * Create a postgresql group @@ -822,13 +821,12 @@ schema_stmt: CreateStmt { $$ = $1; } * SET TIME ZONE 'var_value' * *****************************************************************************/ - VariableSetStmt: SET set_rest { $$ = cat2_str(make_str("set"), $2 ); } | SET LOCAL set_rest - { $$ = cat2_str(make_str("set local"), $2 ); } + { $$ = cat2_str(make_str("set local"), $3 ); } | SET SESSION set_rest - { $$ = cat2_str(make_str("set session"), $2 ); } + { $$ = cat2_str(make_str("set session"), $3 ); } ; set_rest: ColId TO var_list_or_default @@ -876,7 +874,6 @@ opt_boolean: TRUE_P { $$ = make_str("true"); } | ON { $$ = make_str("on"); } | OFF { $$ = make_str("off"); } ; - /* Timezone values can be: * - a string such as 'pst8pdt' * - a column identifier such as "pst8pdt" @@ -2193,7 +2190,7 @@ opt_equal: '=' { $$ = make_str("="); } *****************************************************************************/ AlterDatabaseSetStmt: ALTER DATABASE database_name SET set_rest - { $$ = cat_str(4, make_str("alter database"), $3, make_Str("set"), $5); } + { $$ = cat_str(4, make_str("alter database"), $3, make_str("set"), $5); } | ALTER DATABASE database_name VariableResetStmt { $$ = cat_str(3, make_str("alter database"), $3, $4); } ; @@ -2881,7 +2878,7 @@ opt_decimal: '(' PosIntConst ',' PosIntConst ')' * The following implements BIT() and BIT VARYING(). */ Bit: BIT opt_varying '(' PosIntConst ')' - { $$ = cat_str(5, $1, $2, make_str("("), $4, make_str(")")); } + { $$ = cat_str(5, make_str("bit"), $2, make_str("("), $4, make_str(")")); } | BIT opt_varying { $$ = cat2_str(make_str("bit"), $2); } ; @@ -3687,7 +3684,7 @@ connection_target: database_name opt_server opt_port } ; -db_prefix: ident cvariable +db_prefix: ident CVARIABLE { if (strcmp($2, "postgresql") != 0 && strcmp($2, "postgres") != 0) { @@ -3778,7 +3775,7 @@ user_name: UserId } ; -char_variable: cvariable +char_variable: CVARIABLE { /* check if we have a char variable */ struct variable *p = find_variable($1); @@ -4421,14 +4418,14 @@ ECPGAllocateDescr: SQL_ALLOCATE SQL_DESCRIPTOR quoted_ident_stringvar * read from descriptor */ -ECPGGetDescHeaderItem: cvariable '=' desc_header_item +ECPGGetDescHeaderItem: CVARIABLE '=' desc_header_item { push_assignment($1, $3); } ; desc_header_item: SQL_COUNT { $$ = ECPGd_count; } ; -ECPGGetDescItem: cvariable '=' descriptor_item { push_assignment($1, $3); }; +ECPGGetDescItem: CVARIABLE '=' descriptor_item { push_assignment($1, $3); }; descriptor_item: SQL_CARDINALITY { $$ = ECPGd_cardinality; } | SQL_DATA { $$ = ECPGd_data; } @@ -4461,7 +4458,7 @@ ECPGGetDescriptorHeader: SQL_GET SQL_DESCRIPTOR quoted_ident_stringvar ; ECPGGetDescriptor: SQL_GET SQL_DESCRIPTOR quoted_ident_stringvar - SQL_VALUE cvariable ECPGGetDescItems + SQL_VALUE CVARIABLE ECPGGetDescItems { $$.str = $5; $$.name = $3; } | SQL_GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE Iconst ECPGGetDescItems { $$.str = $5; $$.name = $3; } @@ -4851,6 +4848,7 @@ function_name: ident { $$ = $1; } ColLabel: ECPGColLabel { $$ = $1; } | ECPGTypeName { $$ = $1; } | CHAR { $$ = make_str("char"); } + | INT { $$ = make_str("int"); } | UNION { $$ = make_str("union"); } ; @@ -5043,29 +5041,36 @@ unreserved_keyword: * looks too much like a function call for an LR(1) parser. */ col_name_keyword: - BIT { $$ = make_str("bit"); } + BIGINT { $$ = make_str("bigint");} + | BIT { $$ = make_str("bit"); } /* CHAR must be excluded from ECPGColLabel because of conflict with UNSIGNED - | CHAR { $$ = make_str("char"); } + | CHAR { $$ = make_str("char"); } */ - | CHARACTER { $$ = make_str("character"); } - | COALESCE { $$ = make_str("coalesce"); } - | DEC { $$ = make_str("dec"); } - | DECIMAL { $$ = make_str("decimal"); } - | EXISTS { $$ = make_str("exists"); } - | EXTRACT { $$ = make_str("extract"); } - | FLOAT { $$ = make_str("float"); } - | INTERVAL { $$ = make_str("interval"); } - | NCHAR { $$ = make_str("nchar"); } - | NONE { $$ = make_str("none"); } - | NULLIF { $$ = make_str("nullif"); } - | NUMERIC { $$ = make_str("numeric"); } - | POSITION { $$ = make_str("position"); } - | SETOF { $$ = make_str("setof"); } - | SUBSTRING { $$ = make_str("substring"); } - | TIME { $$ = make_str("time"); } - | TIMESTAMP { $$ = make_str("timestamp"); } - | TRIM { $$ = make_str("trim"); } - | VARCHAR { $$ = make_str("varchar"); } + | CHARACTER { $$ = make_str("character"); } + | COALESCE { $$ = make_str("coalesce"); } + | DEC { $$ = make_str("dec"); } + | DECIMAL { $$ = make_str("decimal"); } + | EXISTS { $$ = make_str("exists"); } + | EXTRACT { $$ = make_str("extract"); } + | FLOAT { $$ = make_str("float"); } +/* INT must be excluded from ECPGColLabel because of conflict + | INT { $$ = make_str("int"); } + */ + | INTEGER { $$ = make_str("integer"); } + | INTERVAL { $$ = make_str("interval"); } + | NCHAR { $$ = make_str("nchar"); } + | NONE { $$ = make_str("none"); } + | NULLIF { $$ = make_str("nullif"); } + | NUMERIC { $$ = make_str("numeric"); } + | POSITION { $$ = make_str("position"); } + | REAL { $$ = make_str("real"); } + | SETOF { $$ = make_str("setof"); } + | SMALLINT { $$ = make_str("smallint"); } + | SUBSTRING { $$ = make_str("substring"); } + | TIME { $$ = make_str("time"); } + | TIMESTAMP { $$ = make_str("timestamp"); } + | TRIM { $$ = make_str("trim"); } + | VARCHAR { $$ = make_str("varchar"); } ; /* Function identifier --- keywords that can be function names. @@ -5188,14 +5193,14 @@ c_args: /*EMPTY*/ { $$ = EMPTY; } | c_list { $$ = $1; } ; -coutputvariable: cvariable indicator +coutputvariable: CVARIABLE indicator { add_variable(&argsresult, find_variable($1), find_variable($2)); } - | cvariable + | CVARIABLE { add_variable(&argsresult, find_variable($1), &no_indicator); } ; -civarind: cvariable indicator +civarind: CVARIABLE indicator { if ($2 != NULL && (find_variable($2))->type->type == ECPGt_array) mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input"); @@ -5204,18 +5209,15 @@ civarind: cvariable indicator } ; -civar: cvariable +civar: CVARIABLE { add_variable(&argsinsert, find_variable($1), &no_indicator); $$ = $1; } ; -cvariable: CVARIABLE { $$ = $1; } - ; - indicator: CVARIABLE { check_indicator((find_variable($1))->type); $$ = $1; } - | SQL_INDICATOR cvariable { check_indicator((find_variable($2))->type); $$ = $2; } + | SQL_INDICATOR CVARIABLE { check_indicator((find_variable($2))->type); $$ = $2; } | SQL_INDICATOR name { check_indicator((find_variable($2))->type); $$ = $2; } ; @@ -5235,10 +5237,8 @@ quoted_ident_stringvar: IDENT * C stuff */ -cpp_line: CPP_LINE { $$ = $1; }; - c_stuff_item: c_anything { $$ = $1; } - | '(' ')' { $$ = make_str("()"); } + | '(' ')' { $$ = make_str("()"); } | '(' c_stuff ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); } ; @@ -5248,19 +5248,19 @@ c_stuff: c_stuff_item { $$ = $1; } { $$ = cat2_str($1, $2); } ; -c_list: c_term { $$ = $1; } - | c_list ',' c_term { $$ = cat_str(3, $1, make_str(","), $3); } +c_list: c_term { $$ = $1; } + | c_list ',' c_term { $$ = cat_str(3, $1, make_str(","), $3); } ; -c_term: c_stuff { $$ = $1; } - | '{' c_list '}' { $$ = cat_str(3, make_str("{"), $2, make_str("}")); } +c_term: c_stuff { $$ = $1; } + | '{' c_list '}' { $$ = cat_str(3, make_str("{"), $2, make_str("}")); } ; c_thing: c_anything { $$ = $1; } - | '(' { $$ = make_str("("); } - | ')' { $$ = make_str(")"); } - | ',' { $$ = make_str(","); } - | ';' { $$ = make_str(";"); } + | '(' { $$ = make_str("("); } + | ')' { $$ = make_str(")"); } + | ',' { $$ = make_str(","); } + | ';' { $$ = make_str(";"); } ; c_anything: IDENT { $$ = $1; } @@ -5315,25 +5315,13 @@ c_anything: IDENT { $$ = $1; } | '=' { $$ = make_str("="); } ; -blockstart : '{' - { - braces_open++; - $$ = make_str("{"); - }; - -blockend : '}' - { - remove_variables(braces_open--); - $$ = make_str("}"); - }; - %% void yyerror( char * error) { char buf[1024]; - snprintf(buf,sizeof buf,"%s at or near \"%s\"",error,yytext); + snprintf(buf,sizeof buf,"%s at or near \"%s\"", error, token_start ? token_start : yytext); buf[sizeof(buf)-1]=0; mmerror(PARSE_ERROR, ET_ERROR, buf); } -- 2.39.5