Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
23db70bf
Commit
23db70bf
authored
Sep 08, 1997
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lex/yacc source cleanup like indent.
parent
319dbfa7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
2725 additions
and
2714 deletions
+2725
-2714
src/backend/bootstrap/bootparse.y
src/backend/bootstrap/bootparse.y
+213
-205
src/backend/bootstrap/bootscanner.l
src/backend/bootstrap/bootscanner.l
+60
-60
src/backend/parser/gram.y
src/backend/parser/gram.y
+2263
-2260
src/backend/parser/scan.l
src/backend/parser/scan.l
+186
-186
src/lextest/scan.l
src/lextest/scan.l
+3
-3
No files found.
src/backend/bootstrap/bootparse.y
View file @
23db70bf
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
*
*
* backendparse.y--
* backendparse.y--
*
yacc parser grammer for the "backend" initialization program.
*
yacc parser grammer for the "backend" initialization program.
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
*
$Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.4 1996/11/13 20:47:45 scrappy
Exp $
*
$Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.5 1997/09/08 03:19:50 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -16,11 +16,11 @@
...
@@ -16,11 +16,11 @@
#include "postgres.h"
#include "postgres.h"
#include "catalog/pg_attribute.h"
#include "catalog/pg_attribute.h"
#include "access/attnum.h"
#include "access/attnum.h"
#include "nodes/pg_list.h"
#include "nodes/pg_list.h"
#include "access/tupdesc.h"
#include "access/tupdesc.h"
#include "storage/fd.h"
#include "storage/fd.h"
#include "catalog/pg_am.h"
#include "catalog/pg_am.h"
#include "catalog/pg_class.h"
#include "catalog/pg_class.h"
#include "nodes/nodes.h"
#include "nodes/nodes.h"
#include "rewrite/prs2lock.h"
#include "rewrite/prs2lock.h"
...
@@ -57,24 +57,27 @@
...
@@ -57,24 +57,27 @@
#include "miscadmin.h"
#include "miscadmin.h"
#define DO_START { StartTransactionCommand();\
#define DO_START { \
}
StartTransactionCommand();\
}
#define DO_END { CommitTransactionCommand();\
#define DO_END { \
if (!Quiet) { EMITPROMPT; }\
CommitTransactionCommand();\
fflush(stdout); \
if (!Quiet) { EMITPROMPT; }\
}
fflush(stdout); \
}
int num_tuples_read = 0;
int num_tuples_read = 0;
static Oid objectid;
static Oid objectid;
%}
%}
%union {
%union
List *list;
{
IndexElem *ielem;
List *list;
char *str;
IndexElem *ielem;
int ival;
char *str;
int ival;
}
}
%type <list> arg_list
%type <list> arg_list
...
@@ -84,7 +87,7 @@ static Oid objectid;
...
@@ -84,7 +87,7 @@ static Oid objectid;
%token <ival> CONST ID
%token <ival> CONST ID
%token OPEN XCLOSE XCREATE INSERT_TUPLE
%token OPEN XCLOSE XCREATE INSERT_TUPLE
%token STRING XDEFINE
%token STRING XDEFINE
%token XDECLARE INDEX ON USING XBUILD INDICES
%token XDECLARE INDEX ON USING XBUILD INDICES
%token COMMA EQUALS LPAREN RPAREN
%token COMMA EQUALS LPAREN RPAREN
%token OBJ_ID XBOOTSTRAP NULLVAL
%token OBJ_ID XBOOTSTRAP NULLVAL
...
@@ -96,228 +99,233 @@ static Oid objectid;
...
@@ -96,228 +99,233 @@ static Oid objectid;
%%
%%
TopLevel:
TopLevel:
Queries
Queries
|
|
;
;
Queries:
Queries:
Query
Query
| Queries Query
| Queries Query
;
;
Query :
Query :
OpenStmt
OpenStmt
| CloseStmt
| CloseStmt
| CreateStmt
| CreateStmt
| InsertStmt
| InsertStmt
| DeclareIndexStmt
| DeclareIndexStmt
| BuildIndsStmt
| BuildIndsStmt
;
;
OpenStmt:
OpenStmt:
OPEN ident
OPEN ident
{
{
DO_START;
DO_START;
boot_openrel(LexIDStr($2));
boot_openrel(LexIDStr($2));
DO_END;
DO_END;
}
}
;
;
CloseStmt:
CloseStmt:
XCLOSE ident %prec low
XCLOSE ident %prec low
{
{
DO_START;
DO_START;
closerel(LexIDStr($2));
closerel(LexIDStr($2));
DO_END;
DO_END;
}
}
| XCLOSE %prec high
| XCLOSE %prec high
{
{
DO_START;
DO_START;
closerel(NULL);
closerel(NULL);
DO_END;
DO_END;
}
}
;
;
CreateStmt:
CreateStmt:
XCREATE optbootstrap ident LPAREN
XCREATE optbootstrap ident LPAREN
{
{
DO_START;
DO_START;
numattr=(int)0;
numattr=(int)0;
}
}
typelist
typelist
{
{
if (!Quiet) putchar('\n');
if (!Quiet)
DO_END;
putchar('\n');
}
DO_END;
RPAREN
}
{
RPAREN
DO_START;
{
DO_START;
if ($2) {
extern Relation reldesc;
if ($2)
TupleDesc tupdesc;
{
extern Relation reldesc;
if (reldesc) {
TupleDesc tupdesc;
puts("create bootstrap: Warning, open relation");
puts("exists, closing first");
if (reldesc)
closerel(NULL);
{
}
puts("create bootstrap: Warning, open relation");
if (DebugMode)
puts("exists, closing first");
puts("creating bootstrap relation");
closerel(NULL);
tupdesc = CreateTupleDesc(numattr,attrtypes);
}
reldesc = heap_creatr(LexIDStr($3),
if (DebugMode)
DEFAULT_SMGR,
puts("creating bootstrap relation");
tupdesc);
tupdesc = CreateTupleDesc(numattr,attrtypes);
if (DebugMode)
reldesc = heap_creatr(LexIDStr($3),
puts("bootstrap relation created ok");
DEFAULT_SMGR,
} else {
tupdesc);
Oid id;
if (DebugMode)
TupleDesc tupdesc;
puts("bootstrap relation created ok");
/* extern Oid heap_create();*/
}
else
tupdesc = CreateTupleDesc(numattr,attrtypes);
{
id = heap_create(LexIDStr($3),
Oid id;
NULL,
TupleDesc tupdesc;
'n',
/* extern Oid heap_create();*/
DEFAULT_SMGR,
tupdesc);
tupdesc = CreateTupleDesc(numattr,attrtypes);
if (!Quiet)
id = heap_create(LexIDStr($3),
printf("CREATED relation %s with OID %d\n",
NULL,
LexIDStr($3), id);
'n',
}
DEFAULT_SMGR,
DO_END;
tupdesc);
if (DebugMode)
if (!Quiet)
puts("Commit End");
printf("CREATED relation %s with OID %d\n",
}
LexIDStr($3), id);
;
}
DO_END;
if (DebugMode)
puts("Commit End");
}
;
InsertStmt:
InsertStmt:
INSERT_TUPLE optoideq
INSERT_TUPLE optoideq
{
{
DO_START;
DO_START;
if (DebugMode)
if (DebugMode)
printf("tuple %d<", $2);
printf("tuple %d<", $2);
num_tuples_read = 0;
num_tuples_read = 0;
}
}
LPAREN tuplelist RPAREN
LPAREN tuplelist RPAREN
{
{
if (num_tuples_read != numattr)
if (num_tuples_read != numattr)
elog(WARN,"incorrect number of values for tuple");
elog(WARN,"incorrect number of values for tuple");
if (reldesc == (Relation)NULL) {
if (reldesc == (Relation)NULL)
elog(WARN,"must OPEN RELATION before INSERT\n");
{
err_out();
elog(WARN,"must OPEN RELATION before INSERT\n");
}
err_out();
if (DebugMode)
}
puts("Insert Begin");
if (DebugMode)
objectid = $2;
puts("Insert Begin");
InsertOneTuple(objectid);
objectid = $2;
if (DebugMode)
InsertOneTuple(objectid);
puts("Insert End");
if (DebugMode)
if (!Quiet) { putchar('\n'); }
puts("Insert End");
DO_END;
if (!Quiet)
if (DebugMode)
putchar('\n');
puts("Transaction End");
DO_END;
}
if (DebugMode)
;
puts("Transaction End");
}
;
DeclareIndexStmt:
DeclareIndexStmt:
XDECLARE INDEX ident ON ident USING ident LPAREN index_params RPAREN
XDECLARE INDEX ident ON ident USING ident LPAREN index_params RPAREN
{
{
List *params;
List *params;
DO_START;
DO_START;
params = lappend(NIL, (List*)$9);
params = lappend(NIL, (List*)$9);
DefineIndex(LexIDStr($5),
DefineIndex(LexIDStr($5),
LexIDStr($3),
LexIDStr($3),
LexIDStr($7),
LexIDStr($7),
params, NIL, 0, 0, NIL);
params, NIL, 0, 0, NIL);
DO_END;
DO_END;
}
}
;
;
BuildIndsStmt:
BuildIndsStmt:
XBUILD INDICES
{ build_indices(); }
XBUILD INDICES
{ build_indices(); }
index_params:
index_params:
index_on ident
index_on ident
{
{
IndexElem *n = (IndexElem*)$1;
IndexElem *n = (IndexElem*)$1;
n->class = LexIDStr($2);
n->class = LexIDStr($2);
$$ = n;
$$ = n;
}
}
index_on:
index_on:
ident
ident
{
{
IndexElem *n = makeNode(IndexElem);
IndexElem *n = makeNode(IndexElem);
n->name = LexIDStr($1);
n->name = LexIDStr($1);
$$ = n;
$$ = n;
}
}
| ident LPAREN arg_list RPAREN
| ident LPAREN arg_list RPAREN
{
{
IndexElem *n = makeNode(IndexElem);
IndexElem *n = makeNode(IndexElem);
n->name = LexIDStr($1);
n->name = LexIDStr($1);
n->args = (List*)$3;
n->args = (List*)$3;
$$ = n;
$$ = n;
}
}
arg_list:
arg_list:
ident
ident
{
{
$$ = lappend(NIL, makeString(LexIDStr($1)));
$$ = lappend(NIL, makeString(LexIDStr($1)));
}
}
| arg_list COMMA ident
| arg_list COMMA ident
{
{
$$ = lappend((List*)$1, makeString(LexIDStr($3)));
$$ = lappend((List*)$1, makeString(LexIDStr($3)));
}
}
optbootstrap:
optbootstrap:
XBOOTSTRAP { $$ = 1; }
XBOOTSTRAP { $$ = 1; }
|
{ $$ = 0; }
|
{ $$ = 0; }
;
;
typelist:
typelist:
typething
typething
| typelist COMMA typething
| typelist COMMA typething
;
;
typething:
typething:
ident EQUALS ident
ident EQUALS ident
{
{
if(++numattr > MAXATTR)
if(++numattr > MAXATTR)
elog(FATAL,"Too many attributes\n");
elog(FATAL,"Too many attributes\n");
DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
if (DebugMode)
if (DebugMode)
printf("\n");
printf("\n");
}
}
;
;
optoideq:
optoideq:
OBJ_ID EQUALS ident { $$ = atol(LexIDStr($3));
}
OBJ_ID EQUALS ident { $$ = atol(LexIDStr($3));
}
|
{ extern Oid newoid(); $$ = newoid(); }
|
{ extern Oid newoid(); $$ = newoid(); }
;
;
tuplelist:
tuplelist:
tuple
tuple
| tuplelist tuple
| tuplelist tuple
| tuplelist COMMA tuple
| tuplelist COMMA tuple
;
;
tuple:
tuple:
ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
| const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
| const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
| NULLVAL
| NULLVAL
{ InsertOneNull(num_tuples_read++); }
{ InsertOneNull(num_tuples_read++); }
;
;
const :
const :
CONST { $$=yylval.ival; }
CONST { $$=yylval.ival; }
;
;
ident :
ident :
ID { $$=yylval.ival; }
ID { $$=yylval.ival; }
;
;
%%
%%
src/backend/bootstrap/bootscanner.l
View file @
23db70bf
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
*
*
* bootscanner.lex--
* bootscanner.lex--
*
a lexical scanner for the bootstrap parser
*
a lexical scanner for the bootstrap parser
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
*
$Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.6 1997/01/10 20:16:26
momjian Exp $
*
$Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.7 1997/09/08 03:19:53
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#include "storage/fd.h"
#include "storage/fd.h"
#include "catalog/pg_am.h"
#include "catalog/pg_am.h"
#include "catalog/pg_class.h"
#include "catalog/pg_class.h"
#include "nodes/nodes.h"
#include "nodes/nodes.h"
#include "rewrite/prs2lock.h"
#include "rewrite/prs2lock.h"
#include "access/skey.h"
#include "access/skey.h"
#include "access/strat.h"
#include "access/strat.h"
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
#include "nodes/primnodes.h"
#include "nodes/primnodes.h"
#include "utils/nabstime.h"
#include "utils/nabstime.h"
#include "access/htup.h"
#include "access/htup.h"
#include "utils/tqual.h"
#include "utils/tqual.h"
#include "nodes/parsenodes.h"
#include "nodes/parsenodes.h"
...
@@ -46,82 +46,82 @@
...
@@ -46,82 +46,82 @@
#include "bootstrap_tokens.h"
#include "bootstrap_tokens.h"
#define YY_NO_UNPUT
#define
YY_NO_UNPUT
/* some versions of lex define this as a macro */
/* some versions of lex define this as a macro */
#if defined(yywrap)
#if defined(yywrap)
#undef yywrap
#undef yywrap
#endif /* yywrap */
#endif /* yywrap */
YYSTYPE
yylval;
YYSTYPE
yylval;
int yyline; /* keep track of the line number for error reporting */
int
yyline; /* keep track of the line number for error reporting */
%}
%}
D [0-9]
D
[0-9]
oct
\\{D}{D}{D}
oct
\\{D}{D}{D}
Exp [Ee][-+]?{D}+
Exp
[Ee][-+]?{D}+
id
([A-Za-z0-9_]|{oct}|\-)+
id
([A-Za-z0-9_]|{oct}|\-)+
sid
\"([^\"])*\"
sid
\"([^\"])*\"
arrayid
[A-Za-z0-9_]+\[{D}*\]
arrayid
[A-Za-z0-9_]+\[{D}*\]
%%
%%
open
{ return(OPEN); }
open
{ return(OPEN); }
close { return(XCLOSE); }
close
{ return(XCLOSE); }
create { return(XCREATE); }
create
{ return(XCREATE); }
OID
{ return(OBJ_ID); }
OID
{ return(OBJ_ID); }
bootstrap { return(XBOOTSTRAP); }
bootstrap
{ return(XBOOTSTRAP); }
_null_ { return(NULLVAL); }
_null_
{ return(NULLVAL); }
insert { return(INSERT_TUPLE); }
insert
{ return(INSERT_TUPLE); }
","
{ return(COMMA); }
","
{ return(COMMA); }
"=" { return(EQUALS); }
"="
{ return(EQUALS); }
"(" { return(LPAREN); }
"("
{ return(LPAREN); }
")" { return(RPAREN); }
")"
{ return(RPAREN); }
[\n]
{ yyline++; }
[\n]
{ yyline++; }
[\t] ;
[\t]
;
" "
;
" "
;
^\#[^\n]* ; /* drop everything after "#" for comments */
^\#[^\n]* ; /* drop everything after "#" for comments */
"declare" { return(XDECLARE); }
"declare"
{ return(XDECLARE); }
"build" { return(XBUILD); }
"build"
{ return(XBUILD); }
"indices" { return(INDICES); }
"indices"
{ return(INDICES); }
"index" { return(INDEX); }
"index"
{ return(INDEX); }
"on" { return(ON); }
"on"
{ return(ON); }
"using" { return(USING); }
"using"
{ return(USING); }
{arrayid} {
{arrayid}
{
yylval.ival = EnterString(MapArrayTypeName((char*)yytext));
yylval.ival = EnterString(MapArrayTypeName((char*)yytext));
return(ID);
return(ID);
}
}
{id}
{
{id}
{
yylval.ival = EnterString(scanstr((char*)yytext));
yylval.ival = EnterString(scanstr((char*)yytext));
return(ID);
return(ID);
}
}
{sid} {
{sid}
{
yytext[strlen(yytext)-1] = '\0'; /* strip off quotes */
yytext[strlen(yytext)-1] = '\0'; /* strip off quotes */
yylval.ival = EnterString(scanstr((char*)yytext+1));
yylval.ival = EnterString(scanstr((char*)yytext+1));
yytext[strlen(yytext)] = '"'; /* restore quotes */
yytext[strlen(yytext)] = '"'; /* restore quotes */
return(ID);
return(ID);
}
}
(-)?{D}+"."{D}*({Exp})?
|
(-)?{D}+"."{D}*({Exp})?
|
(-)?{D}*"."{D}+({Exp})?
|
(-)?{D}*"."{D}+({Exp})?
|
(-)?{D}+{Exp} {
(-)?{D}+{Exp}
{
yylval.ival = EnterString((char*)yytext);
yylval.ival = EnterString((char*)yytext);
return(CONST);
return(CONST);
}
}
. {
.
{
printf("syntax error %d : -> %s\n", yyline, yytext);
printf("syntax error %d : -> %s\n", yyline, yytext);
}
}
...
@@ -130,11 +130,11 @@ insert { return(INSERT_TUPLE); }
...
@@ -130,11 +130,11 @@ insert { return(INSERT_TUPLE); }
int
int
yywrap(void)
yywrap(void)
{
{
return 1;
return 1;
}
}
void
void
yyerror(const char *str)
yyerror(const char *str)
{
{
fprintf(stderr,"\tsyntax error %d : %s",yyline, str);
fprintf(stderr,"\tsyntax error %d : %s",yyline, str);
}
}
src/backend/parser/gram.y
View file @
23db70bf
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/backend/parser/scan.l
View file @
23db70bf
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
*
*
* scan.l--
* scan.l--
*
lexical scanner for POSTGRES
*
lexical scanner for POSTGRES
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
*
$Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.18 1997/09/05 09:05:48 vadim
Exp $
*
$Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.19 1997/09/08 03:20:04 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -64,207 +64,207 @@ int llen;
...
@@ -64,207 +64,207 @@ int llen;
char literal[MAX_PARSE_BUFFER];
char literal[MAX_PARSE_BUFFER];
%}
%}
/* OK, here is a short description of lex/flex rules behavior.
/* OK, here is a short description of lex/flex rules behavior.
* The longest pattern which matches an input string is always chosen.
* The longest pattern which matches an input string is always chosen.
* For equal-length patterns, the first occurring in the rules list is chosen.
* For equal-length patterns, the first occurring in the rules list is chosen.
* INITIAL is the starting condition, to which all non-conditional rules apply.
* INITIAL is the starting condition, to which all non-conditional rules apply.
* <xc> is an exclusive condition to allow embedded C-style comments.
* <xc> is an exclusive condition to allow embedded C-style comments.
* When in an exclusive condition, only those rules defined for that condition apply.
* When in an exclusive condition, only those rules defined for that condition apply.
* So, when in condition <xc>, only strings which would terminate the "extended comment"
* So, when in condition <xc>, only strings which would terminate the "extended comment"
*
trigger any action other than "ignore".
*
trigger any action other than "ignore".
* The "extended comment" syntax closely resembles allowable operator syntax.
* The "extended comment" syntax closely resembles allowable operator syntax.
* Therefore, be sure to match _any_ candidate comment, including those with appended
* Therefore, be sure to match _any_ candidate comment, including those with appended
*
operator-like symbols. - thomas 1997-07-14
*
operator-like symbols. - thomas 1997-07-14
*/
*/
/* define an exclusive condition to allow extended C-style comments - tgl 1997-07-12 */
/* define an exclusive condition to allow extended C-style comments - tgl 1997-07-12 */
%x xc
%x xc
/* define an exclusive condition for quoted strings - tgl 1997-07-30 */
/* define an exclusive condition for quoted strings - tgl 1997-07-30 */
%x xq
%x xq
/* We used to allow double-quoted strings, but SQL doesn't so we won't either */
/* We used to allow double-quoted strings, but SQL doesn't so we won't either */
quote
'
quote
'
xqstart {quote}
xqstart
{quote}
xqstop {quote}
xqstop
{quote}
xqdouble {quote}{quote}
xqdouble
{quote}{quote}
xqinside [^\']*
xqinside
[^\']*
xqliteral [\\].
xqliteral
[\\].
xcline [\/][\*].*[\*][\/]{space}*\n*
xcline
[\/][\*].*[\*][\/]{space}*\n*
xcstart [\/][\*]{op_and_self}*
xcstart
[\/][\*]{op_and_self}*
xcstop {op_and_self}*[\*][\/]({space}*|\n)
xcstop
{op_and_self}*[\*][\/]({space}*|\n)
xcinside [^*]*
xcinside
[^*]*
xcstar [^/]
xcstar
[^/]
digit [0-9]
digit
[0-9]
letter [_A-Za-z]
letter
[_A-Za-z]
letter_or_digit
[_A-Za-z0-9]
letter_or_digit
[_A-Za-z0-9]
sysfunc SYS_{letter}{letter_or_digit}*
sysfunc
SYS_{letter}{letter_or_digit}*
identifier {letter}{letter_or_digit}*
identifier
{letter}{letter_or_digit}*
typecast "::"
typecast
"::"
self [,()\[\].;$\:\+\-\*\/\<\>\=\|]
self
[,()\[\].;$\:\+\-\*\/\<\>\=\|]
selfm {self}[\-][\.0-9]
selfm
{self}[\-][\.0-9]
op_and_self [\~\!\@\#\%\^\&\|\`\?\$\:\+\-\*\/\<\>\=]
op_and_self
[\~\!\@\#\%\^\&\|\`\?\$\:\+\-\*\/\<\>\=]
operator {op_and_self}+
operator
{op_and_self}+
operatorm {op_and_self}+[\-][\.0-9]
operatorm
{op_and_self}+[\-][\.0-9]
integer -?{digit}+
integer
-?{digit}+
real -?{digit}+\.{digit}+([Ee][-+]?{digit}+)?
real
-?{digit}+\.{digit}+([Ee][-+]?{digit}+)?
param \${integer}
param
\${integer}
comment "--".*\n
comment
"--".*\n
comment2 "//".*\n
comment2
"//".*\n
space [ \t\n\f]
space
[ \t\n\f]
other .
other
.
%%
%%
{sysfunc} {
{sysfunc}
{
yylval.str = pstrdup(SystemFunctionHandler((char *)yytext));
yylval.str = pstrdup(SystemFunctionHandler((char *)yytext));
return (SCONST);
return (SCONST);
}
}
{comment} { /* ignore */ }
{comment}
{ /* ignore */ }
{comment2} { /* ignore */ }
{comment2}
{ /* ignore */ }
{xcline} { /* ignore */ }
{xcline}
{ /* ignore */ }
<xc>{xcstar} |
<xc>{xcstar} |
{xcstart} { BEGIN(xc); }
{xcstart}
{ BEGIN(xc); }
<xc>{xcstop} { BEGIN(INITIAL); }
<xc>{xcstop} { BEGIN(INITIAL); }
<xc>{xcinside} { /* ignore */ }
<xc>{xcinside} { /* ignore */ }
{xqstart} {
{xqstart} {
BEGIN(xq);
BEGIN(xq);
llen = 0;
llen = 0;
*literal = '\0';
*literal = '\0';
}
}
<xq>{xqstop} {
<xq>{xqstop} {
BEGIN(INITIAL);
BEGIN(INITIAL);
yylval.str = pstrdup(scanstr(literal));
yylval.str = pstrdup(scanstr(literal));
return (SCONST);
return (SCONST);
}
}
<xq>{xqdouble} |
<xq>{xqdouble} |
<xq>{xqinside} {
<xq>{xqinside} {
if ((llen+yyleng) > (MAX_PARSE_BUFFER - 1)) {
if ((llen+yyleng) > (MAX_PARSE_BUFFER - 1))
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
/* not reached */
memcpy(literal+llen, yytext, yyleng+1);
}
llen += yyleng;
memcpy(literal+llen, yytext, yyleng+1);
}
llen += yyleng;
<xq>{xqliteral} {
}
if ((llen+yyleng-1) > (MAX_PARSE_BUFFER - 1))
<xq>{xqliteral} {
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
if ((llen+yyleng-1) > (MAX_PARSE_BUFFER - 1)) {
memcpy(literal+llen, yytext+1, yyleng);
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
llen += yyleng-1;
/* not reached */
}
}
memcpy(literal+llen, yytext+1, yyleng);
{typecast} { return TYPECAST; }
llen += yyleng-1;
}
{selfm} {
yyless(yyleng-2);
{typecast} { return TYPECAST; }
return (yytext[0]);
}
{selfm} {
{self} { return (yytext[0]); }
yyless(yyleng-2);
return (yytext[0]);
{operatorm} {
}
yyless(yyleng-2);
{self} { return (yytext[0]); }
yylval.str = pstrdup((char*)yytext);
return (Op);
{operatorm} {
}
yyless(yyleng-2);
{operator} {
yylval.str = pstrdup((char*)yytext);
if (strcmp((char*)yytext,"!=") == 0)
return (Op);
yylval.str = pstrdup("<>"); /* compatability */
}
else
{operator} {
yylval.str = pstrdup((char*)yytext);
if (strcmp((char*)yytext,"!=") == 0)
return (Op);
yylval.str = pstrdup("<>"); /* compatability */
}
else
{param} {
yylval.str = pstrdup((char*)yytext);
yylval.ival = atoi((char*)&yytext[1]);
return (Op);
return (PARAM);
}
}
{param} { yylval.ival = atoi((char*)&yytext[1]);
{integer} {
return (PARAM);
yylval.ival = atoi((char*)yytext);
}
return (ICONST);
{integer} {
}
yylval.ival = atoi((char*)yytext);
{real} {
return (ICONST);
char* endptr;
}
{real} {
errno = 0;
char* endptr;
yylval.dval = strtod(((char *)yytext),&endptr);
errno = 0;
if (*endptr != '\0' || errno == ERANGE)
yylval.dval = strtod(((char *)yytext),&endptr);
elog(WARN,"\tBad float8 input format\n");
if (*endptr != '\0' || errno == ERANGE)
CheckFloat8Val(yylval.dval);
elog(WARN,"\tBad float8 input format\n");
return (FCONST);
CheckFloat8Val(yylval.dval);
}
return (FCONST);
}
{identifier} {
{identifier} {
int i;
int i;
ScanKeyword *keyword;
ScanKeyword *keyword;
for(i = strlen(yytext); i >= 0; i--)
for(i = strlen(yytext); i >= 0; i--)
if (isupper(yytext[i]))
if (isupper(yytext[i]))
yytext[i] = tolower(yytext[i]);
yytext[i] = tolower(yytext[i]);
keyword = ScanKeywordLookup((char*)yytext);
keyword = ScanKeywordLookup((char*)yytext);
if (keyword != NULL) {
if (keyword != NULL) {
if ( keyword->value == DEFAULT ) {
if ( keyword->value == DEFAULT )
DefaultStartPosition = CurScanPosition () + yyleng + 1;
{
printf( "default offset is %d\n", DefaultStartPosition);
DefaultStartPosition = CurScanPosition () + yyleng + 1;
printf( "default offset is %d\n", DefaultStartPosition);
} else if ( keyword->value == CHECK ) {
}
CheckStartPosition = CurScanPosition () + yyleng + 1;
else if ( keyword->value == CHECK )
printf( "check offset is %d\n", CheckStartPosition);
{
CheckStartPosition = CurScanPosition () + yyleng + 1;
};
printf( "check offset is %d\n", CheckStartPosition);
}
return (keyword->value);
return (keyword->value);
} else {
}
yylval.str = pstrdup((char*)yytext);
else
return (IDENT);
{
}
yylval.str = pstrdup((char*)yytext);
}
return (IDENT);
{space} { /* ignore */ }
}
}
{other} { return (yytext[0]); }
{space} { /* ignore */ }
{other} { return (yytext[0]); }
%%
%%
void yyerror(char message[])
void yyerror(char message[])
{
{
elog(WARN, "parser: %s at or near \"%s\"\n", message, yytext);
elog(WARN, "parser: %s at or near \"%s\"\n", message, yytext);
}
}
int yywrap()
int yywrap()
{
{
return(1);
return(1);
}
}
/*
/*
init_io:
init_io:
called by postgres before any actual parsing is done
called by postgres before any actual parsing is done
*/
*/
void
void
init_io()
init_io()
{
{
/* it's important to set this to NULL
/* it's important to set this to NULL
because input()/myinput() checks the non-nullness of parseCh
because input()/myinput() checks the non-nullness of parseCh
to know when to pass the string to lex/flex */
to know when to pass the string to lex/flex */
parseCh = NULL;
parseCh = NULL;
#if defined(FLEX_SCANNER)
#if defined(FLEX_SCANNER)
if (YY_CURRENT_BUFFER)
if (YY_CURRENT_BUFFER)
yy_flush_buffer(YY_CURRENT_BUFFER);
yy_flush_buffer(YY_CURRENT_BUFFER);
#endif /* FLEX_SCANNER */
#endif /* FLEX_SCANNER */
BEGIN INITIAL;
BEGIN INITIAL;
}
}
...
@@ -274,63 +274,63 @@ init_io()
...
@@ -274,63 +274,63 @@ init_io()
int
int
input()
input()
{
{
if (parseCh == NULL) {
if (parseCh == NULL)
parseCh = parseString;
{
return(*parseCh++);
parseCh = parseString;
} else if (*parseCh == '\0') {
return(*parseCh++);
return(0);
}
} else {
else if (*parseCh == '\0')
return(*parseCh++);
return(0);
}
else
return(*parseCh++);
}
}
/* undo lex input from a string instead of from stdin */
/* undo lex input from a string instead of from stdin */
void
void
unput(char c)
unput(char c)
{
{
if (parseCh == NULL) {
if (parseCh == NULL)
elog(FATAL, "Unput() failed.\n");
elog(FATAL, "Unput() failed.\n");
} else if (c != 0) {
else if (c != 0)
*--parseCh = c;
*--parseCh = c;
}
}
}
int
int
CurScanPosition(void)
CurScanPosition(void)
{
{
return (parseCh - parseString - yyleng);
return (parseCh - parseString - yyleng);
}
}
#endif /* !defined(FLEX_SCANNER) */
#endif /* !defined(FLEX_SCANNER) */
#ifdef FLEX_SCANNER
#ifdef FLEX_SCANNER
/* input routine for flex to read input from a string instead of a file */
/* input routine for flex to read input from a string instead of a file */
int
int
myinput(char* buf, int max)
myinput(char* buf, int max)
{
{
int len, copylen;
int len, copylen;
if (parseCh == NULL) {
if (parseCh == NULL)
len = strlen(parseString);
{
if (len >= max)
len = strlen(parseString);
copylen = max - 1;
if (len >= max)
copylen = max - 1;
else
copylen = len;
if (copylen > 0)
memcpy(buf, parseString, copylen);
buf[copylen] = '\0';
parseCh = parseString;
return copylen;
}
else
else
copylen = len;
return 0; /* end of string */
if (copylen > 0)
memcpy(buf, parseString, copylen);
buf[copylen] = '\0';
parseCh = parseString;
return copylen;
} else {
return 0; /* end of string */
}
}
}
int
int
CurScanPosition(void)
CurScanPosition(void)
{
{
printf( "current position is %d\n", yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng);
printf( "current position is %d\n", yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng);
return (yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng);
return (yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng);
}
}
#endif /* FLEX_SCANNER */
#endif /* FLEX_SCANNER */
...
...
src/lextest/scan.l
View file @
23db70bf
%{
%{
/*
/*
This should work, but non-patched flex 2.5.3 fails because input()
This should work, but non-patched flex 2.5.3 fails because input()
doesn't return EOF or '\0'
doesn't return EOF or '\0'
Bruce Momjian <root@candle.pha.pa.us>
Bruce Momjian <root@candle.pha.pa.us>
*/
*/
%}
%}
%%
%%
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment