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

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: 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 14:10:41
Message-ID: 200105161410.KAA03183@jupiter.jw.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Klaus Reger wrote:
> Hi,
>
> I want to learn, how the pl/plsql-parser/compiler works. Therefore I planned
> to implement a simple ELSIF, like oracle does.
>
> I added the following K_ELSIF branch to gram.y, in the hope that, when ELSIF
> is parsed, simply another if-structure in inserted.
>
> ---------------------------------------------------------
> stmt_else :
> {
> PLpgSQL_stmts *new;
>
> new = malloc(sizeof(PLpgSQL_stmts));
> memset(new, 0, sizeof(PLpgSQL_stmts));
> $$ = new;
> elog(NOTICE, "empty ELSE detected");
> }
> | K_ELSIF expr_until_then proc_sect stmt_else
> {
> PLpgSQL_stmt_if *new;
> elog(NOTICE, "ELSIF detected");
> new = malloc(sizeof(PLpgSQL_stmt_if));
> memset(new, 0, sizeof(PLpgSQL_stmt_if));
> new->cmd_type = PLPGSQL_STMT_IF;
> // new->lineno = $2;
> new->cond = $2;
> new->true_body = $3;
> new->false_body = $4;
>
> $$ = (PLpgSQL_stmts *)new;

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.

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.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Lamar Owen 2001-05-16 16:13:20 Re: Configurable path to look up dynamic libraries
Previous Message Nils Zonneveld 2001-05-16 12:56:44 Re: Queries across multiple databases (was: SELECT from a table in another database).