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

From Jan Wieck
Subject Re: Grammar-problems with pl/pgsql in gram.y
Date
Msg-id 200105161410.KAA03183@jupiter.jw.home
Whole thread Raw
In response to Grammar-problems with pl/pgsql in gram.y  (Klaus Reger <K.Reger@gmx.de>)
Responses Re: Grammar-problems with pl/pgsql in gram.y  (Klaus Reger <K.Reger@gmx.de>)
List 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
listof 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@Yahoo.com #



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



pgsql-hackers by date:

Previous
From: Klaus Reger
Date:
Subject: Grammar-problems with pl/pgsql in gram.y
Next
From: Lamar Owen
Date:
Subject: Re: Configurable path to look up dynamic libraries