Commit 23db70bf authored by Bruce Momjian's avatar Bruce Momjian

Lex/yacc source cleanup like indent.

parent 319dbfa7
...@@ -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; }
; ;
%% %%
...@@ -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);
} }
This diff is collapsed.
This diff is collapsed.
%{ %{
/* /*
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>
*/ */
%} %}
%% %%
......
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