Re: Grammar-problems with pl/pgsql in gram.y

From: Klaus Reger <K(dot)Reger(at)gmx(dot)de>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>, K(dot)Reger(at)gmx(dot)de
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Grammar-problems with pl/pgsql in gram.y
Date: 2001-05-16 16:57:13
Message-ID: 200105161657.f4GGvSa05143@pc01.reger-clan.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Am Mittwoch, 16. Mai 2001 16:10 schrieb Jan Wieck:
> Here it is. stmt_else is defined as type <stmts>, not <stmt>.
> The PLpgSQL_stmt_if struct has a condition query and two
> statement lists (type <stmts>). You're trying to put a single
> statement into the else part instead of a list of statements.
Thank you for the hint! That was it.

> Maybe it'll work if you surround it with another
> PLpgSQL_stmts struct where your new PLpgSQL_stmt_if is the
> only statement in it's list. Since I have some bigger work
> outstanding for PL/pgSQL, send the resulting patch (if you
> get it to work) directly to me.
The patch follows this message. May you tell me what kind of work it is,
cause I'm so curous :-). By the way, the next thing I try is a
EXCEPTION WHEN OTHER-clause, like in Oracle. Let's look if I'm successful.

Ciao, Klaus

----------------------------------------------------------------------------

diff -Naurb src/gram.y src.elsif/gram.y
--- src/gram.y Wed May 16 18:00:53 2001
+++ src.elsif/gram.y Wed May 16 17:39:19 2001
@@ -147,6 +147,7 @@
%token K_DIAGNOSTICS
%token K_DOTDOT
%token K_ELSE
+%token K_ELSIF
%token K_END
%token K_EXCEPTION
%token K_EXECUTE
@@ -544,6 +545,7 @@
new->stmts[0] = (struct PLpgSQL_stmt *)$1;

$$ = new;
+
}
;

@@ -721,8 +723,53 @@
memset(new, 0, sizeof(PLpgSQL_stmts));
$$ = new;
}
+ | K_ELSIF lno expr_until_then proc_sect stmt_else
+ {
+ /*
+ * Translate the structure: into:
+ *
+ * IF c1 THEN IF c1 THEN
+ * ... ...
+ * ELSIF c2 THEN ELSE
+ * IF c2 THEN
+ * ... ...
+ * ELSE ELSE
+ * ... ...
+ * END IF END IF
+ * END IF
+ *
+ */
+
+ PLpgSQL_stmts *new;
+ PLpgSQL_stmt_if *new_if;
+
+ /* first create a new if-statement */
+ new_if = malloc(sizeof(PLpgSQL_stmt_if));
+ memset(new_if, 0, sizeof(PLpgSQL_stmt_if));
+
+ new_if->cmd_type = PLPGSQL_STMT_IF;
+ new_if->lineno = $2;
+ new_if->cond = $3;
+ new_if->true_body = $4;
+ new_if->false_body = $5;
+
+ /* this is a 'container' for the if-statement */
+ new = malloc(sizeof(PLpgSQL_stmts));
+ memset(new, 0, sizeof(PLpgSQL_stmts));
+
+ new->stmts_alloc = 64;
+ new->stmts_used = 1;
+ new->stmts = malloc(sizeof(PLpgSQL_stmt *) * new->stmts_alloc);
+ new->stmts[0] = (struct PLpgSQL_stmt *)new_if;
+
+ $$ = new;
+
+ }
+
| K_ELSE proc_sect
- { $$ = $2; }
+ {
+ $$ = $2;
+ }
;

stmt_loop : opt_label K_LOOP lno loop_body
@@ -1271,7 +1318,6 @@
break;
}
}
-
expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - sizeof(int));
expr->dtype = PLPGSQL_DTYPE_EXPR;
expr->query = strdup(plpgsql_dstring_get(&ds));
diff -Naurb src/scan.l src.elsif/scan.l
--- src/scan.l Wed May 16 18:01:36 2001
+++ src.elsif/scan.l Tue May 15 12:49:43 2001
@@ -99,6 +99,7 @@
default { return K_DEFAULT; }
diagnostics { return K_DIAGNOSTICS; }
else { return K_ELSE; }
+elsif { return K_ELSIF; }
end { return K_END; }
exception { return K_EXCEPTION; }
execute { return K_EXECUTE; }

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2001-05-16 17:02:28 Re: Configurable path to look up dynamic libraries
Previous Message Peter Eisentraut 2001-05-16 16:56:43 Re: Configurable path to look up dynamic libraries