Commit f35ced3d authored by Michael Meskes's avatar Michael Meskes

- Fixed reduce/reduce conflict in parser.

        - Synced preproc.y with gram.y.
        - Synced pgc.l with scan.l.
        - Synced keywords.c.
parent f76bc9c7
......@@ -1247,6 +1247,13 @@ Sun Apr 28 19:16:40 CEST 2002
- Synced preproc.y with gram.y.
- Fixed typo in comment printed by ecpg.
Sun May 19 19:21:34 CEST 2002
- Fixed reduce/reduce conflict in parser.
- Synced preproc.y with gram.y.
- Synced pgc.l with scan.l.
- Synced keywords.c.
- Set ecpg version to 2.10.0.
- Set library version to 3.4.0.
......@@ -4,7 +4,7 @@
* lexical token lookup for reserved words in postgres embedded SQL
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.25 2001/09/19 14:09:32 meskes Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.26 2002/05/19 20:00:53 meskes Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -34,6 +34,7 @@ static ScanKeyword ScanKeywords[] = {
{"connection", SQL_CONNECTION},
{"continue", SQL_CONTINUE},
{"count", SQL_COUNT},
{"current", SQL_CURRENT},
{"data", SQL_DATA},
{"datetime_interval_code", SQL_DATETIME_INTERVAL_CODE},
{"datetime_interval_precision", SQL_DATETIME_INTERVAL_PRECISION},
......@@ -48,7 +49,6 @@ static ScanKeyword ScanKeywords[] = {
{"goto", SQL_GOTO},
{"identified", SQL_IDENTIFIED},
{"indicator", SQL_INDICATOR},
{"int", SQL_INT},
{"key_member", SQL_KEY_MEMBER},
{"length", SQL_LENGTH},
{"long", SQL_LONG},
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.47 2002/04/22 18:54:43 meskes Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.48 2002/05/19 20:00:53 meskes Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -50,11 +50,14 @@ static ScanKeyword ScanKeywords[] = {
{"before", BEFORE},
{"begin", BEGIN_TRANS},
{"between", BETWEEN},
{"bigint", BIGINT},
{"binary", BINARY},
{"bit", BIT},
{"boolean", BOOLEAN},
{"both", BOTH},
{"by", BY},
{"cache", CACHE},
{"called", CALLED},
{"cascade", CASCADE},
{"case", CASE},
{"cast", CAST},
......@@ -93,6 +96,7 @@ static ScanKeyword ScanKeywords[] = {
{"default", DEFAULT},
{"deferrable", DEFERRABLE},
{"deferred", DEFERRED},
{"definer", DEFINER},
{"delete", DELETE},
{"delimiters", DELIMITERS},
{"desc", DESC},
......@@ -112,6 +116,7 @@ static ScanKeyword ScanKeywords[] = {
{"execute", EXECUTE},
{"exists", EXISTS},
{"explain", EXPLAIN},
{"external", EXTERNAL},
{"extract", EXTRACT},
{"false", FALSE_P},
{"fetch", FETCH},
......@@ -132,6 +137,8 @@ static ScanKeyword ScanKeywords[] = {
{"hour", HOUR_P},
{"ilike", ILIKE},
{"immediate", IMMEDIATE},
{"immutable", IMMUTABLE},
{"implicit", IMPLICIT},
{"in", IN},
{"increment", INCREMENT},
{"index", INDEX},
......@@ -139,12 +146,16 @@ static ScanKeyword ScanKeywords[] = {
{"initially", INITIALLY},
{"inner", INNER_P},
{"inout", INOUT},
{"input", INPUT},
{"insensitive", INSENSITIVE},
{"insert", INSERT},
{"instead", INSTEAD},
{"int", INT},
{"integer", INTEGER},
{"intersect", INTERSECT},
{"interval", INTERVAL},
{"into", INTO},
{"invoker", INVOKER},
{"is", IS},
{"isnull", ISNULL},
{"isolation", ISOLATION},
......@@ -213,6 +224,7 @@ static ScanKeyword ScanKeywords[] = {
{"procedural", PROCEDURAL},
{"procedure", PROCEDURE},
{"read", READ},
{"real", REAL},
{"references", REFERENCES},
{"reindex", REINDEX},
{"relative", RELATIVE},
......@@ -229,6 +241,7 @@ static ScanKeyword ScanKeywords[] = {
{"schema", SCHEMA},
{"scroll", SCROLL},
{"second", SECOND_P},
{"security", SECURITY},
{"select", SELECT},
{"sequence", SEQUENCE},
{"serializable", SERIALIZABLE},
......@@ -238,13 +251,16 @@ static ScanKeyword ScanKeywords[] = {
{"setof", SETOF},
{"share", SHARE},
{"show", SHOW},
{"smallint", SMALLINT},
{"some", SOME},
{"stable", STABLE},
{"start", START},
{"statement", STATEMENT},
{"statistics", STATISTICS},
{"stdin", STDIN},
{"stdout", STDOUT},
{"storage", STORAGE},
{"strict", STRICT},
{"substring", SUBSTRING},
{"sysid", SYSID},
{"table", TABLE},
......@@ -282,6 +298,7 @@ static ScanKeyword ScanKeywords[] = {
{"verbose", VERBOSE},
{"version", VERSION},
{"view", VIEW},
{"volatile", VOLATILE},
{"when", WHEN},
{"where", WHERE},
{"with", WITH},
......
......@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.90 2002/04/05 11:39:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.91 2002/05/19 20:00:53 meskes Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -49,7 +49,10 @@ 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;
int state_before;
struct _yy_buffer
......@@ -131,10 +134,11 @@ xqstart {quote}
xqstop {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
xqliteral [\\](.|\n)
xqescape [\\][^0-7]
xqoctesc [\\][0-7]{1,3}
xqcat {quote}{whitespace_with_newline}{quote}
/* Delimited quote
/* Double quote
* Allows embedded spaces and other special characters into identifiers.
*/
dquote \"
......@@ -229,7 +233,7 @@ non_newline [^\n\r]
comment ("--"{non_newline}*)
whitespace ({space}|{comment})
whitespace ({space}+|{comment})
/*
* SQL92 requires at least one newline in the whitespace separating
......@@ -262,10 +266,7 @@ ip {ipdigit}\.{ipdigit}\.{ipdigit}\.{ipdigit}
/* Take care of cpp continuation lines */
cppline {space}*#(.*\\{space})*.*
/* DO NOT PUT ANY COMMENTS IN THE FOLLOWING SECTION.
* AT&T lex does not properly handle C-style comments in this second lex block.
* So, put comments here. thomas - 1997-09-08
*
/*
* Quoted strings must allow some special characters such as single-quote
* and newline.
* Embedded single-quotes are implemented both in the SQL92-standard
......@@ -278,9 +279,16 @@ cppline {space}*#(.*\\{space})*.*
*/
%%
%{
/* code to execute during start of each call of yylex() */
token_start = NULL;
%}
<SQL>{whitespace} { /* ignore */ }
{xcstart} {
token_start = yytext;
state_before = YYSTATE;
xcdepth = 0;
BEGIN(xc);
......@@ -298,7 +306,10 @@ cppline {space}*#(.*\\{space})*.*
<xc>{xcstop} {
ECHO;
if (xcdepth <= 0)
BEGIN(state_before);
{
BEGIN(INITIAL);
token_start = NULL;
}
else
xcdepth--;
}
......@@ -309,8 +320,10 @@ cppline {space}*#(.*\\{space})*.*
<xc><<EOF>> { mmerror(PARSE_ERROR, ET_ERROR, "Unterminated /* comment"); }
<SQL>{xbitstart} {
token_start = yytext;
BEGIN(xbit);
startlit();
addlitchar('b');
}
<xbit>{xbitstop} {
BEGIN(SQL);
......@@ -327,6 +340,7 @@ cppline {space}*#(.*\\{space})*.*
<xbit><<EOF>> { mmerror(PARSE_ERROR, ET_ERROR, "Unterminated bit string"); }
<SQL>{xhstart} {
token_start = yytext;
BEGIN(xh);
startlit();
}
......@@ -351,6 +365,7 @@ cppline {space}*#(.*\\{space})*.*
<xh><<EOF>> { mmerror(PARSE_ERROR, ET_ERROR, "Unterminated hexadecimal integer"); }
<C,SQL>{xqstart} {
token_start = yytext;
state_before = YYSTATE;
BEGIN(xq);
startlit();
......@@ -360,9 +375,11 @@ cppline {space}*#(.*\\{space})*.*
yylval.str = mm_strdup(literalbuf);
return SCONST;
}
<xq>{xqdouble} |
<xq>{xqinside} |
<xq>{xqliteral} { addlit(yytext, yyleng); }
<xq>{xqdouble} { addlitchar('\''); }
<xq>{xqinside} { addlit(yytext, yyleng); }
<xq>{xqescape} { addlitchar(unescape_single_char(yytext[1])); }
<xq>{xqoctesc} { unsigned char c = strtoul(yytext+1, NULL, 8);
addlitchar(c); }
<xq>{xqcat} { /* ignore */ }
<xq><<EOF>> { mmerror(PARSE_ERROR, ET_ERROR, "Unterminated quoted string"); }
......@@ -374,20 +391,13 @@ cppline {space}*#(.*\\{space})*.*
}
<xd>{xdstop} {
BEGIN(state_before);
if (strlen(literalbuf) >= NAMEDATALEN)
if (literallen == 0)
mmerror(PARSE_ERROR, ET_ERROR, "zero-length delimited identifier");
if (literallen >= NAMEDATALEN)
{
#ifdef MULTIBYTE_NOTUSED
int len;
len = pg_mbcliplen(literalbuf,strlen(literalbuf),NAMEDATALEN-1);
sprintf(errortext, "identifier \"%s\" will be truncated to \"%.*s\"",
literalbuf, len, literalbuf);
literalbuf[len] = '\0';
#else
sprintf(errortext, "identifier \"%s\" will be truncated to \"%.*s\"",
literalbuf, NAMEDATALEN-1, literalbuf);
literalbuf[NAMEDATALEN-1] = '\0';
#endif
mmerror(PARSE_ERROR, ET_WARNING, errortext);
}
......@@ -399,7 +409,7 @@ cppline {space}*#(.*\\{space})*.*
yylval.str = mm_strdup(literalbuf);
return CSTRING;
}
<xd>{xddouble} { addlit(yytext, yyleng-1); }
<xd>{xddouble} { addlitchar('"'); }
<xd>{xdinside} { addlit(yytext, yyleng); }
<xd,xdc><<EOF>> { mmerror(PARSE_ERROR, ET_ERROR, "Unterminated quoted identifier"); }
<C,SQL>{xdstart} {
......@@ -426,8 +436,8 @@ cppline {space}*#(.*\\{space})*.*
* character will match a prior rule, not this one.
*/
int nchars = yyleng;
char *slashstar = strstr((char*)yytext, "/*");
char *dashdash = strstr((char*)yytext, "--");
char *slashstar = strstr(yytext, "/*");
char *dashdash = strstr(yytext, "--");
if (slashstar && dashdash)
{
......@@ -438,7 +448,7 @@ cppline {space}*#(.*\\{space})*.*
else if (!slashstar)
slashstar = dashdash;
if (slashstar)
nchars = slashstar - ((char*)yytext);
nchars = slashstar - yytext;
/*
* For SQL92 compatibility, '+' and '-' cannot be the
......@@ -480,14 +490,14 @@ cppline {space}*#(.*\\{space})*.*
}
/* Convert "!=" operator to "<>" for compatibility */
if (strcmp((char*)yytext, "!=") == 0)
if (strcmp(yytext, "!=") == 0)
yylval.str = mm_strdup("<>");
else
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return Op;
}
<SQL>{param} {
yylval.ival = atol((char*)&yytext[1]);
yylval.ival = atol(yytext+1);
return PARAM;
}
<C,SQL>{integer} {
......@@ -504,26 +514,26 @@ cppline {space}*#(.*\\{space})*.*
)
{
errno = 0;
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return FCONST;
}
yylval.ival = val;
return ICONST;
}
<SQL>{ip} {
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return IP;
}
{decimal} {
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return FCONST;
}
<C,SQL>{real} {
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return FCONST;
}
<SQL>:{identifier}(("->"|\.){identifier})* {
yylval.str = mm_strdup((char*)yytext+1);
yylval.str = mm_strdup(yytext+1);
return(CVARIABLE);
}
<SQL>{identifier} {
......@@ -531,12 +541,12 @@ cppline {space}*#(.*\\{space})*.*
struct _defines *ptr;
/* Is it an SQL keyword? */
keyword = ScanKeywordLookup((char*) yytext);
keyword = ScanKeywordLookup(yytext);
if (keyword != NULL)
return keyword->value;
/* Is it an ECPG keyword? */
keyword = ScanECPGKeywordLookup((char*) yytext);
keyword = ScanECPGKeywordLookup( yytext);
if (keyword != NULL)
return keyword->value;
......@@ -571,7 +581,7 @@ cppline {space}*#(.*\\{space})*.*
*/
if (ptr == NULL)
{
yylval.str = mm_strdup((char*) yytext);
yylval.str = mm_strdup( yytext);
return IDENT;
}
}
......@@ -586,19 +596,19 @@ cppline {space}*#(.*\\{space})*.*
if (*endptr != '\0' || errno == ERANGE)
{
errno = 0;
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return SCONST;
}
return ICONST;
}
<C>{cppline} {
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return(CPP_LINE);
}
<C>{identifier} {
ScanKeyword *keyword;
keyword = ScanCKeywordLookup((char*)yytext);
keyword = ScanCKeywordLookup(yytext);
if (keyword != NULL) {
return keyword->value;
}
......@@ -627,7 +637,7 @@ cppline {space}*#(.*\\{space})*.*
}
if (ptr == NULL)
{
yylval.str = mm_strdup((char*)yytext);
yylval.str = mm_strdup(yytext);
return IDENT;
}
}
......@@ -731,7 +741,7 @@ cppline {space}*#(.*\\{space})*.*
yytext[i+1] = '\0';
for ( defptr = defines; defptr != NULL &&
( strcmp((char*)yytext, defptr->old) != 0 ); defptr = defptr->next );
( strcmp(yytext, defptr->old) != 0 ); defptr = defptr->next );
preproc_tos++;
stacked_if_value[preproc_tos].else_branch = FALSE;
......@@ -911,7 +921,37 @@ addlit(char *ytext, int yleng)
literalbuf[literallen] = '\0';
}
int yywrap(void)
static void
addlitchar(unsigned char ychar)
{
return 1;
/* enlarge buffer if needed */
if ((literallen+1) >= literalalloc)
{
literalalloc *= 2;
literalbuf = (char *) realloc(literalbuf, literalalloc);
}
/* append new data, add trailing null */
literalbuf[literallen] = ychar;
literallen += 1;
literalbuf[literallen] = '\0';
}
unsigned char
unescape_single_char(unsigned char c)
{
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;
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment