Grammar-problems with pl/pgsql in gram.y - Mailing list pgsql-hackers
| From | Klaus Reger |
|---|---|
| Subject | Grammar-problems with pl/pgsql in gram.y |
| Date | |
| Msg-id | 200105161029.f4GATII18440@pc01.reger-clan.de Whole thread Raw |
| Responses |
Re: Grammar-problems with pl/pgsql in gram.y
|
| List | pgsql-hackers |
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;
}| K_ELSE proc_sect{ $$ = $2; elog(NOTICE, "ELSE detected
(%s)", strdup(yytext));};
--------------------------------------------------------------
A testprocedure, which looks like that:
--------------------------------------------------------------
DECLARE iPar1PI ALIAS FOR $1; iTmp integer; iResult varchar;
BEGIN
iTmp = iPar1PI; raise notice '1.0';
if iTmp IS NULL then raise notice '2.0'; iResult = 'Echt NULL';
else if iTmp = 0 then raise notice '2.1.0'; iResult = 'Null (0)';
elsif (iTmp < 0) THEN raise notice '2.1.1'; iResult = 'Negativ';
elsif (iTmp > 0) THEN raise notice '2.1.2'; iResult = 'Positiv';
else raise notice '2.1.3'; iResult = 'Gibts nicht!'; end if; end if; raise
notice'3.0';
return iResult;
END;
--------------------------------------------------------------
is dumped in this way ...
--------------------------------------------------------------
Execution tree of successfully compiled PL/pgSQL function kr_test:
Functions data area: entry 0: VAR $1 type int4 (typoid 23) atttypmod -1 entry 1: VAR found
typebool (typoid 16) atttypmod -1 entry 2: VAR itmp type int4 (typoid 23) atttypmod -1 entry 3: VAR
iresult type varchar (typoid 1043) atttypmod -1
Functions statements: 8:BLOCK <<*unnamed*>>10: ASSIGN var 2 := 'SELECT $1 {$1=0}'12: RAISE ''1.0''14: IF 'SELECT
$1 IS NULL {$1=2}' THEN15: RAISE ''2.0''16: ASSIGN var 3 := 'SELECT 'Echt NULL'' ELSE19: IF 'SELECT $1
= 0 {$1=2}' THEN20: RAISE ''2.1.0''21: ASSIGN var 3 := 'SELECT 'Null (0)'' ELSE ENDIF
ENDIF37: RAISE ''3.0''39: RETURN 'SELECT $1 {$1=3}' END -- *unnamed*
End of execution tree of function kr_test
--------------------------------------------------------------
So my question is: Why does my inserted
PLpgSQL_stmt_if *new;
is not executed, because I do it in the same way like stmt_if does?
Who can halp me (Maybe Jan??)
Regards, Klaus
pgsql-hackers by date: